CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

bug(telemetry): provider/model switch mislabels prior turn_cache_history under new model

Open peixl opened this issue 6 months ago • 0 comments

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

  1. Start a session on deepseek-v4-pro. Run a few prompts so turn_cache_history has rows.
  2. /model deepseek-v4-flash (or switch provider through any supported path).
  3. Run /cache.

Expected behavior

Either:

  • (a) turn_cache_history is cleared on provider/model switch and /cache shows only rows recorded under the new model, or
  • (b) each TurnCacheRecord carries the provider/model it was recorded under and /cache renders 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 -- clear turn_cache_history.
  • crates/tui/src/commands/core.rs::model -- clear turn_cache_history on 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-TUI main (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 /cache is 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.

peixl avatar May 07 '26 08:05 peixl