-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Model fallback selection ignores candidate context windows, causing overflow/compaction storms on mid-turn failover #109436
Copy link
Copy link
Open
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper 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 does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, 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.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper 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 does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, 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.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
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.jsandfallbacks-*.jscontain zero references tocontextWindow/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_uprisk. 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
contextWindowis 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)
context_size/context_length, so registered windows may be wrong; window-aware selection needs those fixed too.