Repository navigation
fix(engine): retry transient TLS and socket errors, and name them when they persist (Refs #1969) - #2204
Merged
Conversation
…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>
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_INVALIDfrom 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'scausechain (undici wraps the real error insideTypeError("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.fromErrorturns such an error into a retryableAPIError.retry.tsalso retries these codes when they appear only in a message text.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 upstreamprocessor.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
Verification
pnpm -r run buildexits 0pnpm -r run testexits 0 (orpnpm -r run typecheckif tests aren't relevant)Engine tests, run with Bun 1.4.2 on a materialized tree in WSL:
test/session/retry.test.tshas 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.mjspasses.Manual Testing Notes
message-v2.test.tsandprocessor-effect.test.tsalso 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).httpapi-event-replay,httpapi-mcp-oauth,llm-native-recorded,snapshot-tool-race). None is in the files I changed. I did not compare them againstmain.post-v2label (deferred until the opencode v2 port) and the0.4.1-betalabel. I started now at the request of the assignee. Maintainers should confirm.🤖 Generated with Claude Code