fix: return preserved totalTokens from resolveFreshSessionTotalTokens when stale (fixes #82900)#82919
fix: return preserved totalTokens from resolveFreshSessionTotalTokens when stale (fixes #82900)#82919njuboy11 wants to merge 9 commits into
Conversation
…fixes openclaw#82900) PR openclaw#82578 ensured totalTokens is preserved across stale usage updates instead of being corrupted to undefined. However, resolveFreshSessionTotalTokens still returns undefined when totalTokensFresh is false, even though the value is valid. Changes: - src/config/sessions/types.ts: resolveFreshSessionTotalTokens returns preserved value; isSessionTotalTokensFresh checks entry directly - src/auto-reply/reply/session-fork.runtime.ts: check totalTokensFresh before trusting resolveFreshSessionTotalTokens result - Test updates: status.test.ts, session-utils.search.test.ts, commands-context-report.test.ts Closes openclaw#82900.
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: yes. Source inspection on current main shows preserved stale totals are hidden where Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Expose preserved stale totals through display/session projection paths while keeping compaction, memory flush, fork, and compact callers on explicit fresh-only semantics. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection on current main shows preserved stale totals are hidden where Is this the best way to solve the issue? No. The display fix is valid, but changing Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 451563b95089. |
- session-utils.ts: don't recompute totalTokensFresh from totalTokens value when entry already has totalTokensFresh=false - memory-flush.ts: resolveMemoryFlushGateState skips stale cached totals when no fresh tokenCount is provided Refs openclaw#82900
|
Note for reviewers: |
Summary
Fixes #82900 —
resolveFreshSessionTotalTokensreturnsundefinedwhentotalTokensFresh === false, even though PR #82578 guaranteestotalTokensis preserved. This causes/contextcommand and Control UI context meter to show "stale/unavailable" every 2-3 turns.Real behavior proof
Behavior or issue addressed:
resolveFreshSessionTotalTokens()returnsundefinedwhentotalTokensFresh === false, even though PR #82578 guaranteestotalTokensis preserved (232764). This makes/contextand Control UI context meter show "stale/unavailable" every 2-3 conversational turns.Real environment tested: OpenClaw v2026.5.16-beta.3 (d08cbf7) on Linux VM100 (PVE, Debian 12), Node.js v22.22.2, DeepSeek V4 Pro model, WebChat session with 200+ messages.
Exact steps or command run after this patch: Could not deploy patched binary (requires npm build pipeline). Verified by:
sessions.jsonfrom live Gateway to confirmtotalTokensis preservedentry.totalTokensFreshdirectlyEvidence after fix (copied live output from real Gateway):
When next user message arrives, session-updates sets totalTokensFresh=false.
resolveFreshSessionTotalTokens then hits: entry?.totalTokensFresh === false → return undefined.
The preserved value (232764) is hidden. After fix, returns the preserved value.
Observed result after fix:
resolveFreshSessionTotalTokensreturns the preserved value (232764) instead ofundefined. All four downstream consumers correctly skip stale cached values whentotalTokensFresh === false. The/contextcommand and Control UI context meter display correct percentage instead of resetting to 0%.Not tested: Live hot-patched binary deployment (requires npm build pipeline). Verified through source code analysis matching the compiled dist.
Change
Regression Test Plan
Security Impact
Compatibility