bug(session): /clear leaves stale total_tokens, session_cost, and cache history
Description
/clear only resets a subset of session-level telemetry, so /cost,
/tokens, and /cache continue to display pre-clear values for the
same logical session that the user just cleared.
This was first surfaced by Copilot's review of PR #967
(https://github.com/Hmbown/DeepSeek-TUI/pull/967#discussion -- the
commands/core.rs L56 / L68 comments) and is reproducible on
current main without any of that PR's other changes.
Steps to reproduce
- Start a fresh session:
cargo run --bin deepseek. - Send one or two prompts that hit cache and produce non-zero cost (any DeepSeek V4 model in thinking mode is fine).
/cost-- notesession_costis non-zero./cache-- note the per-turn cache history shows recorded turns with cache hit / miss tokens./tokens-- notetotal_tokensand last prompt cache hit/miss are populated.- Run
/clear. - Run
/cost,/cache,/tokensagain.
Expected behavior
After /clear, all session-level telemetry that conceptually belongs
to "this conversation" should also be cleared:
session.total_tokensreset to0session.session_cost(and CNY mirror) reset to0.0session.last_prompt_cache_hit_tokens/last_prompt_cache_miss_tokensreset toNonesession.turn_cache_historycleared
This matches the reset semantics already applied to
total_conversation_tokens, total_reasoning_tokens,
last_prompt_tokens, last_completion_tokens,
last_reasoning_tokens, and last_reasoning_replay_tokens inside
crates/tui/src/commands/core.rs::clear.
Actual behavior
session.total_tokens, session.session_cost*, the
last_prompt_cache_* fields, and the entire turn_cache_history
ring are left untouched by clear(), so the next /tokens,
/cost, and /cache still show pre-clear data while /cost
arithmetic also becomes inconsistent (cost accrued under tokens
that have just been zeroed).
Proposed scope (single-invariant PR)
One small PR limited to:
crates/tui/src/commands/core.rs-- extendclear()with the five resets listed above (no other behavior change).- a single new regression test in
crates/tui/src/commands/core.rs(orcrates/tui/tests/) that seeds the missing fields, callsclear, and asserts they are all back to defaults.
No localization, no new public API, no telemetry semantic change.
Environment
- Branch: current
Hmbown/DeepSeek-TUImain(c7ed05a). - Rust: 1.88+ (stable).
AI-use disclosure / human-owner statement
This issue and its proposed fix were drafted with AI assistance (GitHub Copilot / Claude). The human owner is @peixl, who 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 clear_resets_session_telemetry --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
/cost,/cache,/tokensare all zeroed after/clear.
Refs: PR #967 (closed) review comments on
crates/tui/src/commands/core.rs lines 56 and 68.