Skip to content

feat: use model fallbacks after context overflow recovery - #170141

Merged
steipete merged 5 commits into
mainfrom
feat/context-overflow-fallback
Oct 13, 2026
Merged

steipete merged 5 commits into
mainfrom
feat/context-overflow-fallback

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #9986

What Problem This Solves

A request that still exceeds the primary model's context window after recovery fails even when a configured fallback can handle it.

User Impact

Replay-safe turns can finish on a configured fallback after compaction and oversized-tool-result recovery are exhausted, with a visible warning naming the model that answered and why it changed. Existing model locks, explicit fallback overrides (including []), operator restrictions, and replay guards still apply. No configuration or migration is required.

Why This Change Was Made

The embedded recovery owner still tries to make the primary request fit first. Its terminal overflow result now reaches the existing fallback owner, which prefers remaining candidates whose known effective context windows fit and preserves configured order within each group. Unknown or smaller windows remain eligible; when provider token counts are absent, larger-window preference is a hint rather than a fit guarantee. Exhaustion preserves the original overflow guidance. Embedded provider request-size/TPM ceilings remain terminal.

Thanks to @amirarenco-create for the feature request and @KarimVKarmali for the local-model reproduction, and to @engagepy and @zhupeng0o0 for the additional reports.

Evidence

  • Final integration head: 09754eef5fb91ef76ffed5991e0025a5dac3a347; merged main 069d40e40cfdadee9c18700168883709fd58693d to take existing runtime-configuration fixture repairs. The four feature implementation files and four feature test files are byte-identical to the reviewed version. No additional production change was needed for CI repair.
  • Local macOS proof: 145 tests passed. Six fallback/classifier files passed 119 tests in 799.40 s wall time; cleanup, rooted-workspace, and suspension files passed all 26 tests in 816.12 s. Commands used the repository node scripts/run-vitest.mjs <files> --maxWorkers=1 wrapper. Times include cold compilation and wrapper cleanup on the shared Mac.
  • node scripts/worktree-setup.mjs gateway passed; build phases took 8m 38.4s. Core production and changed-test typechecks passed; the latter selected the agents-other graph. Targeted lint and formatting passed. All seven required ratchets passed: max-lines, line-cap, assertion-safety, test-timeout-race, test-mock-exports, config docs, and plugin inventory.
  • Fresh isolated Codex autoreview: scoped-clean, no actionable P0–P2 findings. Integration retained the reviewed feature implementation and tests unchanged.
  • Native Ollama CLI proof from the original feature validation remains applicable to the unchanged implementation: qwen3:4b at 8,192 tokens failed on base 856ae491f235bd70a9ac85d1ad1384fe5acdd2b3 with no fallback (37.28 s); the feature completed the same 52,657-character synthetic request through configured qwen3:8b at 32,768 tokens, returning OVERFLOW_FALLBACK_OK, fallbackUsed: true, and reason context_overflow (136.05 s). This CI repair did not rerun live inference.
  • No model-facing prompt changes (token delta: 0), new dependencies, config options, schemas, or storage. Production LOC: +91 / -21 (net +70); tests: +410 / -28 (net +382); docs: +9 / -3. Context-fit ordering and classification account for the production growth; nearby cleanup removes the blanket overflow stop and consolidates fallback warning ownership.
CI attribution and main integration

Original run 38305345929 checked merge c48e94c2aea8e72201bd984f90f1580f7f31c41e against exact main base c5b9b254bff4d728447da563b2c29de8461a2007. Its 234 extension entries comprise 233 test failures and one suite-loading failure; it also had 22 other core failures and four cleanup failures.

The strict runtime-config snapshot migration on that base exposed fixtures that previously relied on lazy config loading. Paired local runs covered every distinct extension error group, plus cleanup: direct native-policy errors, plugin-load errors, missing native requests, native timeouts, startup errors, agent-end behavior, Copilot finalization, and scheduled approvals. The native tests call their attempt/compaction owners directly, without entering the changed fallback runner. The scheduled-approval and plugin-load failures reproduce exactly on the base and pass on the original PR head; the cleanup representative reproduces the exact runtime-config rejection and 120-second timeout on the base and passes on the original head. Main already supplies the missing fixture configuration in d8253ad5ef5df239276c29d706775b8ae39a06f6, cbc53ac75eca314efebdcc57cfcbb68ce5d4e99e, and the cleanup repair in 4944a6df77080f328fed59ee22384e3ee45d522f.

The warm-claim settlement representative passes on the original PR head. Running it after the same preceding explicit-target test used by CI reproduces the exact base failure: initialize and initialized are sent, but configRequirements/read is absent (210.99 s wall; preceding test passed). A cold filtered run stopped one checkpoint earlier; the ordered run resolves that attribution gap without changing either test or its timeout. The integration's complete cleanup/rooted/suspension suite is green; broad extension coverage belongs to the new exact-head CI run.

Local proof entry point

The message asks for OVERFLOW_FALLBACK_OK after 700 synthetic padding rows. Isolated state/config and profile were used; no operator state or running Gateway was touched.

OPENCLAW_STATE_DIR=/private/tmp/oc-lm-feat-overflow-fallback/candidate-state-v2 \
OPENCLAW_CONFIG_PATH=/private/tmp/oc-lm-feat-overflow-fallback/state/openclaw.json \
TMPDIR=/private/tmp/oc-lm-feat-overflow-fallback/tmp \
pnpm openclaw --profile feat-overflow-fallback agent --local \
  --agent main --session-id overflow-candidate \
  --message "$(cat /private/tmp/oc-lm-feat-overflow-fallback/message.txt)" \
  --json --timeout 180

This exercises the CLI, embedded context recovery, fallback selection, native Ollama generation, and visible terminal result. The primary's oversized-message rejection is OpenClaw's precheck; the separate composition test covers a provider still rejecting after bounded compaction.

Exact-head validation complete for 09754eef5fb91ef76ffed5991e0025a5dac3a347: CI run 38323581294 passed, including all three extension bundles and openclaw/ci-gate (44 successful jobs, 26 intentionally skipped, no failures). ClawSweeper reviewed this exact head with no findings and no Before merge items. Its proof-only note is that a base-failing run of the added regression tests is not recorded; the supplied native CLI comparison provides before-and-after user-flow evidence. No additional proof cycle was pursued for that note. CI wall times: extension bundles 1/2/3 took 352/646/366 seconds; compact-large-13 took 253 seconds. The PR remains open and is not being merged by this repair lane.

After replay-safe compaction recovery is exhausted, prefer configured fallback models with known context headroom and report the answering model. Preserve explicit fallback overrides, operator restrictions, and blocked guidance on exhaustion.

Refs #9986. Reported by @amirarenco-create, with the local-model use case from @KarimVKarmali.
Use the detached runner contract and fixed model metadata for compaction/fallback integration proof. Assert the existing replay veto without coupling it to a particular terminal error kind.
@steipete steipete added the ci:no-fail-fast Keep all selected CI matrix jobs running after failures on the next PR run. label Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR tries configured model fallbacks after replay-safe context-overflow recovery is exhausted, preferring candidates with known context headroom.

Example: A 52,657-character synthetic request exceeds qwen3:4b's configured 8,192-token window.

  • Before: The CLI returns overflow guidance without trying the configured fallback.
  • After: The supplied CLI proof completes through qwen3:8b at 32,768 tokens with OVERFLOW_FALLBACK_OK and reason context_overflow.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Useful maintainer-directed feature with shipped CLI evidence, focused behavioral coverage, successful reviewed-head CI, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied isolated macOS CLI proof exercises embedded overflow recovery and native Ollama fallback: the primary fails on base, while unchanged feature code completes the same synthetic request on the configured larger model with overflow attribution.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: A turn fails after exhausting context recovery even when a configured fallback can handle the request.
Reason: The concrete local-model report establishes value, and maintainer authorship supplies direction for changing the intentional exclusion.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it delivers a maintainer-approved recovery capability missing from current main, with no actionable defects found.

Priority: P2
Reviewed head: 09754eef5fb91ef76ffed5991e0025a5dac3a347

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A base-failing run of the added regression tests is not recorded; the supplied native CLI comparison provides before-and-after user-flow evidence.
Agent review details

How this fits together

The agent runner recovers oversized requests on the active model, then passes eligible terminal results to the shared fallback controller, which selects another configured model and records the outcome.

flowchart TD
  A[Agent request] --> B[Active model attempt]
  B --> C[Compaction and truncation recovery]
  C --> D[Replay safety classification]
  D --> E[Configured fallback controller]
  E --> F[Candidate context preference]
  F --> G[Answer or preserved overflow guidance]
