Repository navigation
fix(agents): single-source model fallback availability - #134111
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 31, 2026, 11:31 AM ET / 15:31 UTC. ClawSweeper reviewWhat this changesThe PR centralizes model-fallback availability for reply runs, embedded execution, completion metadata, and cron routing so pinned user model overrides do not advertise unavailable fallback behavior. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open: the prior P1 compatibility regression remains on the latest head. The new reply-entry test covers pinned-model suppression, but active fallbacks inherited from defaults still lose the configured-primary candidate. Priority: P1 Review scores
Verification
How this fits togetherA channel reply is prepared with its session model selection, then run through the embedded agent fallback loop. The fallback selection determines which models are attempted and whether retry policy surfaces an error or advances to another candidate. flowchart LR
A[Channel reply and session] --> B[Reply run preparation]
B --> C[Fallback availability]
C --> D[Candidate chain]
D --> E[Embedded agent retry policy]
E --> F[Reply result]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +169, Tests +142. Total +311 across 17 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one prepared availability fact, but preserve whether active models came from an explicit override versus inherited defaults; pass undefined to the candidate builder for the inherited case so it retains the configured primary. Do we have a high-confidence way to reproduce the issue? Yes, from source: configure a primary A and default fallback B, select a different model C, and exhaust C then B. The introduced explicit override suppresses the candidate builder's existing configured-primary append. Is this the best way to solve the issue? No. Centralizing availability is the right owner-boundary direction, but its current active result drops the provenance that distinguishes inherited defaults from an explicit override. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c884d51b870b. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
A pinned-model session with configured default fallbacks now proves at the embedded runner surface that no fallback escalation fires: pre-fix the rate-limit rotation cap escalated to fallback_model over the empty ladder and threw the escalation error after two attempts; post-fix the run spends its full same-model retry budget and surfaces the real rate-limit copy with suspend semantics. Sibling guard keeps fallback engaged for auto provenance.
The embedded-runner fallback e2e file crossed the max-lines lint cap; the mock-free config/workspace/auth-store helpers move to a colocated test-support module with grep-unique exported names.
Reply/command preparation collapsed inherited default fallbacks into an explicit run override, so the candidate resolver stopped appending the configured primary (C->B->A regressed to C->B). Tag availability with explicit/inherited provenance, project it through the new modelFallbackOverrideFromAvailability, and restore resolveEffectiveModelFallbacks to its string[]|undefined contract so command prep and codex diagnostics repair with zero call-site changes. Cron collapses back to a single resolveEffectiveModelFallbacks call.
|
Thanks @obviyus! Proof: Boundary e2e through the real orchestrator/run-loop/failover controller plus a shipped-entry Telegram reply-chain test; both fail on the merge base for the intended reason and pass on the merged head. Full CI green on the exact head.
|
The "are model fallbacks available" fact was derived twice with different rules: resolveEffectiveModelFallbacks emptied the ladder under a user model override while the orchestrator's fallbackConfigured signal did not, so pinned-model runs executed failover policy against a ladder that was empty. On a rate-limited provider the run aborted early with a bogus "escalating to model fallback" error instead of spending its retry budget and surfacing the real rate-limit copy with suspend semantics. One resolver, resolveModelFallbackAvailability, now returns a closed union computed once at run-scope preparation and carried as a prepared fact; the duplicate derivations are deleted and disagreement is unrepresentable. disabled_by_model_override is logged once per run so operators learn why no fallback fired. Evidence: fail-pre-fix boundary e2e (model-fallback.run-embedded.e2e.test.ts) plus shipped-entry Telegram reply chain proof (model-fallback.reply-entry .e2e.test.ts); sibling and unit suites green on the exact head. Co-authored-by: Ayaan Zaidi <[email protected]>
…er (#134281) Three uncoordinated retry layers replayed the same provider request on a transient failure: provider SDK client defaults, a per-request retry loop inside the ChatGPT transport, and an outer whole-turn replay in the reply runner. Stacked, one transient 429 could hold a turn silently for minutes, and the failover controller that owns provider/model fallback never saw the attempts it needed to budget. Transient retry now has one owner: the embedded runner's failover retry controller. `retry.provider.maxRetries` is its attempt budget (default 3), the retry window stays flat at 90s so time-to-failover stays bounded, and window truncation is recorded at the producer. SDK clients run with `maxRetries: 0`, the ChatGPT transport loop is deleted, and the outer overload replay plus `OverloadRetryState` and the obsolete `StreamOptions.maxRetries` knob are removed. User impact: a transient blip retries quickly and quietly, then succeeds or follows the existing failover chain; a persistent outage surfaces within 90s with curated, actionable copy instead of minutes of silence. An unprepared provider HTTP 500 now reads "provider internal error" instead of "request timed out". Not a breaking change: a saved `retry.provider.maxRetries` keeps a coherent meaning and needs no migration. Named tradeoffs: the 30s "still retrying" notice is gone, and worst-case transient patience drops from about 217s to 90s. Production LOC: +463 / -685 across 44 files, net -222. Follows #134103 and #134111 in the LLM error-UX series. Co-authored-by: Ayaan Zaidi <[email protected]>
…er (openclaw#134281) Three uncoordinated retry layers replayed the same provider request on a transient failure: provider SDK client defaults, a per-request retry loop inside the ChatGPT transport, and an outer whole-turn replay in the reply runner. Stacked, one transient 429 could hold a turn silently for minutes, and the failover controller that owns provider/model fallback never saw the attempts it needed to budget. Transient retry now has one owner: the embedded runner's failover retry controller. `retry.provider.maxRetries` is its attempt budget (default 3), the retry window stays flat at 90s so time-to-failover stays bounded, and window truncation is recorded at the producer. SDK clients run with `maxRetries: 0`, the ChatGPT transport loop is deleted, and the outer overload replay plus `OverloadRetryState` and the obsolete `StreamOptions.maxRetries` knob are removed. User impact: a transient blip retries quickly and quietly, then succeeds or follows the existing failover chain; a persistent outage surfaces within 90s with curated, actionable copy instead of minutes of silence. An unprepared provider HTTP 500 now reads "provider internal error" instead of "request timed out". Not a breaking change: a saved `retry.provider.maxRetries` keeps a coherent meaning and needs no migration. Named tradeoffs: the 30s "still retrying" notice is gone, and worst-case transient patience drops from about 217s to 90s. Production LOC: +463 / -685 across 44 files, net -222. Follows openclaw#134103 and openclaw#134111 in the LLM error-UX series. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
The "are model fallbacks available" fact was derived twice with different rules:
resolveEffectiveModelFallbacks(src/agents/agent-scope.ts) returned an empty ladder when the session carried a user model override.hasConfiguredModelFallbacks— feedingfallbackConfiguredinsrc/agents/embedded-agent-runner/run-orchestrator.ts— did not apply the override rule.So a gateway with configured fallbacks and a user-pinned model ran the whole failover policy with
fallbackConfigured=truewhile the ladder the outer runner consumed was empty. This is not a diagnostics-only bug:fallbackConfiguredis a behavioral input toresolveRunFailoverDecision(run/failover-policy.tsretry-limit escalation) and to the rate-limit rotation cap (run/failover-retry-controller.ts:160), so the split-brain changed what the user saw:The AI service is temporarily rate-limited. Please try again in a moment., no suspend) after two attempts, the outer runner recordedchain_exhaustedwith no next candidate and rethrew. The run skipped its remaining same-model retry budget and never entered the real rate-limit surface.failover-policy.tsselectedfallback_model→run/retry-limit.tsthrew aFailoverErrorinstead of returning the normal retry-limit payload.Why This Change Was Made
The pinned-override semantic is intentional (a pinned model must not silently switch). The bug is the split-brain derivation and the silence. Fix:
resolveModelFallbackAvailability, returns a closed union:{ kind: "active", models } | { kind: "none_configured" } | { kind: "disabled_by_model_override" } | { kind: "disabled_by_model_selection_lock" }— computed once where the run scope is prepared and carried onRunEmbeddedAgentParamsas a prepared fact.resolveEffectiveModelFallbacksand the orchestrator'sfallbackConfiguredare now projections of that one result; the duplicatehasConfiguredModelFallbacksandhasEmbeddedRunConfiguredModelFallbacks(run/fallbacks.ts) derivations are deleted, so disagreement is unrepresentable.disabled_by_model_override, the orchestrator logs it once per run ([model-fallback] configured fallbacks disabled by user model override), so an operator reading logs during an incident learns why no fallback fired.resolveFallbackTransitionrequires a real selected→active model difference before any chat notice or lifecycle event fires (src/auto-reply/fallback-state.ts,src/auto-reply/reply/agent-runner-result-payloads.ts); no change needed, group/channel notice suppression untouched.User Impact
Pinned-model sessions with configured default fallbacks now get honest failure behavior. On a rate-limited provider the run spends its full same-model retry and profile-rotation budget and then surfaces the real rate-limit copy (
⚠️ API rate limit reached. Please try again later.) with proper suspend/cooldown semantics — instead of aborting early with a bogus "escalating to model fallback" error over a ladder that was empty all along. At the retry limit, the run returns the normal retry-limit payload instead of a thrown escalation error. The ladder semantics themselves (pinned override disables fallbacks, auto provenance keeps them) are preserved exactly, and operators gain one explanatory log line when configured fallbacks are suppressed by a pinned model.Evidence
Boundary regression (embedded runner surface, fail-pre-fix proven):
src/agents/model-fallback.run-embedded.e2e.test.ts— real orchestrator/run-loop/failover controller, onlyrunEmbeddedAttemptmocked:disabled_by_model_overrideprepared fact, multi-profile rate-limit faults. Asserts the run rejects with the real rate-limit surface (API rate limit reached,reason: "rate_limit",suspend: true), spends >2 primary attempts, attempts only the pinned provider, and records achain_exhaustedobservation with nofallbackStepToModel. Pre-fix (production files checked out from the merge basebbd3410c067) this test fails for the intended reason: the run rejects with the rotation-cap escalation errorThe AI service is temporarily rate-limited. Please try again in a moment.(suspend: undefined) thrown fromfailover-retry-controller.tsunder the bogusfallbackConfigured=true.{ kind: "active" }fact → fallback engages and the groq candidate answers.node scripts/run-vitest.mjs src/agents/model-fallback.run-embedded.e2e.test.ts.Unit regression (fail-pre-fix proven): with source changes stashed,
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/fallbacks.test.tsfailed withexpected true to be false— the old configured signal reportedtruewhile the resolved ladder was empty under a user override. Post-fix the disagreement is structurally impossible.Post-fix, independently rerun:
src/agents/agent-scope.test.ts(54),src/auto-reply/reply/agent-runner-utils.test.ts,src/agents/model-fallback.test.ts+ candidates/terminal-boundary/observation siblings,src/auto-reply/fallback-state.test.ts— all green.node scripts/check-changed.mjs --dry-runclassified core/coreTests lanes;oxfmtandgit diff --checkclean.Shipped-entry product path (unbroken chain):
src/agents/model-fallback.reply-entry.e2e.test.tsdrives a Telegram DM turn through the real reply entry with no bridges:getReplyFromConfig→ followup queue →runReplyAgent→ run-params (resolveModelFallbackOptions) →runEmbeddedAgent→ real orchestrator/run-loop/failover controller, with only the attempt layer (runEmbeddedAttempt), model resolution, and environment seams mocked — the same seams the boundary suite uses. Setup: a session entry persisted through the shipped session store pinsopenai/mock-1withmodelOverrideSource: "user"while config declaresfallbacks: ["anthropic/mock-2"]; the mocked attempt returns persistent rate-limit failures. Asserts the user-visible reply text containsAPI rate limit reached, >2 openai attempts, and zero anthropic attempts. Pre-fix this chain returned the rotation-cap escalation copy (The AI service is temporarily rate-limited. Please try again in a moment.) because run preparation rebuiltfallbackConfiguredfrom config defaults instead of carrying the disabled availability fact.Inherited-fallbacks provenance repair (ClawSweeper P1, confirmed real): the refactor's first cut collapsed inherited default fallbacks into an explicit run override in reply/command preparation. The candidate resolver (
src/agents/model-fallback-candidates.ts:343,370) treatsfallbacksOverride === undefinedas "derive configured fallbacks and append the configured primary as the final candidate" — so a selected route C with default primary A + fallbacks [B] regressed from C→B→A to C→B. Repair:ModelFallbackAvailabilitynow records provenance (source: "explicit" | "inherited"onactive/none_configured), and one canonical projectionmodelFallbackOverrideFromAvailabilitymaps inherited→undefined(resolver owns the ladder), explicit→models/[], disabled→[].resolveEffectiveModelFallbacksis that projection composed over the availability resolver, restoring its pre-refactorstring[] | undefinedcontract — so command prep (src/agents/command/run-embedded-attempt.ts) and codex diagnostics were repaired with zero call-site changes, and cron's tail collapsed back to a singleresolveEffectiveModelFallbackscall. Regression coverage: projection truth-table rows inagent-scope.test.ts, and a chain-retention test inmodel-fallback.test.tsproving inherited fallbacks produceundefinedand the candidate chain keeps the configured-primary tail (C→B→A) — sibling to the existing "does not append configured primary when fallbacksOverride is set" guard.Channel-visible proof: the changed path is fully covered from the shipped reply entry through the embedded-runner boundary with real orchestrator/controller code and fault injection; the affected copy strings are asserted exactly there.
Post-repair reruns, all green:
agent-scope.test.ts(60),model-fallback.test.ts(154+),agent-runner-utils.test.ts(87),prepared-model-runtime.reply-fallback.test.ts,run-fallback-policy.test.ts+run.payload-fallbacks.test.ts,config.plugin-validation.test.ts,agent-command.live-model-switch.test.ts(129), both model-fallback e2e suites (23),agent-runner.runreplyagent.e2e.test.ts(169), fullsrc/cron/isolated-agent(43 files).Production LOC net +54 vs merge base (closed provenance union + carried fact + canonical projection + one log line, minus deleted duplicate derivations); tests net +392 (boundary/e2e regression scenarios and the shipped-entry chain suite).