Skip to content

fix(failover): classify transient Undici error codes - #123042

Merged
sallyom merged 2 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/failover-undici-transient
Aug 16, 2026
Merged

sallyom merged 2 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/failover-undici-transient

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where agent runs could stop without retry or failover when a transient transport failure was preserved only as a structured error code and its message did not identify the network failure.

Why This Change Was Made

Assistant retry now forwards structured errorCode / errorType fields into the failover signal. Core failover classification reuses the existing shared transient-network matcher rather than maintaining a second Undici-only policy, while the three failover-specific codes remain local to failover.

User Impact

Transient connection, DNS, socket, and response-timeout failures can now follow the normal retry and failover policy instead of ending the agent run. This adds no API, config, schema, migration, or default change.

Evidence

Exact-head real transport fault

Verified at b5b4a9bf11fad122732171f695fd13a0caf120c3 with a disposable, secretless loopback harness:

  1. A real Undici request() POST was sent to a local TCP server that accepted the connection but withheld response headers (headersTimeout: 50).
  2. Undici emitted an actual HeadersTimeoutError carrying UND_ERR_HEADERS_TIMEOUT.
  3. That caught error object was passed unchanged to production failTransportStream; the harness did not construct or assign an assistant errorCode.
  4. Production transport projection preserved the code, embedded-agent failover classified it as timeout, and outer assistant retry accepted it.
$ node --import tsx scripts/pr-123042-transport-proof.mts
{
  "head": "b5b4a9bf11fad122732171f695fd13a0caf120c3",
  "transport": "Undici request -> loopback headers timeout -> OpenClaw transport projection",
  "sourceErrorName": "HeadersTimeoutError",
  "sourceErrorCode": "UND_ERR_HEADERS_TIMEOUT",
  "stopReason": "error",
  "projectedErrorCode": "UND_ERR_HEADERS_TIMEOUT",
  "failoverReason": "timeout",
  "retryable": true
}

The disposable proof script and server were removed after the run; no branch files or credentials were used.

Regression and review evidence

  • Pre-fix focused regression: structured ENOTFOUND returned no failover classification on maintainer parent 0934155784f2759210024fe8dfe7a830ae990f7f.
  • Exact-head focused tests: node scripts/run-vitest.mjs src/agents/embedded-agent-helpers/assistant-message-failures.test.ts src/llm/utils/retry.test.ts — pass.
  • Exact-head changed-file gate — pass.
  • Exact-head local ClawSweeper — no findings.
  • Exact-head autoreview — no findings.
  • Canonical shared-policy precedent: fix(provider-runtime): retry transient socket failures #122535 added these transient transport codes to src/infra/retryable-network-errors.ts; this PR now consumes that owner directly.

AI-assisted: built with Codex

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Aug 13, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 1:27 PM ET / 17:27 UTC.

ClawSweeper review

What this changes

The PR routes structured assistant error codes and types into failover and retry decisions, reusing OpenClaw’s shared transient-network classifier.

Merge readiness

✅ Ready for maintainer review

No blocking findings. This remains necessary: current main still ignores structured transient codes in outer retry and its failover code list, while the branch carries those fields through the existing shared matcher.

Priority: P1
Reviewed head: b5b4a9bf11fad122732171f695fd13a0caf120c3

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with direct transport-fault evidence and regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body records exact-head output from a real Undici loopback headers-timeout passed through the production transport projection to failover and outer-retry acceptance.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records exact-head output from a real Undici loopback headers-timeout passed through the production transport projection to failover and outer-retry acceptance.
Evidence reviewed 6 items Current-main defect: Current main already preserves assistant errorCode for embedded-agent failover, but its structured-code classifier only checks a local set and its outer retry signal omits errorCode/errorType; a generic message plus UND_ERR_HEADERS_TIMEOUT therefore remains unclassified and non-retryable.
Branch repair path: The branch forwards structured fields to the retry signal and makes both failover classification and retry evidence consume the canonical transient-network matcher, retaining only failover-specific codes locally.
Producer and caller boundary: The production transport projects provider errors onto the assistant message before emitting it; the existing transport test proves a wrapped transport error retains errorCode and reaches failover classification.
Findings None None.
Security None None.

How this fits together

Provider transports normalize thrown network failures into assistant messages. Agent failover and outer retry consume the normalized status, code, and message to select a fallback or retry.

flowchart LR
A[Provider transport error] --> B[Assistant error projection]
B --> C[Failover signal]
C --> D[Shared transient network matcher]
D --> E[Failover classification]
D --> F[Outer retry decision]
E --> G[Model fallback]
F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -1, Tests +28. Total +27 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 12 13 -1
Tests 2 28 0 +28
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 40 13 +27

Review metrics

Metric Value Why it matters
Production versus test LOC production +12/-13 (net -1); tests +28/-0 The repair removes the duplicated transient-code list while adding focused coverage for classification and retry.

Technical review

Best possible solution:

Keep transient-code policy centralized in the shared matcher and merge this focused consumer repair after the normal exact-head gate.

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

Yes — current main’s code path is source-reproducible with a generic assistant error message plus a structured transient code; the PR body additionally records exact-head real-transport output.

Is this the best way to solve the issue?

Yes — forwarding the normalized fields and reusing the existing shared matcher is the narrow canonical fix, rather than adding a second Undici-specific policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6509a09ca7a5.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records exact-head output from a real Undici loopback headers-timeout passed through the production transport projection to failover and outer-retry acceptance.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records exact-head output from a real Undici loopback headers-timeout passed through the production transport projection to failover and outer-retry acceptance.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A transient transport failure can currently end an agent run instead of entering its established retry or failover path.
  • 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. Sufficient (live_output): The PR body records exact-head output from a real Undici loopback headers-timeout passed through the production transport projection to failover and outer-retry acceptance.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records exact-head output from a real Undici loopback headers-timeout passed through the production transport projection to failover and outer-retry acceptance.

Evidence

What I checked:

  • Current-main defect: Current main already preserves assistant errorCode for embedded-agent failover, but its structured-code classifier only checks a local set and its outer retry signal omits errorCode/errorType; a generic message plus UND_ERR_HEADERS_TIMEOUT therefore remains unclassified and non-retryable. (src/agents/failover/classification-rules.ts:345, 6509a09ca7a5)
  • Branch repair path: The branch forwards structured fields to the retry signal and makes both failover classification and retry evidence consume the canonical transient-network matcher, retaining only failover-specific codes locally. (src/agents/failover/classification-rules.ts:337, b5b4a9bf11fa)
  • Producer and caller boundary: The production transport projects provider errors onto the assistant message before emitting it; the existing transport test proves a wrapped transport error retains errorCode and reaches failover classification. (packages/ai/src/transports/transport-stream-shared.ts:205, 6509a09ca7a5)
  • Undici contract: The repository declares Undici 8.9.0; direct local Undici source inspection confirms HeadersTimeoutError carries UND_ERR_HEADERS_TIMEOUT, matching the code exercised in the PR’s exact-head transport proof. (package.json:2053, 6509a09ca7a5)
  • Current-main and release status: The PR head diverges from current main at its declared base and has a clean computed merge; neither current main nor the latest release tag contains the branch head. (src/llm/utils/retry.ts:39, 6509a09ca7a5)
  • History and ownership: Blame attributes the shared matcher owner to the current-main refactor by Peter Steinberger, while the branch’s retry-field forwarding dates to the contributor commit and the shared retry precedent is merged PR 122535. (src/llm/utils/retry.ts:39, 8bf55bfe1929)

