-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
fix: resolveFreshSessionTotalTokens returns undefined when totalTokens is preserved (post-#82578 regression) #82900
Copy link
Copy link
Open
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Bug:
resolveFreshSessionTotalTokensreturns undefined whentotalTokensis preserved (post-#82578 regression)Symptom
After every 2-3 conversational turns, the
/contextcommand shows stale/unknown context utilization, and the Control UI context meter resets to 0%. The session still works correctly and context IS being sent to the model — this is purely a display/estimation issue.Root Cause
PR #82578 correctly fixed
persistSessionUsageUpdatefrom overwritingtotalTokens=undefinedwhen there is no fresh context snapshot. After the fix,totalTokensis preserved across stale usage updates.However,
resolveFreshSessionTotalTokens()(insrc/types.ts) still returnsundefinedwhenentry?.totalTokensFresh === false, even thoughtotalTokensis now a valid, preserved number. This function is used by:/contextcommand handler → returnsundefined→ "context unavailable"session-utils.tstranscript estimation → returnsundefined→ triggers unnecessary transcript re-readInternal consumers unaffected
The compaction preflight check and memory flush logic check
entry.totalTokensFreshdirectly on the entry object, not throughresolveFreshSessionTotalTokens(). So they are unaffected and continue to work correctly.Real Behavior Data
Flow trace:
session-updates.tssetstotalTokensFresh = false(incrementBy > 0)persistSessionUsageUpdatealso setstotalTokensFresh = falsewhen!hasFreshContextSnapshotresolveFreshSessionTotalTokensseestotalTokensFresh === false→ returnsundefined/contextcommand shows stale/unavailableentry.totalTokensFresh === false(checked directly on entry) → reads from transcript → setstotalTokensFresh = trueSuggested Fix
In
resolveFreshSessionTotalTokens(), return the preservedtotalTokensvalue even whentotalTokensFresh === false, since the value is now guaranteed to be valid (notundefined) after PR #82578.The
totalTokensFreshflag continues to serve its intended purpose for compaction preflight and memory flush, which check it directly onentry.totalTokensFresh.