fix(stats): persist cache totals + lastPromptTokens across resume#384
Merged
Conversation
`SessionMeta` only carried `totalCostUsd` and `turnCount`, so on every resume `/status` showed: - 0 context — `lastPromptTokens` came from `turns[0]?.usage`, and `turns` is empty before the first live turn fires - 0% cache hit — `aggregateCacheHitRatio` summed `turns[]` only The next API call would still read the cached prefix and answer correctly (turn 1 in the user's log shows 366,976 / 367,085 cache hits), but the panel reported "no context" until that call landed. Persist the missing fields after each turn (`patchSessionMeta`) and seed them on resume (`stats.seedCarryover`). `aggregateCacheHitRatio` and `summary().lastPromptTokens` now fall through to the carryover when no live turn has run yet.
ChasLui
pushed a commit
to ChasLui/DeepSeek-Reasonix
that referenced
this pull request
May 23, 2026
…engine#364) (esengine#384) `SessionMeta` only carried `totalCostUsd` and `turnCount`, so on every resume `/status` showed: - 0 context — `lastPromptTokens` came from `turns[0]?.usage`, and `turns` is empty before the first live turn fires - 0% cache hit — `aggregateCacheHitRatio` summed `turns[]` only The next API call would still read the cached prefix and answer correctly (turn 1 in the user's log shows 366,976 / 367,085 cache hits), but the panel reported "no context" until that call landed. Persist the missing fields after each turn (`patchSessionMeta`) and seed them on resume (`stats.seedCarryover`). `aggregateCacheHitRatio` and `summary().lastPromptTokens` now fall through to the carryover when no live turn has run yet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #364.
Why
SessionMetaonly carriedtotalCostUsdandturnCount. On every resume/statusshowed:summary.lastPromptTokenscame fromturns[0]?.usage, andturnsis empty before the first live turn fires.aggregateCacheHitRatiosummedturns[]only, so it was undefined / 0 immediately after resume.The next API call still hit the cached prefix and answered correctly (the user's transcript shows 366,976 / 367,085 cache hits on turn 1), but the status panel claimed "no context" until that call landed.
What changes
src/memory/session.ts— extendSessionMeta:src/telemetry/stats.ts—seedCarryoveraccepts the three new fields.aggregateCacheHitRationow seedshit/missfrom carryover before summing live turns.summary().lastPromptTokensfalls back to the carryover when no live turn exists yet.src/loop.ts—seedCarryovercall on resume passes the new fields.src/cli/ui/App.tsx—patchSessionMetaafterassistant_finalnow writes:Tests
tests/telemetry.test.ts— 5 new cases: ratio with carryover-only, ratio with carryover + live, lastPromptTokens fallback + override, seedCarryover ignores zero/negative.tests/session.test.ts— new case:CacheFirstLoopresume preloads cache + lastPromptTokens through the meta → stats path.Test plan
npm run verify— 133 files / 2138 passed / 1 skipped (was 2132, +6 new)/statusshows the prior context bar and a non-zero cache hit %, not the previous 0/0 state