Skip to content

Bug: totalTokens incorrectly set to contextWindow on request failure #15150

@followdeep

Description

@followdeep

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

  1. Have a long conversation that accumulates tool results (e.g., multiple web_fetch calls)
  2. Eventually the request body exceeds the provider's size limit (~1.5MB for some proxies)
  3. Request fails with CONTENT_LENGTH_EXCEEDS_THRESHOLD
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions