Skip to content

[Bug]: Session contextTokens gets stuck at lower model limit after model switch (e.g. 198k -> 160k -> stays 160k) #35372

@WhiteGiverMa

Description

@WhiteGiverMa

Bug type

Behavior bug (incorrect output/state without crash)

Summary

When switching models in an existing session, contextTokens can become "stuck" at a lower value.

Example:

  • Model A context window: ~198k
  • Switch to Model B context window: ~160k
  • Switch back to Model A
  • Session still reports/uses ~160k context window (in session file and runtime behavior)

This causes premature compaction and incorrect context accounting.

Steps to reproduce

  1. Configure two models with different context windows (for example 198k and 160k).
  2. Start a session (OpenClaw TUI / gateway-client).
  3. Use Model A (198k).
  4. Switch to Model B (160k).
  5. Switch back to Model A (198k).
  6. Check /status and/or session store file (contextTokens).

Expected behavior

  • Context window should update based on the currently selected provider/model each time.
  • After switching back to Model A, context should return to ~198k

Actual behavior

  • contextTokens remains at the lower value (~160k) and appears effectively hardcoded in session state.
  • Switching back to higher-context model does not restore the larger context window in that session.

OpenClaw version

2026.3.2

Operating system

Ubuntu 24.04.4

Install method

npm global

Logs, screenshots, and evidence

n/a

Impact and severity

  • Early compaction / pruning
  • Incorrect status reporting
  • Reduced usable context in long-running sessions

Additional information

This looks related to previous context-window cache/provider-resolution issues:

Could be a regression or another path where session state keeps stale contextTokens after model switch

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug:behaviorIncorrect behavior without a crash

    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