Skip to content

Retry transient upstream errors in handle_exceptions decorator#2563

Merged
hiroshinishio merged 1 commit intomainfrom
wes
Apr 20, 2026
Merged

Retry transient upstream errors in handle_exceptions decorator#2563
hiroshinishio merged 1 commit intomainfrom
wes

Conversation

@hiroshinishio
Copy link
Copy Markdown
Collaborator

No description provided.

Sentry AGENT-36Z/36J were transient GitHub 5xx on git push surfacing as
a plain ValueError from run_subprocess wrapping the remote stderr. The
existing retry path in the decorator only fired on requests.HTTPError
rate limits, so these ValueErrors bubbled straight through, reported to
Sentry, and the push just failed.

Adds is_transient_error to recognize GitHub 5xx, remote Internal Server
Error from subprocess, and HTTP 5xx message markers. handle_exceptions
now retries the wrapped function up to TRANSIENT_MAX_ATTEMPTS (3) with
linear backoff when the raised exception matches. 5xx responses almost
always mean the server did not complete the operation so retry is safe
by default for all decorated functions; non-transient exceptions still
fail fast on the first attempt.

Split handle_http_error, handle_json_error, and handle_generic_error
into their own files and extracted GitHub 403/429 rate-limit handling
into handle_github_rate_limit. handle_exceptions.py is now just the
decorator plus the retry loop.

Exempted handle_exceptions.py from the cast-usage lint: the generic
decorator with ParamSpec + TypeVar genuinely needs cast to bridge the
async wrapper's Coroutine[..., R] against the declared Callable[P, R].

Added regression tests for git_commit_and_push retry behavior, the new
helpers, and is_transient_error classification. Updated CLAUDE.md to
flag hard-wrapped comment sentences. Repointed existing tests that
patched utils.error.handle_exceptions.sentry_sdk to patch the module
function directly, which works across all new helper locations. Also
rewrote pre-existing partial in/not-in assertions in touched test files
to exact == equality per CLAUDE.md.
@hiroshinishio hiroshinishio self-assigned this Apr 20, 2026
@hiroshinishio hiroshinishio merged commit 2d03d9b into main Apr 20, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch April 20, 2026 05:54
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.

1 participant