fix(tui): refresh prompt on model switch#2534
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Harvested #2534 into #2504 for v0.8.50 as I also added a maintainer follow-up in Local validation on #2504 after the harvest:
Thanks for the focused fix. Once #2504 lands, this draft PR should be treated as superseded by the release harvest. |
|
Thanks @cyq1017 — your contribution landed in
Closing this PR now that the code is on If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the |
Refs #2379
Problem:
/modelupdated the engine model but only emitted a status event.Change:
Op::SetModel.SessionUpdated.Verification:
cargo test -p codewhale-tui set_model_reloads_instruction_sources_and_updates_session_prompt --lockedcargo test -p codewhale-tui model_change_update_syncs_engine_model_before_compaction --lockedcargo fmt --all -- --checkgit diff --checkGreptile Summary
This PR fixes a bug (#2379) where using
/modelto switch the AI model updated the engine state but left the session system prompt stale until the next conversation turn. The fix carriesAppModeinOp::SetModel, callsrefresh_system_prompt(mode)in the engine handler, and emitsSessionUpdatedso the UI sees the refreshed prompt immediately.Op::SetModelgains amode: AppModefield; all six call sites inui.rsare updated to passapp.mode, and the engine handler now callsrefresh_system_promptthenemit_session_updatedin the correct order (after the model and config are already updated).SetModelis sent beforeSetCompactionand now carries the correct mode.Confidence Score: 4/5
Safe to merge; the model-switch stale-prompt bug is correctly fixed and all call sites are updated.
The core change is tight and correct — model, config, prompt refresh, and session event all happen in the right order. All six SetModel construction sites in ui.rs pass the current mode, and two regression tests cover both the instruction-file reload path and the op-ordering guarantee. The only gap is that Tab-cycling the mode without a model change still leaves the engine prompt stale, but that is a pre-existing limitation unrelated to the code introduced here.
No files require special attention; the one observation is in ui.rs around the Tab-cycle mode path.
Important Files Changed
Comments Outside Diff (1)
crates/tui/src/tui/ui.rs, line 3409-3418 (link)When the user presses Tab to cycle through Plan → Agent → Yolo,
cycle_mode()changesapp.modebut notapp.model, so theapp.model != prior_modelguard is false and noOp::SetModelis ever sent. The engine's system prompt therefore stays stale until the next AI turn, even though the new mode uses different prompt content (e.g., Yolo enables auto-approval and alters the tooling section).Op::ChangeModeexists in the op-set but is never sent anywhere. With therefresh_system_prompt(mode)path now wired inSetModel, a sibling fix for pure mode changes would be straightforward — either sendOp::SetModel { model: app.model.clone(), mode: app.mode }unconditionally when mode changes, or start sendingOp::ChangeModeand callrefresh_system_promptthere too.Reviews (1): Last reviewed commit: "fix(tui): refresh prompt on model switch" | Re-trigger Greptile