fix(background-agent): preserve parent agent context in completion notifications

When parentAgent is undefined, omit the agent field entirely from
session.prompt body instead of passing undefined. This prevents the
OpenCode SDK from falling back to defaultAgent(), which would change
the parent session's agent context.

Changes:
- manager.ts: Build prompt body conditionally, only include agent/model
  when defined
- background-task/tools.ts: Use ctx.agent as primary source for
  parentAgent (consistent with sisyphus-task)
- registerExternalTask: Add parentAgent parameter support
- Added tests for agent context preservation scenarios
This commit is contained in:
YeonGyu-Kim
2026-01-09 15:53:36 +09:00
parent a50878df51
commit 79e9fd82c5
3 changed files with 111 additions and 11 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ export function createBackgroundTask(manager: BackgroundManager): ToolDefinition
parentSessionID: ctx.sessionID,
parentMessageID: ctx.messageID,
parentModel,
parentAgent: prevMessage?.agent,
parentAgent: ctx.agent ?? prevMessage?.agent,
})
ctx.metadata?.({