Skip to content

Model fallback selection ignores candidate context windows, causing overflow/compaction storms on mid-turn failover #109436

Description

@davidste

Version

v2026.7.1-beta.5 (commit b6387af), analysis of shipped dist code.

Environment

Linux gateway, OpenClaw running as a systemd user service; large-context primary with a 131k-context local terminal fallback.

Summary

Fallback candidate selection never considers the candidate model's context window. A session grown large on a big-context primary that fails over mid-turn to a smaller-window fallback immediately overflows, triggering compaction storms and risking unrecoverable compaction failure.

Code analysis

model-fallback-BV_Bq-Z8.js and fallbacks-*.js contain zero references to contextWindow/contextTokens. Selection is availability-ordered only; there is no check that the current prompt size fits the candidate's window, and no preemptive compaction before switching.

Observed impact

On our gateway: sessions grown on a 1M-context primary failed over mid-turn to a 131k-context local fallback, producing repeated overflow/compaction cycles with observed compaction give_up risk. 34 sessions on this gateway currently exceed 131k tokens — every one of them hits this on failover to the terminal fallback.

Expected behavior

Fallback selection should either (a) skip candidates whose contextWindow is smaller than the current prompt size, or (b) preemptively compact to fit before dispatching to that candidate — and log which path was taken.

Suggested fix

In the candidate loop, compare current prompt token estimate against each candidate's registered context window; skip too-small candidates (configurable), or invoke compaction targeting the candidate's window before the first request to it.

Related (not duplicates)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.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.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions