Skip to content

fix(engine): retry transient TLS and socket errors, and name them when they persist (Refs #1969) - #2204

Merged
bc037 merged 1 commit into
mainfrom
fix/1969-transport-retry
Dec 3, 2026
Merged

bc037 merged 1 commit into
mainfrom
fix/1969-transport-retry

Conversation

@bc037

@bc037 bc037 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Related Issue

Refs #1969 (items 1 and 2 only; items 3 to 5 are not in this PR, so it does not close the issue)

Description

Two implementer subagents died on a one-time ERR_TLS_CERT_ALTNAME_INVALID from a rotating AWS IP. The engine had no retry class for TLS or socket errors, so the first occurrence ended the session.

Item 1: transient transport errors retry.

  • session/transport-error.ts (new) finds a transport code anywhere in the error's cause chain (undici wraps the real error inside TypeError("fetch failed")). Codes: ERR_TLS_*, ERR_SSL_*, UNABLE_TO_VERIFY_LEAF_SIGNATURE, CERT_HAS_EXPIRED, EPROTO, ECONNABORTED, EPIPE, UND_ERR_SOCKET, UND_ERR_CONNECT_TIMEOUT.
  • MessageV2.fromError turns such an error into a retryable APIError.
  • retry.ts also retries these codes when they appear only in a message text.
  • HTTP 502, 503 and 504 were already retried; tests now cover them.

Item 2: persistent errors stay loud. Transport errors use the normal attempt cap (5 retries, about 62 s of backoff). They do not get the 10-minute rate-limit budget. The error message names the failure: code, host and certificate subject, for example Transport error ERR_TLS_CERT_ALTNAME_INVALID connecting to bedrock-runtime.us-east-1.amazonaws.com (certificate subject *.s3.amazonaws.com): .... The retry loop lives in the upstream processor.ts, which the overlay does not change, so the named failure comes from the error message itself.

Changes: transport-error.ts (new), message-v2.ts, retry.ts, test/session/retry.test.ts, and the overlay manifest hashes (refresh_manifest.mjs).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Config / infrastructure (CI, tooling, build, docs)
  • Breaking change (fix or feature that changes existing behavior)

Verification

  • pnpm -r run build exits 0
  • pnpm -r run test exits 0 (or pnpm -r run typecheck if tests aren't relevant)
  • Manual testing described below

Engine tests, run with Bun 1.4.2 on a materialized tree in WSL: test/session/retry.test.ts has 93 tests. 21 fail on the old source and all 93 pass with the fix. They include one test per error code, a non-transient 400 that is not retried, a fake provider that fails TLS twice and then succeeds (two retries recorded, under the test clock), and a fake provider that always fails (stops after 5 retries with the named error). drift_gate.mjs passes.

Manual Testing Notes

  • message-v2.test.ts and processor-effect.test.ts also run. One processor test (retry recognized structured json errors) timed out in a shared run. It passes alone on both the old and the new source, so it looks like the known shared-process load flake (Session-lineage spec conflict: legacy-parent aggregation vs 'Bug A fix' (auto-create) — tied to server-survives-rebuild #1239).
  • Engine typecheck reports 5 errors in other test files (httpapi-event-replay, httpapi-mcp-oauth, llm-native-recorded, snapshot-tool-race). None is in the files I changed. I did not compare them against main.
  • Not done: "open a fresh connection on retry". I did not verify that this needs a change. undici normally drops a socket that errored. I need to check this on a real provider path. It may need a provider-level change.
  • Not tested end to end: a real TLS failure against a live endpoint. The tests inject the error shape that undici produces.
  • The issue carries a post-v2 label (deferred until the opencode v2 port) and the 0.4.1-beta label. I started now at the request of the assignee. Maintainers should confirm.

🤖 Generated with Claude Code

…n they persist

A one-time ERR_TLS_CERT_ALTNAME_INVALID (a rotating AWS IP) killed two
subagents: RETRYABLE_MESSAGE_PATTERNS had no TLS or socket class, so the
session failed on the first occurrence.

- transport-error.ts (new): finds a transport code (ERR_TLS_*, ERR_SSL_*,
  UNABLE_TO_VERIFY_LEAF_SIGNATURE, CERT_HAS_EXPIRED, EPROTO, ECONNABORTED,
  EPIPE, UND_ERR_SOCKET, UND_ERR_CONNECT_TIMEOUT) anywhere in the error's
  cause chain, with the host and certificate subject.
- message-v2.ts: fromError turns such an error into a retryable APIError whose
  message names the code, host and certificate subject.
- retry.ts: the same codes retry when they appear only in a message text.

Transport errors keep the normal attempt cap (5 retries, about 62 s of
backoff), not the 10-minute rate-limit budget. A persistent error therefore
ends in the named failure, not a bare "fetch failed".

Tests first: 21 of the 93 retry tests failed on the old code and all pass now.
Items 3 to 5 of the issue are not in this commit.

Refs #1969

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb31e345-e754-4327-8184-e7e01c3f1a6a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@bc037
bc037 marked this pull request as ready for review December 3, 2026 17:05
@bc037
bc037 merged commit 3c0fa52 into main Dec 3, 2026
12 checks passed
@bc037
bc037 deleted the fix/1969-transport-retry branch December 3, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants