bug(telemetry): provider/model switch mislabels prior turn_cache_history under new model
Description
When the user changes provider (switch_provider() in
crates/tui/src/tui/ui.rs) or switches model (/model in
crates/tui/src/commands/core.rs), the per-turn cache ring
session.turn_cache_history is not cleared. /cache prints
its header with the current model: value, so older entries
recorded under the previous provider/model are silently
re-attributed to the newly active one.
This was first surfaced by Copilot's review of PR #967
(crates/tui/src/tui/ui.rs L3924 and
crates/tui/src/commands/core.rs L111 review comments) and is
reproducible on current main without any of that PR's other
changes.
Steps to reproduce
- Start a session on
deepseek-v4-pro. Run a few prompts soturn_cache_historyhas rows. /model deepseek-v4-flash(or switch provider through any supported path).- Run
/cache.
Expected behavior
Either:
- (a)
turn_cache_historyis cleared on provider/model switch and/cacheshows only rows recorded under the new model, or - (b) each
TurnCacheRecordcarries the provider/model it was recorded under and/cacherenders them with their original attribution.
Per the PR #967 reviewer note, option (a) is the simpler fix and
matches the existing semantics (we already clear the
last_prompt_cache_* fields on switch).
Actual behavior
/cache shows pre-switch rows under the new model's header,
making per-model cache analysis misleading.
Proposed scope (single-invariant PR)
One small PR, option (a), limited to:
crates/tui/src/tui/ui.rs::switch_provider-- clearturn_cache_history.crates/tui/src/commands/core.rs::model-- clearturn_cache_historyon a real model change (not on a no-op re-set of the same model).- One regression test that seeds two records, performs a model switch, and asserts the ring is empty.
No new public API. No localization. No change to record schema.
Environment
- Branch: current
Hmbown/DeepSeek-TUImain(c7ed05a). - Rust: 1.88+ (stable).
AI-use disclosure / human-owner statement
Drafted with AI assistance (GitHub Copilot / Claude). Human owner @peixl reviews each change line-by-line, owns the resulting PR, and is responsible for the test plan.
Test plan for the eventual PR
cargo test -p deepseek-tui model_switch_clears_turn_cache_history --locked(new test).cargo test -p deepseek-tui provider_switch_clears_turn_cache_history --locked(new test).cargo test -p deepseek-tui --locked.cargo fmt --all -- --check.cargo clippy -p deepseek-tui --all-targets --all-features --locked -- -D warnings.- Manual: reproduce the steps above and confirm
/cacheis empty immediately after the switch.
Refs: PR #967 (closed) review comments on
crates/tui/src/tui/ui.rs line 3924 and
crates/tui/src/commands/core.rs line 111.