Skip to content

fix(cli): switch to the code model after planning - #13112

Merged
johnnyeric merged 3 commits into
mainfrom
johnnyeric/fix-plan-to-code-model-switch
Aug 17, 2026
Merged

fix(cli): switch to the code model after planning#13112
johnnyeric merged 3 commits into
mainfrom
johnnyeric/fix-plan-to-code-model-switch

Conversation

@johnnyeric

@johnnyeric johnnyeric commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Issue

Fixes #13109

Context

Leaving a planning session via Start new session or Continue here was still billing the planning model. The first implementation turn now uses the saved or configured code model.

resolveCodeModel treated a failed standalone catalog lookup as “no code model” and fell through to the planning model. Interrupt + “go on” then used the TUI picker, which is why the correct model appeared only after stopping.

Implementation

Catalog lookups now go through the shared AppRuntime instead of a standalone provider runtime whose first failure was cached forever. KilocodeModelState reads model.json so a branded parse cannot drop the saved pick.

stamp() distinguishes a genuine ModelNotFoundError (fall through to the configured code model) from a transient catalog failure (keep the saved IDs; the session loop already validates). The resolved model is applied on new-session creation and via setAgentModel on Continue here only.

When no saved or configured code pick exists, the planning model is kept. Handover still tries the compaction model, then the planning model, and skips if neither resolves.

TUI question-picker agent switching was dropped: the existing prompt sync effect already flips agent/model when the injected code-mode message lands. VS Code still gets an optimistic agent flip from option.mode.

Screenshots / Video

Plan model selection

Screenshot 2026-08-17 at 13 55 35

Code model selection (after plan exit "Start in a new session"

Screenshot 2026-08-17 at 13 55 05

How to Test

Manual/local verification

  • Agent: cd packages/opencode && bun test ./test/kilocode/plan-followup.test.ts (34 pass). bun run typecheck in packages/opencode clean. CI on 5e9b76fe36 green.
  • Human: in this worktree run bun dev. Switch to code, pick model A. Switch to plan, pick model B, ask for a short plan. On Ready to implement?, choose Continue here — footer/model should be A, not B. Start new session should open already on code + A.

Reviewer test steps

  1. Run bun dev from this worktree (not PATH kilo).
  2. /agentcode, select a code model.
  3. /agentplan, select a different planning model.
  4. Ask for a short plan and wait for Ready to implement?
  5. Choose Continue here and confirm the implementation turn uses the code model from step 2.
  6. Repeat with Start new session and confirm the new session is code + that model.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02e83206a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review of 5e9b76fe ("Restore plan-model fallback for handover generation"). The previous suggestion is resolved: generateHandover now falls back to the plan model via the shared lookup helper when the compaction agent's model is missing or its catalog lookup fails, and a new test covers that path. The earlier TUI findings remain out of scope (those files left the PR diff).

Files Reviewed (2 files)
  • packages/opencode/src/kilocode/plan-followup.ts
  • packages/opencode/test/kilocode/plan-followup.test.ts
Previous Review Summaries (5 snapshots, latest commit 645b306)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 645b306)

Status: 1 Issue Found | Recommendation: Address before merge

Incremental review of 645b3066 ("keep plan follow-up off recent-model fallback"). The recent-model fallback loop in resolveCodeModel was removed along with its two tests; the remaining test suite still covers the plan-model fallback path. One new suggestion on a subtle behavior change in generateHandover. Previous findings (Codex P2, recent-model fallback suggestion) are resolved or moot — the TUI findings are out of scope since those files left the PR.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/plan-followup.ts 115 entry?.model ?? input.model drops the plan-model fallback when the compaction agent's model lookup fails — handover is silently skipped instead of retrying with the plan model
Files Reviewed (2 files)
  • packages/opencode/src/kilocode/plan-followup.ts - 1 issue
  • packages/opencode/test/kilocode/plan-followup.test.ts

