Skip to content

Distinguish transient from unsent errors in retry logic - #368

Merged
alexkroman merged 2 commits into
mainfrom
claude/quirky-brown-r5qtaa
Nov 25, 2026
Merged

alexkroman merged 2 commits into
mainfrom
claude/quirky-brown-r5qtaa

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

What & why

The transcription client's retry logic now distinguishes between two categories of failures:

  1. Transient errors (isTransient): Network blips, timeouts, and server errors (5xx, 429) that may have reached the API. Safe to retry for polling and uploads, but not for non-idempotent POSTs like transcript submission, which could create duplicates.

  2. Unsent errors (isUnsent): Connection failures that definitely never reached the server (DNS, cannot connect, etc.) plus 429s. Safe to retry for any operation, including transcript submission, since nothing was created server-side.

This fixes a bug where transcript submissions timing out would not be retried (correct), but submissions that couldn't connect would also not be retried (incorrect—they're safe to retry). It also prevents cancelled requests from being retried, which would keep a Library cancel waiting through every retry attempt.

The changes:

  • Extract retry logic into a reusable retrying(when:) helper
  • Apply isUnsent to transcript submission (non-idempotent POST)
  • Apply isTransient to upload and polling (idempotent or read-only)
  • Refine error classification with explicit URL error code sets
  • Add ScriptedTransport test helper for per-request response scripting

How it was tested

  • Added transientClassification() test covering all error categories

  • Added cancelledPollNotRetried() test ensuring cancellations surface immediately

  • Added uploadRetry() test verifying transient upload failures are retried

  • Added submitRetry() test verifying submit retry behavior differs by error type

  • All new tests pass; existing tests remain green

  • scripts/check.sh passes (or CI will, if I'm not on a Mac)

  • I read AGENTS.md and this doesn't reintroduce anything deliberately removed

  • Docs updated if behavior changed

…#336)

AsyncTranscriptionClient.isTransient treated every URLError as transient,
including URLError.cancelled, so cancelling a Library/Record transcription
mid-poll burned all pollAttempts (with sleeps) before surfacing. It now
retries only a named set of network codes (timeouts, dropped/unreachable
connections), never a cancellation.

The upload and submit were single-shot while only the status poll was
retried, so one blip on POST /v2/upload lost a whole recording. Both now
go through the same retry helper: the upload on any transient failure,
the submit only when the API certainly created nothing (a 429, or a
connection that never reached it), since repeating a submit that may
have landed would bill a second transcript.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1WYcKDrTGM1dPNwV1h
The four retry tests pushed FileTranscriptionTests past swiftlint's
250-line type_body_length limit. They now live in
AsyncTranscriptionRetryTests, and the scratch-audio-file helper both
suites need moves to the shared test stubs rather than being copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1WYcKDrTGM1dPNwV1h
@alexkroman
alexkroman enabled auto-merge November 25, 2026 00:13
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 0d8613a Nov 25, 2026
19 of 21 checks passed
@alexkroman
alexkroman deleted the claude/quirky-brown-r5qtaa branch November 25, 2026 01:42
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