fix(opencode): keep the session model on injected prompts#38959
Open
iceteaSA wants to merge 1 commit into
Open
fix(opencode): keep the session model on injected prompts#38959iceteaSA wants to merge 1 commit into
iceteaSA wants to merge 1 commit into
Conversation
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. |
6 tasks
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 #38770
Also relevant to #28735 and #23369, which describe the same symptom through paths this does not fully cover.
Type of change
What does this PR do?
A background subagent finishing can silently switch the parent session's model to the agent's configured default. Since Anthropic prompt caching keys on the model, the next turn misses the cache prefix and re-uploads the entire context — on a long session that is the expensive kind of silent. #38770 reports being billed on both models sequentially, which is the same thing seen from the invoice side.
createUserMessageresolves an injected prompt's model as:So any injected prompt that omits
modellands onag.model— the configured default — regardless of what the session was actually using. Two call sites ondevdo exactly that:TaskTool.injectBackgroundResult(packages/opencode/src/tool/task.ts) passesagentandvariantbut nomodel. This is #38770: the completion notification for a background child re-prompts the parent, and the parent's model changes underneath them. It now reads the parent's latest user message and forwards that model explicitly, with the existingvariantretained as a fallback.That also explains the detail in #38770 that looks strange at first — the agent kept reporting the old model as its identity. The system prompt was assembled before the switch; nothing re-runs it when an injected message changes the resolved model, so the prompt and the billed model disagree until the next assembly.
The shell-execution message (
packages/opencode/src/session/prompt.ts) carries provider and model but drops the variant, so a session runningxhighquietly falls back to default reasoning effort. The variant is now preserved when the resolved model carries one. Separate bug, same shape, found while fixing the first.Both fixes only supply what was already implied — neither changes agent resolution, so a genuine agent switch still adopts the new agent's model as before.
I found this from the other end: a live session moved
claude-fable-5→claude-opus-5at a user message with no text (the injected notification), timestamp-matched to its child session completing, landing on exactly that agent's configured default.How did you verify your code works?
Red-first, one test per site, each failing for its own distinct reason against unmodified
dev:Mutation-checked separately, so neither fix is riding on the other's coverage:
Full suite in
packages/opencode: 3208 pass / 0 fail.bun typecheckexit 0.Note on scope: #35195 fixes this class more broadly at the shared resolution point, by consulting the durable session row before the agent default — these two sites would be covered by it. This PR fixes the call sites directly, which is independently useful and does not conflict with that approach.
Screenshots / recordings
Not a UI change.
Checklist