From 66f8946ff1e3a7cc5bf1b511e68c38c5db693987 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Wed, 14 Jan 2026 13:50:12 +0900 Subject: [PATCH] fix(background-agent): preserve parent model in notifyParentSession Fixes model switching bug where sisyphus_task with category would change the main session's model after completion. - Add parentModel to session.prompt body in notifyParentSession - Add test verifying model is included when parentModel is defined --- src/features/background-agent/manager.test.ts | 27 ++++++++++++++++++- src/features/background-agent/manager.ts | 8 ++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/features/background-agent/manager.test.ts b/src/features/background-agent/manager.test.ts index 6d2f61e7..00fdee5e 100644 --- a/src/features/background-agent/manager.test.ts +++ b/src/features/background-agent/manager.test.ts @@ -675,7 +675,32 @@ describe("LaunchInput.skillContent", () => { }) }) -describe("BackgroundManager.notifyParentSession - agent context preservation", () => { +describe("BackgroundManager.notifyParentSession - model/agent context preservation", () => { + test("should include model field in session.prompt when parentModel is defined", async () => { + // #given + const task: BackgroundTask = { + id: "task-with-model", + sessionID: "session-child", + parentSessionID: "session-parent", + parentMessageID: "msg-parent", + description: "task with model context", + prompt: "test", + agent: "explore", + status: "completed", + startedAt: new Date(), + completedAt: new Date(), + parentAgent: "Sisyphus", + parentModel: { providerID: "anthropic", modelID: "claude-opus-4-5" }, + } + + // #when + const promptBody = buildNotificationPromptBody(task) + + // #then - model MUST be included when parentModel is defined + expect(promptBody.model).toEqual({ providerID: "anthropic", modelID: "claude-opus-4-5" }) + expect(promptBody.agent).toBe("Sisyphus") + }) + test("should not pass agent field when parentAgent is undefined", async () => { // #given const task: BackgroundTask = { diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index dcc142e4..2da2f053 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -639,12 +639,16 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea } // Inject notification via session.prompt with noReply + // Preserve parent session's model/agent context to prevent model switching try { await this.client.session.prompt({ path: { id: task.parentSessionID }, body: { - noReply: !allComplete, // Silent unless all complete - agent: task.parentAgent, + noReply: !allComplete, + ...(task.parentAgent !== undefined ? { agent: task.parentAgent } : {}), + ...(task.parentModel?.providerID && task.parentModel?.modelID + ? { model: { providerID: task.parentModel.providerID, modelID: task.parentModel.modelID } } + : {}), parts: [{ type: "text", text: notification }], }, })