fix: skip retries for non-retryable errors via NonRetryable marker interface#1157
Open
qozle wants to merge 1 commit intoanthropics:mainfrom
Open
fix: skip retries for non-retryable errors via NonRetryable marker interface#1157qozle wants to merge 1 commit intoanthropics:mainfrom
qozle wants to merge 1 commit intoanthropics:mainfrom
Conversation
…terface retryWithBackoff retried all errors unconditionally, including deterministic failures like WorkflowValidationSkipError (401 workflow-not-on-default-branch), wasting ~35 seconds per occurrence. Introduces a NonRetryable marker interface in src/utils/errors.ts. Any error class that sets `retryable = false as const` is automatically skipped by retryWithBackoff without requiring callers to pass a custom shouldRetry option. The shouldRetry option is also added to RetryOptions for explicit control. WorkflowValidationSkipError now implements NonRetryable, fixing the primary reported case. The shouldRetry check is guarded inside `attempt < maxAttempts` to prevent spurious "aborting retries" log messages on the final attempt. Also fixes a gap in prepare.ts: WorkflowValidationSkipError was not caught there, causing the action to fail instead of skip (run.ts already handled this correctly). Updates misleading comments in github-file-ops-server.ts that claimed non-403 errors would not be retried — they were. See anthropics#1156 for the follow-up fix. Closes anthropics#1081
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.
Summary
Fixes #1081.
retryWithBackoffretried all errors unconditionally, includingWorkflowValidationSkipError(thrown on 401 workflow-not-on-default-branch failures), wasting ~35 seconds per occurrence across 3 retry attempts.Approach
This PR introduces a
NonRetryablemarker interface rather than requiring callers to pass an explicitshouldRetrypredicate (the approach in #1082). Errors self-declare their retryability:WorkflowValidationSkipErrornow implementsNonRetryable:retryWithBackoffdefaults to skipping retry for anyNonRetryableerror, so no changes are needed at existing call sites. Future non-retryable errors (e.g. anHttpErrorfor 4xx status codes, tracked in #1156) get the same behavior automatically just by implementing the interface.The
shouldRetryoption is also added toRetryOptionsfor callers that need explicit control.Additional fixes
prepare.tsgap:WorkflowValidationSkipErrorwas not caught inprepare.ts, causing the action tosetFailedinstead of silently skipping.run.tsalready handled this correctly — this PR bringsprepare.tsin line.attempt < maxAttempts, so "aborting retries" is never printed on the final attempt of a normal retryable error.github-file-ops-server.ts: Two call sites had comments claiming non-403 errors would "fail immediately without retry" — they did not. Comments updated to reflect actual behavior. The underlying fix for those call sites is tracked in retryWithBackoff: non-retryable intent in github-file-ops-server.ts is unenforced #1156.Tests
17 new tests in
test/retry.test.tscovering:NonRetryabledefault (no explicitshouldRetryneeded)shouldRetryoptionmaxAttempts=0, non-Error thrown values,shouldRetrycalled-with assertionWorkflowValidationSkipErroris not retriedAll 670 existing tests continue to pass.