Repository navigation
fix(agents): own transient LLM retries in one failover retry controller - #134281
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
e51f49d to
ed0593f
Compare
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 1:49 AM ET / 05:49 UTC. ClawSweeper reviewWhat this changesThe branch centralizes transient provider retries in the embedded agent runner, disables overlapping SDK and native transport retries, and uses the existing session retry setting as a turn-wide retry budget. Merge readinessKeep open for maintainer review: the branch is not on current main and coherently removes stacked transient retry owners, but it intentionally changes the scope of an existing saved retry setting and needs explicit compatibility acceptance plus direct pinned-SDK contract verification before merge. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s embedded agent runner converts a channel turn into provider attempts, failover decisions, and a final channel reply. This change makes one controller own retry timing before a failed attempt can rotate credentials, switch models, or surface an error. flowchart LR
A[Channel turn] --> B[Embedded agent runner]
B --> C[Provider attempt]
C --> D{Transient failure}
D -->|retryable| E[Shared retry controller]
E --> C
D -->|not retryable or exhausted| F[Profile or model failover]
F --> G[Final channel reply]
Decision needed
Why: This is a deliberate compatibility and operator-behavior change to a retained persisted setting; source review cannot decide whether that upgrade tradeoff is acceptable. Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single controller, explicitly accept the turn-wide saved-setting semantics, and verify the pinned SDK clients honor retry disabling before merge. Do we have a high-confidence way to reproduce the issue? Yes—source and regression tests give a high-confidence path: trigger a replay-safe transient provider failure during an embedded run and observe the controller’s retry/failover decisions; this review did not execute it locally. Is this the best way to solve the issue? Yes for the duplicate-retry failure class: one controller makes accounting visible and bounded, contingent on confirming the retained SDK and saved-setting compatibility contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b9c3958eef13. LabelsLabel changes:
Label 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 (6 earlier review cycles)
|
59422dd to
cca8551
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
cca8551 to
4cc0298
Compare
|
@clawsweeper re-review — all three findings addressed on head 94b957b (excess test inputs removed, retired retry.provider.maxRetries now stripped by the settings-storage owner under its lock, failover retry count reads live via getTransientRetryCount). |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
…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]>
…enclaw#135374) Follow up on openclaw#134980 by computing attempt visibility and silent-reply eligibility once, removing duplicated empty-turn predicates and a one-call terminal-error wrapper. Align the failover docs with the consolidated transient retry owner from openclaw#134281. Production delta: -71 lines; no behavior or configuration change.
Restore the shipped optional provider-wrapper input as deprecated without re-enabling nested text retries. Keep numeric callers source-compatible and document the future SDK-major removal gate. Correct the nearby header-wrapper example to forward model, context, and request options. Production net0;217 focused tests, strict stable/baseline/candidate public SDK consumers, full changed gate, and independent managed review pass. Related: #134281.
Restore the shipped optional provider-wrapper input as deprecated without re-enabling nested text retries. Keep numeric callers source-compatible and document the future SDK-major removal gate. Correct the nearby header-wrapper example to forward model, context, and request options. Production net0;217 focused tests, strict stable/baseline/candidate public SDK consumers, full changed gate, and independent managed review pass. Related: openclaw#134281.
Closes #160534 ## What Problem This Solves Fixes repeated provider requests when an HTTP 400 response has an empty body, wasting rate limits and potentially hiding the original error behind subsequent throttling. ## User Impact A deterministic bodyless client error now surfaces after one model request rather than four. Transient recovery, empty successful response repair, and normal replies retain their existing behavior. No configuration changes are required. ## Why This Change Was Made The silent-error recovery path previously treated an unclassified bodyless HTTP 400 like a missing model response. It now checks the existing HTTP-status and transient-retry evidence owners before replaying a client error, without introducing another retryable-status list or reclassifying the failure as a format error. The transport's existing retryable HTTP-status predicate is shared with the silent-error guard, preserving bodyless 409 conflict recovery without changing the transport's SDK wait cap or the transient retry budget. The reasoning-only, replay-safe recovery introduced in #92191 remains intact, as does the separate transient recovery budget from #134281 and #139397. Thanks to @bogdandragosvasile for the exact local reproduction. No overlap with Pash/Sarah changes. ## Evidence Ran `pnpm openclaw --profile <isolated-profile> agent exec` against the issue's local empty-body fault server, using task-owned config, state, home, workspace, and ports. Baseline: `25d771cb8203f5afeea7b7c9dc8060210db8e43d`. | Provider response | Baseline model requests | Fixed model requests | Observed result | | --- | ---: | ---: | --- | | Empty HTTP 400 | 4 | 1 | Original `400 status code (no body)` surfaces | | Empty HTTP 409 | 4 | 4 | Existing silent-error retries, then original conflict error | | Empty HTTP 429 | 10 | 10 | Existing transient retries, then rate-limit error | | Empty HTTP 200 | 2 | 2 | Existing visible-answer retry, then incomplete-response error | | Normal streamed HTTP 200 | 1 | 1 | `pong` | Counts are `POST /v1/chat/completions` requests; unrelated `GET /` probes are excluded. Baseline controls were run with the production change reverted in the same worktree. The new bodyless 400/422 owner regressions both failed before the fix (`retry` instead of `proceed`) and pass afterward. The focused run of `run.owner-policy.test.ts`, `failover/classify.test.ts`, and `provider-transport-fetch.test.ts` with `pnpm test ... --maxWorkers=1` passed all 133 tests in 40.6 seconds total wall time including worker compilation. This includes the new 409 preservation case, existing reasoning-only and replay-unsafe-tool cases, and existing SDK retry-cap tests. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes openclaw#160534 ## What Problem This Solves Fixes repeated provider requests when an HTTP 400 response has an empty body, wasting rate limits and potentially hiding the original error behind subsequent throttling. ## User Impact A deterministic bodyless client error now surfaces after one model request rather than four. Transient recovery, empty successful response repair, and normal replies retain their existing behavior. No configuration changes are required. ## Why This Change Was Made The silent-error recovery path previously treated an unclassified bodyless HTTP 400 like a missing model response. It now checks the existing HTTP-status and transient-retry evidence owners before replaying a client error, without introducing another retryable-status list or reclassifying the failure as a format error. The transport's existing retryable HTTP-status predicate is shared with the silent-error guard, preserving bodyless 409 conflict recovery without changing the transport's SDK wait cap or the transient retry budget. The reasoning-only, replay-safe recovery introduced in openclaw#92191 remains intact, as does the separate transient recovery budget from openclaw#134281 and openclaw#139397. Thanks to @bogdandragosvasile for the exact local reproduction. No overlap with Pash/Sarah changes. ## Evidence Ran `pnpm openclaw --profile <isolated-profile> agent exec` against the issue's local empty-body fault server, using task-owned config, state, home, workspace, and ports. Baseline: `f6f301f702dfed02b63423237db57f96e8f4145a`. | Provider response | Baseline model requests | Fixed model requests | Observed result | | --- | ---: | ---: | --- | | Empty HTTP 400 | 4 | 1 | Original `400 status code (no body)` surfaces | | Empty HTTP 409 | 4 | 4 | Existing silent-error retries, then original conflict error | | Empty HTTP 429 | 10 | 10 | Existing transient retries, then rate-limit error | | Empty HTTP 200 | 2 | 2 | Existing visible-answer retry, then incomplete-response error | | Normal streamed HTTP 200 | 1 | 1 | `pong` | Counts are `POST /v1/chat/completions` requests; unrelated `GET /` probes are excluded. Baseline controls were run with the production change reverted in the same worktree. The new bodyless 400/422 owner regressions both failed before the fix (`retry` instead of `proceed`) and pass afterward. The focused run of `run.owner-policy.test.ts`, `failover/classify.test.ts`, and `provider-transport-fetch.test.ts` with `pnpm test ... --maxWorkers=1` passed all 133 tests in 40.6 seconds total wall time including worker compilation. This includes the new 409 preservation case, existing reasoning-only and replay-unsafe-tool cases, and existing SDK retry-cap tests. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
When a provider returns a transient failure (429, 5xx, or timeout), up to three uncoordinated retry layers replayed the same request:
openai-chatgpt-responseshad its own per-request retry loop on top of the SDK.Stacked, these multiplied: one transient 429 could hold a turn silently for minutes with no coherent budget, and the failover controller (which owns provider/model fallback) never saw all the attempts it needed to budget. This follows #134103 and #134111 in the LLM error-UX series.
Why This Change Was Made
One retry owner, one budget. The embedded runner's failover retry controller (
src/agents/embedded-agent-runner/run/failover-retry-controller.ts) owns transient-retry policy:retry.provider.maxRetriesis the transient-retry attempt budget. The controller installs the saved value for each dispatch. The default budget remains 3.maybeRetryTransientreturns false, the caller falls through torotate_profile,fallback_model, orsurface_error(src/agents/embedded-agent-runner/run/assistant-failover.ts:137-153). Exhaustion moves to another profile or model, which is better recovery than more same-model retries against a slow provider.resolveTransientRetryDelayMsuses a 1s base, 0.5–1.5x jitter, and a 30s cap (src/agents/embedded-agent-runner/run/helpers.ts:44-79). The window truncates only when requests themselves are slow, which is when failover is the right move.7d7d6a5e8a2logs the retry count and configured budget at the controller producer (src/agents/embedded-agent-runner/run/failover-retry-controller.ts:244-250), so a configured budget that cannot run fully is diagnosable. The regression is covered bysrc/agents/embedded-agent-runner/run/failover-retry-controller.test.ts,records the truncation when the window ends a budget that still has attempts.This is not a breaking change. A saved
retry.provider.maxRetrieskeeps a coherent meaning: it was the per-SDK-request retry count, and it is now the transient-retry attempt budget owned by one controller. Before this PR, the value reached only the provider SDK and multiplied against a separate hardcoded controller retry of 3; it never reached OpenClaw's own retry owner. Saved values remain valid, with no migration, doctor repair, or config-shape change.Other retry paths are consolidated around that owner:
maxRetries: 0.buildOpenAISdkClientOptionsandbuildOpenAISdkRequestOptionsprevent SDK retries from hiding attempts from the owner.Retry-After/retry-after-msthrough the terminal error text, so the controller can honor provider pacing.StreamOptions.maxRetriesknob is removed. The session runtime'sretry.maxRetriesloop remains separate because it has a different owner.src/auto-reply/reply/agent-runner-error-handler.ts), along withOverloadRetryStateand the 30s "still retrying" notice. Embedded runs use the inner controller; CLI harness backends own their internal retries, so escaping errors surface immediately with actionable copy.providerRequestError.userMessage) beats the generic classified summary.AgentFallbackCycleState.turnStartedAtMs, so error events and sessionruntimeMsreflect the real turn duration.Accepted tradeoffs (named, not accidental)
User Impact
retry.provider.maxRetriescontrols the transient-retry attempt budget in one controller. A slow provider can end that budget at the flat window, and the controller records that truncation.Evidence
OPENCLAW_E2E_OKonly; the mock provider returned an injected transient HTTP 500 on the first/v1/responsesrequest and a normal completion on the second. The gateway log showedtransient same-model retry 1/3 for openai/gpt-5.5. Telegram received exactly one assistant reply, with no error and no duplicate.mock-openai-requests.ndjsoncontained exactly two provider requests. The same prompt without fault injection used exactly one provider request.maybeRetryTransient({ reason: "timeout" })insrc/agents/embedded-agent-runner/run/assistant-failover.tsinstead of a second bespoke retry counter. The run-wide idle-timeout breaker still caps consecutive silent attempts at 5.server_erroror prompt timeout exhausts the 3-retry budget, for 4 attempts total, and then throwsFailoverErrorto the configured fallback.packages/aifull suite: 115 files / 2103 tests green, including transport tests that prove one HTTP request per failure mode and preserveRetry-Afterevidence.src/auto-reply/replyfull suite: 257 files / 5323 passed, 1 skipped, green, including the CLI capacity-error path and removal of the outer replay tests.src/agents/embedded-agent-runner/runfull directory: green, including retry-owner budget, backoff, provider pacing, and wall-clock coverage.packages/ai/src/providers/openai-chatgpt-responses.retry.test.tsproves a 429 withretry-after: 7preservesRetry-After: 7 secondsin one HTTP request, which the retry owner parses as 7000ms.server_errorthrough the controller;src/agents/embedded-agent-runner/run/assistant-failure.test.tsis 21/21 green.turnStartedAtMsis carried on the fallback cycle state.src/agents/embedded-agent-runner/run/failover-retry-controller.test.tscovers the new truncation record:records the truncation when the window ends a budget that still has attemptsverifies the controller logsafter 1/8 retrieswhen the flat window ends before the configured budget.git diff --checkis clean; formatting is applied.*.test.tsand*owner-test-support.tsas test paths: +463 / -685 across 44 production files, net -222. Tests: +459 / -617 across 47 test files, net -158. Overall: +922 / -1302 across 91 changed files, net -380.