Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Jan 30, 2026

Summary

Fixes #142

Adds automatic retry when API requests time out with "The operation timed out." error, instead of failing immediately. Uses configurable retry intervals of 30s, 60s, and 120s (3 retries max).

Root Cause

The "The operation timed out." error is a DOMException with name === 'TimeoutError', generated by AbortSignal.timeout(). The AI SDK's handleFetchError() re-throws this error as-is (not wrapped in APICallError), so it bypasses the existing retry logic and creates an unretryable NamedError.Unknown.

Changes

  • js/src/session/message-v2.ts: Added TimeoutError error type; detect DOMException with name === 'TimeoutError' and generic timeout errors in fromError()
  • js/src/session/retry.ts: Added timeout-specific retry configuration: 3 retries with 30s, 60s, 120s delays
  • js/src/session/processor.ts: Added retry handling for TimeoutError alongside existing APIError and SocketConnectionError retry paths
  • js/tests/timeout-retry.test.js: 16 tests covering timeout error detection, retry configuration, and delay calculation
  • docs/case-studies/issue-142/: Case study with root cause analysis and original error log

Retryable errors now handled

Error Type Source Retry Config
APIError (isRetryable) HTTP 408, 409, 429, 500+ Exponential backoff (2s base) with retry-after header support
SocketConnectionError Bun 10s idle timeout Exponential backoff (1s, 2s, 4s)
TimeoutError (NEW) AbortSignal.timeout() Fixed intervals (30s, 60s, 120s)

Test Results

All 29 retry-related tests pass (16 new + 13 existing socket-retry tests). Lint passes with no warnings.

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #142
@konard konard self-assigned this Jan 30, 2026
@konard konard marked this pull request as ready for review January 30, 2026 15:10
@konard
Copy link
Contributor Author

konard commented Jan 30, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Model: Big Pickle
  • Provider: OpenCode Zen
  • Public pricing estimate: $0.00 (Free model)
  • Token usage: 0 input, 0 output
    📎 Log file uploaded as Gist (592KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard marked this pull request as draft January 30, 2026 17:59
@konard
Copy link
Contributor Author

konard commented Jan 30, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-30T17:59:25.788Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 3 commits January 30, 2026 19:06
Document the root cause analysis of why timeout errors are not retried,
including error propagation path through AI SDK and the agent's error handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Detect DOMException TimeoutError (from AbortSignal.timeout()) and generic
timeout errors, creating a retryable TimeoutError that triggers automatic
retry with configurable delays (30s, 60s, 120s for up to 3 attempts).

Previously, timeout errors fell through to NamedError.Unknown and were
not retried, causing immediate session failure on transient network issues.

Fixes #142

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] We should automatically retry on: The operation timed out, not fail immediately Add automatic retry for timeout errors with configurable intervals Jan 30, 2026
konard and others added 2 commits January 30, 2026 19:14
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 30, 2026 18:19
@konard
Copy link
Contributor Author

konard commented Jan 30, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $7.847072 USD
  • Calculated by Anthropic: $5.596183 USD
  • Difference: $-2.250889 (-28.68%)
    📎 Log file uploaded as Gist (1647KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit c7aeb32 into main Jan 30, 2026
8 checks passed
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.

We should automatically retry on: The operation timed out, not fail immediately

2 participants