CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

bug(session): /load inherits prior session's turn_cache_history and cost counters

Open peixl opened this issue 6 months ago • 0 comments

Description

/load (and the equivalent "apply loaded session" path in crates/tui/src/tui/ui.rs) restores conversation messages and resets some last-turn token counters, but it does not clear session.turn_cache_history, session.session_cost, session.session_cost_cny, session.subagent_cost, session.subagent_cost_high_water, or session.subagent_cost_event_seqs. None of those fields are persisted in the saved session file, so loading a session inherits whatever was in memory immediately before the load.

This was first surfaced by Copilot's review of PR #967 (crates/tui/src/commands/session.rs L106 and crates/tui/src/tui/ui.rs L5792 review comments) and is reproducible on current main without any of that PR's other changes.

Steps to reproduce

  1. Start a session and run a few prompts so session_cost > 0 and turn_cache_history has rows.
  2. /save my-checkpoint (or use any existing saved session).
  3. Without restarting, /load my-checkpoint (or load any other saved session).
  4. Run /cost and /cache.

Expected behavior

Loading a saved session should present a clean view of that session's recorded state. Cache history and cost counters that were not part of the saved session should be reset to defaults.

Actual behavior

/cache shows the pre-load turn_cache_history rows, attributing them to the loaded session's model. /cost shows session_cost that was accrued from prompts that no longer appear in the transcript (and may be from a different model or provider).

Proposed scope (single-invariant PR)

One small PR limited to:

  • crates/tui/src/commands/session.rs -- in load (around L106 in PR #967's diff range), additionally clear turn_cache_history, session_cost, session_cost_cny, subagent_cost, subagent_cost_high_water, and subagent_cost_event_seqs.
  • The matching apply-loaded-session path in crates/tui/src/tui/ui.rs (around L5792 in PR #967's diff range) must apply the same resets so the two entry points stay in sync.
  • One regression test that seeds the missing fields, calls load on a fixture session file, and asserts they are all back to defaults.

No new public API, no telemetry semantic change beyond the reset.

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 load_resets_cache_history_and_cost --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: run the repro above and confirm /cache shows no rows and /cost reads as a fresh load.

Refs: PR #967 (closed) review comments on crates/tui/src/commands/session.rs line 106 and crates/tui/src/tui/ui.rs line 5792.

peixl avatar May 07 '26 08:05 peixl