Skip to content

fix(plan): don't carry plan agent model into build on plan_exit - #50609

Closed
log0u7 wants to merge 1 commit into
anomalyco:devfrom
log0u7:plan-exit-build-model
Closed

log0u7 wants to merge 1 commit into
anomalyco:devfrom
log0u7:plan-exit-build-model

Conversation

@log0u7

@log0u7 log0u7 commented Sep 22, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #9296

Note: #9296 was closed pending v2 and the bug still reproduces on dev. Earlier attempts #23971 and #29457 were closed unmerged.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

plan_exit resolved the model for the synthetic build user message from the last user message, which in plan mode carries the plan agent's model. The run loop (SessionPrompt runLoop) picks its model from the newest user message on every turn and never reads agent.build.model mid-loop, so with both agent.plan.model and agent.build.model configured, the build kept running the plan model.

This applies the same precedence createUserMessage uses when creating prompts (input.model ?? ag.model ?? currentModel): the build agent's configured model first, then the last user message's model, then the provider default. The build agent's variant is resolved the way createUserMessage resolves it (only when the agent's configured model was selected and the model exposes that variant).

How did you verify your code works?

  • New test packages/opencode/test/tool/plan.test.ts: with agent.plan.model = test/test-model and agent.build.model = test/build-model, asserts plan_exit stamps build-model on the synthetic message (failed with test-model before the fix); a second case asserts the fallback to the plan model when the build agent has no configured model.
  • bun test test/tool/plan.test.ts test/session/prompt.test.ts in packages/opencode: 61 pass, 1 skip, 0 fail.
  • bun test test/agent/agent.test.ts test/agent/plan-mode-subagent-bypass.test.ts: 48 pass, 0 fail.
  • bun typecheck in packages/opencode: clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Sep 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@log0u7

log0u7 commented Sep 23, 2026

Copy link
Copy Markdown
Author

@stevoland you closed #9296 a while back - this PR fixes the exact repro described there (plan agent's model carried into the build agent on plan_exit), which still reproduces on current dev. Ships with a regression test. Would appreciate your take when you have a moment.

@log0u7

log0u7 commented Sep 27, 2026

Copy link
Copy Markdown
Author

@nexxeln sorry to add to your queue - could you take a look when you have a moment? @stevoland was pinged a few days ago without response so far. It fixes the repro from #9296 and ships with a regression test. Happy to adjust anything.

@log0u7

log0u7 commented Sep 29, 2026

Copy link
Copy Markdown
Author

@rekram1-node hi! This one has been waiting on a review for a while (all checks green, mergeable). It's a small core fix: plan_exit no longer carries the plan agent's model into the build agent. Would you mind taking a look when you get a chance? Happy to adjust anything.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
@log0u7
log0u7 deleted the plan-exit-build-model branch October 10, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experimental plan mode handover -> build uses plan agent's model

2 participants