bug(session): /load inherits prior session's turn_cache_history and cost counters
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
- Start a session and run a few prompts so
session_cost > 0andturn_cache_historyhas rows. /save my-checkpoint(or use any existing saved session).- Without restarting,
/load my-checkpoint(or load any other saved session). - Run
/costand/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-- inload(around L106 in PR #967's diff range), additionally clearturn_cache_history,session_cost,session_cost_cny,subagent_cost,subagent_cost_high_water, andsubagent_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
loadon 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-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 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
/cacheshows no rows and/costreads 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.