Description
When a request fails with CONTENT_LENGTH_EXCEEDS_THRESHOLD error (or similar), the totalTokens field in sessions.json is incorrectly set to the contextWindow value instead of preserving the actual accumulated token count.
Steps to Reproduce
- Have a long conversation that accumulates tool results (e.g., multiple
web_fetch calls)
- Eventually the request body exceeds the provider's size limit (~1.5MB for some proxies)
- Request fails with
CONTENT_LENGTH_EXCEEDS_THRESHOLD
- Check
sessions.json - totalTokens is now set to contextWindow (e.g., 140000)
Expected Behavior
totalTokens should remain at its previous value or be calculated from the transcript.
Actual Behavior
totalTokens is set to contextWindow value (140000), causing the UI to show 140000 / 140000 which misleads users into thinking the context is full.
Evidence
From transcript, last successful request had input: 113546 tokens, but sessions.json showed totalTokens: 140000.
Environment
- OpenClaw version: 2026.2.9
- Provider: zhongzhuan (anthropic-messages API)
Workaround
Manually edit sessions.json to fix the totalTokens value.
Description
When a request fails with
CONTENT_LENGTH_EXCEEDS_THRESHOLDerror (or similar), thetotalTokensfield insessions.jsonis incorrectly set to thecontextWindowvalue instead of preserving the actual accumulated token count.Steps to Reproduce
web_fetchcalls)CONTENT_LENGTH_EXCEEDS_THRESHOLDsessions.json-totalTokensis now set tocontextWindow(e.g., 140000)Expected Behavior
totalTokensshould remain at its previous value or be calculated from the transcript.Actual Behavior
totalTokensis set tocontextWindowvalue (140000), causing the UI to show140000 / 140000which misleads users into thinking the context is full.Evidence
From transcript, last successful request had
input: 113546tokens, butsessions.jsonshowedtotalTokens: 140000.Environment
Workaround
Manually edit
sessions.jsonto fix thetotalTokensvalue.