Skip to content

Model switch can fail silently when carried-over session context is too large #58957

@LunaLee0130

Description

@LunaLee0130

Summary

When switching models or continuing in a long-running session, OpenClaw can appear to fail silently when the carried-over context is too large. There is no clear error message indicating that the prompt/context window was exceeded, so users cannot tell whether the problem is caused by context overflow, model switching, transport issues, or something else.

Why this is confusing

From the user side, it looks like:

  • the model switch "doesn't work"
  • the session becomes unresponsive or errors unclearly
  • there is no actionable hint that the previous session history is the real cause

In practice, starting a fresh session (/new <model>) works, which strongly suggests the old context was too large and got carried into the model switch.

Expected behavior

At minimum, OpenClaw should surface a clear, user-visible reason, e.g.:

  • context window exceeded
  • prompt too large for selected model
  • session history too long to carry over during model switch

And ideally it should offer a graceful fallback, such as:

  1. automatically compacting the session before/while switching models
  2. prompting the user to compact
  3. transparently starting a compacted continuation session
  4. providing a one-click suggested recovery action in the UI/CLI

Actual behavior

  • No obvious error message explaining the root cause
  • Users have to guess that the session context is too large
  • Recovery is manual and non-obvious (/new <model> or maybe /compact, if the user already knows to try that)

Reproduction (likely)

  1. Use a long-running session with a lot of accumulated history/tool output
  2. Switch to another model
  3. Observe that the session fails unclearly / does not provide a useful explanation
  4. Start a fresh new session with the same target model
  5. The new session works normally

Proposed improvements

1) Better error reporting

If a request fails due to token/context limits, show a specific message instead of a generic or silent failure.

Example:

This session is too large to continue with the selected model. Try /compact or start a fresh session with /new <model>.

2) Automatic compaction

On model switch (or any continuation that exceeds limits), automatically attempt compaction before failing.

3) Safer model switching UX

If the target model has a smaller effective context budget than the current session size, warn before switching or provide an automatic downgrade path.

4) Better observability

Include some visibility into:

  • current estimated session size
  • selected model context budget
  • whether compaction was attempted

Environment

Observed in Telegram/OpenClaw chat workflow while switching models in an existing session.

Impact

This creates a bad UX because the failure mode is silent or ambiguous. Users who are not already familiar with OpenClaw internals will not know that the session simply became too large.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.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