Likely related people:

  • steipete: Current-main history and blame attribute the shared transient-network matcher and failover split to this area. (role: current shared-policy owner; confidence: high; commits: 8bf55bfe1929; files: src/infra/retryable-network-errors.ts, src/agents/failover/classification-rules.ts)
  • vincentkoc: Merged PR 122535 established the recent shared transient socket retry precedent that this branch now consumes. (role: adjacent retry-policy contributor; confidence: high; commits: dfbdbf2a67de; files: src/infra/retryable-network-errors.ts)
  • sallyom: Assigned reviewer who authored the exact-head consolidation commit and supplied the refreshed transport proof. (role: recent branch maintainer and reviewer; confidence: high; commits: b5b4a9bf11fa; files: src/agents/failover/classification-rules.ts, src/agents/failover/retry-evidence.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-13T07:16:10.080Z sha 12268093363d03aebd9bf0f2cc49311f942546f4 :: needs maintainer review before merge. :: none
  • reviewed August 15, 2026, 11:44 PM ET / August 16, 2026, 03:44 UTC sha unknown :: needs maintainer review before merge. :: none
  • reviewed 2026-08-16T08:10:32.448Z sha f6b6332b62f669efd6a5453922fb74f5128cf8bf :: needs maintainer review before merge. :: none
  • reviewed 2026-08-16T15:43:39.352Z sha 0934155 :: needs real behavior proof before merge. :: [P2] Reuse the shared transient network matcher
  • reviewed 2026-08-16T17:12:49.742Z sha b5b4a9b :: needs real behavior proof before merge. :: none

@sunlit-deng
sunlit-deng force-pushed the sunlit/fix/failover-undici-transient branch from 1226809 to f6b6332 Compare August 16, 2026 08:04
@sallyom sallyom self-assigned this Aug 16, 2026
@sallyom

sallyom commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Maintainer note: local review is clean. I am updating this PR from f6b6332b62f669efd6a5453922fb74f5128cf8bf onto current origin/main (886e5c0) to refresh exact-head CI and clear the unrelated red gateway timing check before merge. No action is needed from the contributor for now.

@sallyom
sallyom force-pushed the sunlit/fix/failover-undici-transient branch from f6b6332 to 0934155 Compare August 16, 2026 15:37
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@sallyom

sallyom commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Latest ClawSweeper review identified a P2 in the transient-network failover classification boundary. I’ve now pushed a small signed-off maintainer fix at b5b4a9bf11f. It reuses the shared transient-network matcher for structured failover codes, retains only failover-specific codes locally, and adds a non-Undici ENOTFOUND regression.

Exact-head offline ClawSweeper and autoreview are clean; focused tests and the full changed-file gate pass. CI has been retriggered.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 16, 2026
@sallyom

sallyom commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Exact-head real transport proof is now in the PR body: a real Undici loopback headers timeout emitted UND_ERR_HEADERS_TIMEOUT, production transport projection preserved it, embedded failover classified it as timeout, and outer retry returned true. The proof did not construct or assign the assistant error code.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 16, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Aug 16, 2026
@sallyom

sallyom commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Merge-ready at HEAD b5b4a9bf11fad122732171f695fd13a0caf120c3.

  • Best-fix verdict: the patch carries normalized structured error fields into the existing retry/failover boundary and reuses the canonical shared transient-network matcher; no duplicated Undici policy remains.
  • Compatibility: no API, config, schema, migration, default, provider-route, or plugin contract changes.
  • Proof: exact-head real Undici UND_ERR_HEADERS_TIMEOUT transport projection reaches timeout failover classification and retryable=true; focused regressions and the full changed-file gate pass.
  • Review: fresh autoreview is clean; ClawSweeper is 5/6 with proof sufficient, no findings, and no before-merge items.
  • CI: required exact-head CI and the native hosted CI/Testbox prepare gate pass.
  • Scope: production +12/-13 (net -1); tests +28/-0.

Proceeding with merge.

@sallyom
sallyom merged commit 0e7deee into openclaw:main Aug 16, 2026
205 checks passed
@sallyom

sallyom commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
* fix(failover): classify transient Undici error codes

* fix(failover): share transient network code policy

Signed-off-by: sallyom <[email protected]>

---------

Signed-off-by: sallyom <[email protected]>
Co-authored-by: sallyom <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

2 participants