Fix these issues in Kilo Cloud

Previous review (commit baf3281)

Status: No Issues Found | Recommendation: Merge

Incremental review of baf32815 (PR rebased and slimmed to 3 files). All previous findings are resolved or no longer in scope:

  • WARNING (question.tsx apply(last) no-op): the PR no longer touches packages/tui/ — the mode-application changes were removed from scope.
  • SUGGESTION (question-mode.test.ts placement): file no longer in the PR.
  • SUGGESTION (plan-followup.ts recent-model fallback tried only the first entry): fixed — resolveCodeModel now loops over all state.recent entries and skips stale ones (ModelNotFoundErrorundefined → next candidate).
  • Codex P2 (retain fallback for genuinely missing saved models): addressed — stamp() distinguishes a real Provider.ModelNotFoundError (falls through to configured code model, then recent models) from a transient catalog failure (keeps the saved pick, matching the PR's stated intent that the session loop validates).

New code verified: modelIfAvailable error handling, KilocodeModelState.get() (never rejects on missing/malformed state), variant: "default" sentinel matches existing convention in session/prompt.ts, Session.create/setAgentModel signatures accept the passed shapes, and no new resource leaks (pending map cleanup unchanged, abort listener removed in finally). Changeset present; new tests cover the saved-model-kept-on-catalog-failure, configured-fallback, and stale-recent-skip paths.

Files Reviewed (3 files)
  • .changeset/plan-to-code-model-switch.md
  • packages/opencode/src/kilocode/plan-followup.ts
  • packages/opencode/test/kilocode/plan-followup.test.ts

Previous review (commit 3284c1f)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2

Incremental review of 3284c1f5: the only change since ff79f157 is a kilocode_change marker added to the const last = answers.flat().at(-1) line in question.tsx — marker hygiene on a shared upstream file, no behavioral change and no new memory-leak surface. No new issues found; the three previous findings were re-verified against current HEAD and remain open.

Issue Details (click to expand)

WARNING

File Line Issue
packages/tui/src/routes/session/question.tsx 64 apply(last) in submit() is a silent no-op — submit() only runs on the confirm tab where options() is empty, and it resolves against the current tab's options rather than the question each answer came from. Plan follow-up (single question) works via pick(), but the multi-question path never applies a mode.

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/plan-followup.ts 232 The recent-model fallback tries only the first non-plan entry — one stale entry (ModelNotFoundError) makes the whole fallback silently give up instead of trying the next recent model.
packages/tui/src/kilocode/question-mode.test.ts 1 Only test co-located in packages/tui/src/; all other TUI tests live in packages/tui/test/. Works, but diverges from convention.
Files Reviewed (6 files)
  • .changeset/plan-to-code-model-switch.md
  • packages/opencode/src/kilocode/plan-followup.ts - 1 issue
  • packages/opencode/test/kilocode/plan-followup.test.ts
  • packages/tui/src/kilocode/question-mode.ts
  • packages/tui/src/kilocode/question-mode.test.ts - 1 issue
  • packages/tui/src/routes/session/question.tsx - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit ff79f15)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2

Incremental review of ff79f157: the stamp/pick refactor correctly distinguishes a genuinely missing saved model (ModelNotFoundError → falls through to the configured code model, resolving the Codex P2 finding) from a transient catalog failure (keeps the saved IDs), generateHandover now falls back to the input model and fails soft, and setAgentModel moved to the continue-here path only — where the plan→code switch actually happens. New tests exercise the real implementation through the existing runtime seams. No new subscriptions, listeners, or map entries — no memory-leak surface added. No new issues found; the three previous findings were re-verified against current HEAD and remain open.

Issue Details (click to expand)

WARNING

