Return context error when a retry backoff wait is cancelled
CI / ci (push) Successful in 1m35s
CI / ci (pull_request) Successful in 1m35s

Retrying.Generate returned the earlier provider error (e.g. a 429) when
cancellation or the deadline interrupted the backoff wait, so callers and
the ai_runs record saw rate limiting instead of cancellation. Return the
context error from the interrupted wait instead. Retry counts, backoff and
other error semantics are unchanged.

Maestro task: 79447ef7-e55c-4641-b351-37bc22ffa760

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-05 11:33:20 -04:00
co-authored by Claude Opus 5.5
parent 72fa311de9
commit e344522c63
2 changed files with 41 additions and 3 deletions
+4 -3
View File
@@ -30,7 +30,8 @@ const (
// rate limit that names no wait, waits a jittered exponential backoff. The Request's Timeout, or DefaultTimeout, is one
// deadline for the whole call, retries and waits included; a caller's
// earlier context deadline wins. A retry whose wait would not end before
// that deadline is not made: the last error is returned at once.
// that deadline is not made: the last error is returned at once. A wait
// cut short by cancellation or the deadline returns the context's error.
// ListModels and Verify pass straight through.
type Retrying struct {
Provider
@@ -83,8 +84,8 @@ func (r *Retrying) Generate(ctx context.Context, req Request) (Response, error)
if !r.now().Add(wait).Before(deadline) {
return resp, err
}
if serr := r.sleep(ctx, wait); serr != nil {
return resp, err
if err := r.sleep(ctx, wait); err != nil {
return Response{}, err
}
}
}