fix(session): skip synthetic delegation nudge in subagent sessions#17210
Open
vicary wants to merge 3 commits intoanomalyco:devfrom
Open
fix(session): skip synthetic delegation nudge in subagent sessions#17210vicary wants to merge 3 commits intoanomalyco:devfrom
vicary wants to merge 3 commits intoanomalyco:devfrom
Conversation
When a user message contains an @agent part, createUserMessage injects a synthetic text part that tells the model to call the task tool with that subagent. In a child/subagent session the orchestrator has already written an explicit task prompt, so injecting the nudge again causes recursive nesting bias: the subagent re-reads the @agent mention in its own context and tries to spawn another layer of delegation. Guard the injection behind a parentID check so only root sessions receive the synthetic delegation instruction. Fixes anomalyco#17202
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
5bbdffa to
ed32b28
Compare
5bbdffa to
f76ead9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #17202
Type of change
What does this PR do?
When a user message contains an
@agentmention,SessionPrompt.createUserMessageinjects a synthetic text part instructing the model to call thetasktool with that subagent. This is correct behaviour in a root session where the user is initiating a delegation.In a child/subagent session however, the orchestrator has already written an explicit task prompt before the session starts. When the subagent processes its own message history it encounters the
@agentpart and the injection runs again, appending a second delegation instruction. This causes recursive nesting bias: the subagent reads its own context, sees the nudge, and attempts to spawn yet another delegation layer.The fix is a minimal guard in the
if (part.type === "agent")branch ofcreateUserMessage:Session.Info.parentIDis already set by the orchestrator when it creates child sessions. The guard is minimal and does not affect any other code path.How did you verify your code works?
packages/opencode/src/session/prompt.tsto confirm the root cause.Session.Info.parentIDis populated for child sessions viapackages/opencode/src/session/index.ts.OPENCODE_VERSION=1.2.24 bun run ./packages/opencode/script/build.ts).@agent. Verified via DB inspection that the subagent's message history no longer contains the synthetic delegation text part.parentIDis absent).packages/opencode/test/session/prompt.test.ts:injects synthetic delegation nudge in root sessionsskips synthetic delegation nudge in subagent sessionsprompt.test.tspass (bun test ./test/session/prompt.test.ts).Screenshots / recordings
No UI changes.
Checklist