diff --git a/src/features/background-agent/manager.test.ts b/src/features/background-agent/manager.test.ts index 4e0e00892..0fcb463e3 100644 --- a/src/features/background-agent/manager.test.ts +++ b/src/features/background-agent/manager.test.ts @@ -1059,7 +1059,18 @@ describe("BackgroundManager.notifyParentSession - aborted parent", () => { prompt: promptMock, promptAsync: promptMock, abort: async () => ({}), - messages: async () => ({ data: [] }), + messages: async () => ({ + data: [{ + info: { + agent: "explore", + model: { + providerID: "anthropic", + modelID: "claude-opus-4-6", + variant: "high", + }, + }, + }], + }), }, } const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput) @@ -1219,6 +1230,58 @@ describe("BackgroundManager.notifyParentSession - variant propagation", () => { manager.shutdown() }) + test("should prefer parent session variant over child task variant in parent notification promptAsync body", async () => { + //#given + const promptCalls: Array<{ body: Record }> = [] + const client = { + session: { + prompt: async () => ({}), + promptAsync: async (args: { path: { id: string }; body: Record }) => { + promptCalls.push({ body: args.body }) + return {} + }, + abort: async () => ({}), + messages: async () => ({ + data: [{ + info: { + agent: "explore", + model: { + providerID: "anthropic", + modelID: "claude-opus-4-6", + variant: "max", + }, + }, + }], + }), + }, + } + const manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput) + const task: BackgroundTask = { + id: "task-parent-variant-wins", + sessionID: "session-child", + parentSessionID: "session-parent", + parentMessageID: "msg-parent", + description: "task with mismatched variant", + prompt: "test", + agent: "explore", + status: "completed", + startedAt: new Date(), + completedAt: new Date(), + model: { providerID: "anthropic", modelID: "claude-opus-4-6", variant: "high" }, + } + getPendingByParent(manager).set("session-parent", new Set([task.id])) + + //#when + await (manager as unknown as { notifyParentSession: (task: BackgroundTask) => Promise }) + .notifyParentSession(task) + + //#then + expect(promptCalls).toHaveLength(1) + expect(promptCalls[0].body.variant).toBe("max") + + manager.shutdown() + }) + test("should not include variant in promptAsync body when task has no variant", async () => { //#given const promptCalls: Array<{ body: Record }> = [] diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index 1a23c3569..d06d5fcaf 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -1783,6 +1783,7 @@ export class BackgroundManager { let agent: string | undefined = task.parentAgent let model: { providerID: string; modelID: string } | undefined let tools: Record | undefined = task.parentTools + let promptContext: ReturnType = null if (this.enableParentSessionNotifications) { try { @@ -1796,7 +1797,7 @@ export class BackgroundManager { tools?: Record } }>) - const promptContext = resolvePromptContextFromSessionMessages( + promptContext = resolvePromptContextFromSessionMessages( messages, task.parentSessionID, ) @@ -1840,7 +1841,7 @@ export class BackgroundManager { const isTaskFailure = task.status === "error" || task.status === "cancelled" || task.status === "interrupt" const shouldReply = allComplete || isTaskFailure - const variant = task.model?.variant + const variant = promptContext?.model?.variant try { await this.client.session.promptAsync({