Skip to content

status: context usage is misleading when totalTokensFresh=false #45268

@xyooz

Description

@xyooz

Summary

/status can show misleading context usage when session token totals are stale.

When totalTokens is missing and totalTokensFresh=false, the status output currently falls back to inputTokens + outputTokens, which can display values like 299k/200k (149%) even though true context occupancy is unknown.

Why this is a problem

  • It looks like auto-compaction failed, while Compactions may still be 0.
  • It conflates cumulative accounting usage with current in-window context usage.
  • Operators cannot distinguish "unknown" from "actually overflowing".

Repro

  1. Use a session entry where:
    • totalTokens: null
    • totalTokensFresh: false
    • inputTokens: 298437
    • outputTokens: 147
    • contextTokens: 200000
  2. Run /status.

Observed:

  • Context: 299k/200k (149%)
  • Compactions: 0

Expected:

  • Context should be shown as unknown (for example ?/200k or unknown/200k), not inferred from input+output when freshness is false.

Root cause (code)

In status rendering path, total tokens are computed as:

totalTokens = entry.totalTokens ?? (entry.inputTokens + entry.outputTokens)

without checking totalTokensFresh.

Proposed fix

  • Only trust entry.totalTokens when fresh (totalTokensFresh !== false).
  • Do not synthesize context occupancy from input+output when totals are stale.
  • Keep transcript-usage override path (if available) to recover an actually useful total.
  • Add regression test for totalTokensFresh=false.

Version

Observed in OpenClaw 2026.3.11 (commit shown by openclaw --version).

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    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