File Line Issue
packages/tui/src/routes/session/question.tsx 64 apply(last) in submit() is a silent no-op — submit() only runs on the confirm tab where options() is empty, and it resolves against the current tab's options rather than the question each answer came from. Plan follow-up (single question) works via pick(), but the multi-question path never applies a mode.

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/plan-followup.ts 232 The recent-model fallback tries only the first non-plan entry — one stale entry (ModelNotFoundError) makes the whole fallback silently give up instead of trying the next recent model.
packages/tui/src/kilocode/question-mode.test.ts 1 Only test co-located in packages/tui/src/; all other TUI tests live in packages/tui/test/. Works, but diverges from convention.
Files Reviewed (5 files)
  • packages/opencode/src/kilocode/plan-followup.ts - 1 issue
  • packages/opencode/test/kilocode/plan-followup.test.ts
  • packages/tui/src/kilocode/question-mode.ts
  • packages/tui/src/kilocode/question-mode.test.ts - 1 issue
  • packages/tui/src/routes/session/question.tsx - 1 issue

Fix these issues in Kilo Cloud

Previous review (commit 446c42e)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2

Incremental review of 5b379c21: the new recent-model fallback in resolveCodeModel is directionally right (ordering confirmed most-recent-first, stamp still distinguishes a genuinely missing model from a transient catalog failure, and the new test matches file conventions). No new subscriptions, listeners, or map entries — no memory-leak surface added. One new edge-case suggestion, plus two still-open findings from the previous review re-verified against current code.

Issue Details (click to expand)

WARNING

File Line Issue
packages/tui/src/routes/session/question.tsx 64 apply(last) in submit() is a silent no-op — submit() only runs on the confirm tab where options() is empty, and it resolves against the current tab's options rather than the question each answer came from. Plan follow-up (single question) works via pick(), but the multi-question path never applies a mode.

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/plan-followup.ts 218 The recent-model fallback tries only the first non-plan entry — one stale entry (ModelNotFoundError) makes the whole fallback silently give up instead of trying the next recent model.
packages/tui/src/kilocode/question-mode.test.ts 1 Only test co-located in packages/tui/src/; all other TUI tests live in packages/tui/test/. Works, but diverges from convention.
Files Reviewed (5 files)
  • packages/opencode/src/kilocode/plan-followup.ts - 1 issue
  • packages/opencode/test/kilocode/plan-followup.test.ts
  • packages/tui/src/kilocode/question-mode.ts
  • packages/tui/src/kilocode/question-mode.test.ts - 1 issue
  • packages/tui/src/routes/session/question.tsx - 1 issue

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 125.2K · Output: 5.3K · Cached: 317.8K

Review guidance: REVIEW.md from base branch main

Comment thread packages/tui/src/routes/session/question.tsx Outdated
Comment thread packages/tui/src/kilocode/question-mode.test.ts Outdated
Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
@johnnyeric
johnnyeric force-pushed the johnnyeric/fix-plan-to-code-model-switch branch from ff79f15 to a3516c1 Compare August 13, 2026 20:50
Keep the saved or configured code model when leaving a planning session,
even if the catalog lookup fails, so implementation starts on the code
model instead of the planning one.

Fall back through recent models when no code pick exists, skip handover
when its model cannot be resolved, and stamp setAgentModel only on
Continue here.
@johnnyeric
johnnyeric force-pushed the johnnyeric/fix-plan-to-code-model-switch branch from 3284c1f to baf3281 Compare August 14, 2026 16:44
Preserve the planning model when no saved or configured code pick
exists. Look up the handover model once from the compaction agent
or the planning model.
Comment thread packages/opencode/src/kilocode/plan-followup.ts Outdated
If the compaction agent's configured model is missing from the catalog,
look up the planning model before skipping handover.
@johnnyeric
johnnyeric merged commit 2eb6300 into main Aug 17, 2026
45 of 49 checks passed
@johnnyeric
johnnyeric deleted the johnnyeric/fix-plan-to-code-model-switch branch August 17, 2026 12: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.

[BUG] Not switching models when moving from planning to code

2 participants