Align generated Go + Python retry loops to total-attempt semantics (A4b1)
SPEC.md and behavior-model.json define max_retries / retry.max as a total attempt count (including the initial request): max_retries = 3 means at most 3 attempts. Ruby, Kotlin, and the hand-written Go client already honor this; generated Go (doWithRetry) and Python (sync + async _request_with_retry) treated it as additional retries (MaxRetries + 1), making one extra request.
This aligns both to total-attempts.
⚠️ Observable change
With the default of 3, requests now make up to 3 attempts, not 4. (max_retries was already documented as a total attempt count; the generated-Go and Python transports were the outliers.)
Effective-attempts algorithm (identical for generated Go and Python)
max_retries < 0→ configuration error. Generated Go returns a plainerrorfromWithRetryConfigand re-checks insidedoWithRetry(RetryConfigis publicly mutable after construction); Python already raisesValueErroratConfigconstruction (immutable thereafter).max_retries == 0→ a single attempt, no retry — an explicit compatibility exception to SPEC's≥ 1.max_retries > 0→max_retriesattempts.
This also fixes a latent generated-Go bug: a negative MaxRetries previously made the loop body never execute and returned (nil, nil).
Docs / user-visible strings brought in line
- SPEC.md validation note now enumerates the three distinct
max_retries = 0outcomes across four implementations (generated Go & Python accept → 1 request; Ruby makes 0 requests and raises; hand-written Go panics) and distinguishes generated from hand-written Go. python/README.md: "3 retries, up to 4 total attempts" → "3 attempts"; env-var table "N+1 total attempts" → "Total attempts including the initial request".- Python / Ruby / hand-written-Go exhaustion strings: "retries" → "attempts" (values were already total-correct; only the wording lied).
Scope
A4b1 only. A4b2 (generated Go / Python honoring per-op retry.max) is deliberately deferred — that per-op divergence remains and is not addressed here.
Tests
- Generated-Go retry counts
{0→1, 1→1, 3→3}, negative rejected both atWithRetryConfigand via post-construction mutation intodoWithRetry, and a deterministic no-sleep-after-final-attempt test (fakeHttpRequestDoer+ context cancellation — no wall-clock threshold). Lives ingo/pkg/basecamp, outsidepkg/generatedper the repo rule. - Python sync + async attempt-count parity and negative-at-construction.
make check green.
Summary by cubic
Aligns generated Go and Python retry loops to total-attempt semantics so max_retries is the total number of attempts. With the default of 3, requests now make up to 3 attempts, not 4.
-
Bug Fixes
- Generated Go (
doWithRetry) and Python (sync + async) now use total-attempts:< 0→ configuration error;0→ one attempt;> 0→ N attempts. Go validates inWithRetryConfigand re-validates in-call; fixes the negative-MaxRetries(nil, nil)bug. - Python
Configrejects negatives and non-integers (includingbool), preventing fractional or misleading attempt counts. - No sleep or
OnRetryafter the final attempt in both generated and hand-written Go; tests pin this behavior. Exhaustion messages now say “attempt(s)” in Go, Python, and Ruby; docs updated (SPEC.md,python/README.md).
- Generated Go (
-
Migration
- Behavior change: default
3means up to 3 attempts. Update tests/monitoring that assumed 4. - Scope: A4b1 only. Per-operation
retry.max(A4b2) is unchanged.
- Behavior change: default