Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/replay/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export async function attemptFallback(
path: { id: sessionId },
body: {
model: { providerID, modelID },
agent: agentName ?? undefined,
parts: promptParts as NonNullable<
Parameters<typeof client.session.prompt>[0]["body"]
>["parts"],
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/mock-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface MockMessageEntry {
export interface MockClientCalls {
abort: string[];
revert: Array<{ sessionId: string; messageID: string }>;
prompt: Array<{ sessionId: string; providerID: string; modelID: string; parts: unknown[] }>;
prompt: Array<{ sessionId: string; providerID: string; modelID: string; agent?: string; parts: unknown[] }>;
toasts: Array<{ title?: string; message: string; variant: string }>;
logs: Array<{ level: string; message: string }>;
}
Expand Down Expand Up @@ -52,13 +52,14 @@ export function makeMockClient(opts: MockClientOptions = {}): {
},
prompt: async (options: {
path: { id: string };
body?: { model?: { providerID: string; modelID: string }; parts?: unknown[] };
body?: { model?: { providerID: string; modelID: string }; agent?: string; parts?: unknown[] };
}) => {
if (opts.promptError) throw opts.promptError;
calls.prompt.push({
sessionId: options.path.id,
providerID: options.body?.model?.providerID ?? "",
modelID: options.body?.model?.modelID ?? "",
agent: options.body?.agent,
parts: options.body?.parts ?? [],
});
return { data: {} };
Expand Down
35 changes: 35 additions & 0 deletions test/orchestrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,41 @@ describe("attemptFallback — concurrency", () => {
});
});

// ─── Agent preservation ───────────────────────────────────────────────────────

describe("attemptFallback — agent preservation", () => {
it("passes the agent name to the prompt call so the fallback model runs under the same agent", async () => {
const { client, calls } = makeMockClient({
messages: [makeUserMessage("s1", "m1", "openai", "gpt-5.3-codex", "OpenCoder")],
});
const store = makeStore();
store.sessions.setOriginalModel("s1", "openai/gpt-5.3-codex");
const logger = new Logger(client, "/tmp/test.log", false);

await attemptFallback("s1", "rate_limit", client, store, BASE_CONFIG, logger, "/tmp");

expect(calls.prompt).toHaveLength(1);
expect(calls.prompt[0].agent).toBe("OpenCoder");
});

it("omits agent from prompt when it could not be resolved", async () => {
// No agent field in the message → agentName resolves to null
const msg = makeUserMessage("s1", "m1", "openai", "gpt-5.3-codex");
// Strip the agent field so resolveAgentName has nothing to work with
(msg.info as any).agent = undefined;

const { client, calls } = makeMockClient({ messages: [msg] });
const store = makeStore();
store.sessions.setOriginalModel("s1", "openai/gpt-5.3-codex");
const logger = new Logger(client, "/tmp/test.log", false);

await attemptFallback("s1", "rate_limit", client, store, BASE_CONFIG, logger, "/tmp");

expect(calls.prompt).toHaveLength(1);
expect(calls.prompt[0].agent).toBeUndefined();
});
});

// ─── Replay step failures ─────────────────────────────────────────────────────

describe("attemptFallback — replay step failures", () => {
Expand Down
Loading