fix(session): preserve agent and model on injected prompts without explicit fields - #46106
Open
iceteaSA wants to merge 1 commit into
Open
fix(session): preserve agent and model on injected prompts without explicit fields#46106iceteaSA wants to merge 1 commit into
iceteaSA wants to merge 1 commit into
Conversation
…plicit fields An injected prompt omitting agent/model falls back to the default agent’s configured model, silently switching the session and busting the provider cache prefix. createUserMessage reads the durable session row and the last agent-carrying user message before falling back to defaults; a genuine agent switch still adopts the new agent’s model, and variant is preserved on the same precedence. Revives the fix from anomalyco#35195 (closed by the inactivity bot, unmerged), extended to also preserve the session variant and to only adopt the new agent’s model on a genuine agent switch. Co-authored-by: Sami Jawhar <sjawhar@users.noreply.github.com>
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
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate/Related PRs FoundHigh relevance:
Context (mentioned in PR description): The PR description itself references:
These historical issues should be checked to understand the full context of this fix attempt. |
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 #46111. Revives @sjawhar's #35195 (bot-closed, unmerged) and the original report #21728 (also bot-closed) — extended here to preserve the session variant and to only adopt the new agent's model on a genuine agent switch.
Type of change
What does this PR do?
A prompt that arrives without explicit
agent/model— a background-subagent completion notification, or any injected prompt — makescreateUserMessagefall back to the default agent and that agent's configured model, silently switching the session. Provider prompt caching keys on the model, so it also drops the cached prefix and re-uploads the context. This is #21728, reported againstprompt_async.On current
dev:Any injected prompt omitting the fields lands on the default agent and
ag.model, whatever the session was using.The fix reads the durable session row (which survives compaction and records the active agent/model) and the last agent-carrying user message before falling back:
agentName = input.agent ?? current.agent ?? prev?.info.agentswitched = !!current.agent && ag.name !== current.agent) still adopts the new agent's model; an injected prompt for the current agent keeps the session modelmodel = input.model ?? sessionModel ?? prev?.info.model ?? ag.model ?? currentModel(...)This is the broad fix at the shared resolution point #35195 aimed at, plus variant preservation and the agent-switch guard. Explicit
agent/modelbehave exactly as before.How did you verify your code works?
Five regression tests through the real producer (
SessionPrompt.prompt), red-first. Reverse-applying only thesrc/hunks (tests kept) shows them fail against unmodifieddev:Full suite
packages/opencode: 3400 pass / 0 fail, +5 over baseline.bun typecheckclean inopencodeandcore.Screenshots / recordings
Not a UI change.
Checklist