fix(session): resolve the turn's agent from live session state - #41396
Open
mewmewmemw wants to merge 3 commits into
Open
fix(session): resolve the turn's agent from live session state#41396mewmewmemw wants to merge 3 commits into
mewmewmemw wants to merge 3 commits into
Conversation
… is given createUserMessage fell back to the default agent when input.agent was absent, ignoring the session's selected agent (set via Tab / switchAgent). It also rolled session.agent back to the default via setAgentModel, so the stale system prompt persisted across turns. Resolve as: input.agent -> session.agent -> default, degrading to the default only when session.agent points to a removed agent. Regression test added (offline, TestLLMServer).
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found one potentially related PR that warrants attention: Related PR:
No other duplicate PRs were found. The current PR (#41396) appears to be the primary fix for issue #41387. |
…f message stamp The V1 prompt loop built the turn's system prompt from the agent stamped on the latest user message. After a durable agent switch (Tab / switchAgent) already-authored messages keep the old stamp, so turns kept running on the previous agent until process restart. Resolve the turn's agent from the live session selection (fresh read), falling back to the message stamp only when the session has none set; degrade to the default agent when the session's agent no longer exists. Regression test added through the real durable AgentSwitched path (offline, TestLLMServer); V2 runner behavior documented with two additional tests.
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 #41387
Type of change
What does this PR do?
Two related fixes for the stale system prompt after switching a session's agent (Tab / switchAgent):
createUserMessage(16a1511): wheninput.agentis absent (the V2 prompt flow does not pass an agent), the agent was resolved viaagents.defaultInfo()— the configured default — ignoring the session's selected agent, and thesetAgentModelblock rolledsession.agentback to the default, so the stale prompt persisted across turns. Now resolved asinput.agent → session.agent → default, degrading to the default only whensession.agentpoints to a removed agent.Prompt loop (4ebf96a): the loop built the turn's system prompt from the agent stamped on the latest user message rather than the live
session.agent. Messages authored before a switch keep the old stamp, so turns kept running on the previous agent — observed live persisting across multiple consecutive turns, cleared only by a process restart. The loop now resolves the turn's agent from a fresh session read, falling back to the message stamp only when the session has none set.How did you verify your code works?
Offline regression tests (in-process TestLLMServer, no network):
Suites: prompt.test.ts 59 pass / 0 fail; packages/opencode full suite 3260 pass / 0 fail; packages/core 1082 pass / 0 fail; typecheck clean in both packages.
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist