-
-
Notifications
You must be signed in to change notification settings - Fork 69.2k
Bug: totalTokens incorrectly set to contextWindow on request failure #15150
Copy link
Copy link
Closed
Description
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_fetchcalls) - 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-totalTokensis now set tocontextWindow(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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.