Skip to content

contextTokens cached in sessions.json is never invalidated when model catalog changes #8937

@loreaai

Description

@loreaai

Bug Description

When a session is created, the contextTokens value from the model catalog is cached in sessions.json. If the catalog later updates with a corrected value (e.g., after a pi-ai update or OpenClaw upgrade), the stale cached value persists indefinitely. The only fix is manually deleting contextTokens from sessions.json and restarting the gateway.

Steps to Reproduce

  1. Start a session with a model whose catalog entry has an incorrect contextWindow (or any value)
  2. The value gets cached in ~/.openclaw/agents/<agent>/sessions/sessions.json as contextTokens
  3. Update OpenClaw or the catalog so the model now has the correct contextWindow
  4. Restart the gateway
  5. Run /status — the old cached value is still displayed

Expected Behavior

On gateway restart (or session resume), contextTokens should be refreshed from the current model catalog rather than relying on the cached value in sessions.json.

Actual Behavior

/status shows the stale cached value (e.g., 1.0m instead of 200k for Claude Sonnet/Opus 4.5).

Workaround

  1. Stop the gateway
  2. Remove contextTokens from all entries in sessions.json
  3. Restart the gateway

Environment

  • OpenClaw: 2026.2.2-3
  • OS: Linux (Ubuntu)
  • Node: v24.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked 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