Loading

Technical review

Best possible solution:

Land recovery-first fallback through the existing controller while retaining replay vetoes, configured model restrictions, and terminal overflow guidance.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the missing routing path; the supplied native CLI comparison demonstrates the user-visible failure and recovery, without a new reproduction run during this review.

Is this the best way to solve the issue?

The change uses existing recovery, classification, context-budget, and fallback owners rather than introducing another routing policy or configuration option.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e26de4eeae75.

Provenance checked

  • Overflow exclusion changes intended behavior with a stated reason (b8f66c2: Keep overflow in inner compaction/retry recovery and avoid worsening failure on a smaller-context fallback.)
  • Fallback success warning keeps the original intent (b9846c9: Centralize fallback observations while preserving outcomes and attribution; this PR moves the existing missing-model warning into that owner and adds overflow explanation.)
  • Provider request-size ceilings keeps the original intent (7e05bd4: Provider quota ceilings must not trigger futile embedded compaction or retries, while transport-owning harnesses retain configured fallback.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +70, Tests +382, Docs +6. Total +458 across 10 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 91 21 +70
Tests 4 410 28 +382
Docs 2 9 3 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 510 52 +458

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: Overflow now advances configured fallback, including through the SDK-exported result classifier; the maintainer-authored direction explicitly accepts this behavior change while preserving strict selections and replay guards.

Label justifications:

  • P2: This improves bounded long-context recovery without evidence of an urgent regression.
  • merge-risk: 🚨 compatibility: Overflow now advances configured fallback, including through the SDK-exported result classifier; the maintainer-authored direction explicitly accepts this behavior change while preserving strict selections and replay guards.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-12T19:16:07.594Z sha 26105c8 :: needs changes before merge. :: none
  • reviewed 2026-10-12T19:47:01.736Z sha ca52bde :: needs changes before merge. :: none
  • reviewed 2026-10-12T20:44:57.923Z sha d5c58f2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T21:28:35.008Z sha d5c58f2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T21:57:58.938Z sha d5c58f2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T23:50:59.014Z sha 09754ee :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 8:03 PM ET / October 13, 2026, 00:03 UTC (Revision 7).

@steipete
steipete marked this pull request as ready for review October 12, 2026 19:39
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 13, 2026
@steipete
steipete merged commit cedf8a9 into main Oct 13, 2026
138 checks passed
@steipete
steipete deleted the feat/context-overflow-fallback branch October 13, 2026 00:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…70141)

* feat: recover context overflow with configured model fallbacks

After replay-safe compaction recovery is exhausted, prefer configured fallback models with known context headroom and report the answering model. Preserve explicit fallback overrides, operator restrictions, and blocked guidance on exhaustion.

Refs openclaw#9986. Reported by @amirarenco-create, with the local-model use case from @KarimVKarmali.

* test: isolate overflow recovery from durable session storage

Use the detached runner contract and fixed model metadata for compaction/fallback integration proof. Assert the existing replay veto without coupling it to a particular terminal error kind.

* test: retain model input literal types in overflow fixtures

* test: prepare runtime config for overflow recovery
steipete added a commit that referenced this pull request Oct 13, 2026
Publish the neutral suite runtime snapshot through the post-reset config owner, leaving run admission and live required-worker enforcement unchanged. Retain the intentional context-overflow failed-attempt receipt from #170141.

Current-main baseline reproduces 52 failures and one passing control. The complete 17-case runner and 26-case auth files pass after preparation; the complete ten-case fault file passes with the exact one-attempt assertion. Scoped types, typed lint, formatting, and independent P0-P2 review pass. Production code is unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
Publish the neutral suite runtime snapshot through the post-reset config owner, leaving run admission and live required-worker enforcement unchanged. Retain the intentional context-overflow failed-attempt receipt from openclaw#170141.

Current-main baseline reproduces 52 failures and one passing control. The complete 17-case runner and 26-case auth files pass after preparation; the complete ten-case fault file passes with the exact one-attempt assertion. Scoped types, typed lint, formatting, and independent P0-P2 review pass. Production code is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling ci:no-fail-fast Keep all selected CI matrix jobs running after failures on the next PR run. docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Trigger model fallback on context length exceeded

1 participant