Retry: honor the declared retry_on and max_attempts in Go and Python
Closes #479. Stacked on #484 → #483 → main.
#483 fixed the per-operation attempt ceiling. This fixes the other half of Gate 3: the status set.
What was wrong
behavior-model.json declares retry_on: [429, 503] for all 226 operations. Neither Go nor Python consulted it:
- Go used a global
isRetryableStatuscovering{429, 500, 502, 503, 504}(client.gen.go:3964-3974), regardless of what an operation declared. - Python had no status gate at all — its loop keyed off
e.retryable, anderrors.py:153-156marks 500 and 502/503/504 retryable.
So both retried three statuses the spec never sanctioned.
What this does
Go. The declared set is emitted as operationRetryOn, a map[string][]int sibling of #483's operationRetryMax — and for the same reason kept off the exported OperationMetadata struct, so wiring it up cannot break an external unkeyed composite literal. isRetryableStatus now takes the operationId and consults it, falling back to defaultRetryOn for an id absent from the table (unreachable from a generated call site).
Python. _is_retryable_error(error, operation) gates on the operation's declared retry_on, resolved by _operation_retry_on(operation) from the metadata #483 already threads through every call site. Because #483 threads a canonical operation id into get() as well, the read path is governed too — no separate mechanism.
errors.py and ParseHTTPError are untouched. They still classify 500/502/503/504 as retryable to callers. That is the caller-facing hint; it must not widen the transport's gate. error-mapping.json conformance cases pass unchanged.
Network errors stay retryable. They carry no HTTP status, so the status gate does not apply — SPEC §7's network-error rule still governs.
Ungoverned traffic is protected structurally, not by convention
get_absolute() — the hand-written Launchpad authorization request — passes no operation id. So both the status gate and #483's attempt ceiling no-op on it automatically, and it keeps its pre-Smithy contract. That is a better outcome than the explicit policy object this PR carried in its first revision, and it falls out of #483's threading rather than needing new machinery.
Four regressions (sync and async) pin it. They pass identically before and after this change — which is the point: they exist to fail if generated policy ever reaches OAuth traffic.
Guard
Extended #483's scripts/check-retry-metadata-parity.py rather than adding a second script:
- new
from_go_retry_on()extractor +check_retry_on_only()parity check foroperationRetryOn; - Go and Python reclassified
max only→max + retry_on. #483'sforbiddentoken list asserted Go does not consumeRetryOn; this makes that false, so leaving it would have failed the build.
Proof matrix — all fail against the un-fixed code
Python, the full 2×2 (sync/async × mutation/read):
FAILED TestDeclaredRetryStatuses::test_sync_mutation_status_gate[500-1] assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_sync_mutation_status_gate[502-1] assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_sync_mutation_status_gate[504-1] assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_async_mutation_status_gate[500-1] assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_async_mutation_status_gate[502-1] assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_async_mutation_status_gate[504-1] assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_sync_read_status_gate assert 3 == 1
FAILED TestDeclaredRetryStatuses::test_async_read_status_gate assert 3 == 1
Go: made 3 attempts for status 500, want 1 (likewise 502 and 504), plus a read-path case on GetAccount.
SPEC
- Removed "Implementations may expand this set to include other 5xx statuses (500, 502, 504)" — that sentence sanctioned the bug. The declared set is now stated as exhaustive, with an explicit note that an SDK may still classify those statuses as retryable in its error taxonomy without widening the gate.
- Added the Gate 3 consumption table. Corrected since first posting: only Kotlin turns the ceiling into a floor (it is the one SDK with both a numeric caller cap and a resolution order that discards it —
opRetry?.maxRetries ?: config.maxRetries). TypeScript and Swift expose no numeric cap, so there is nothing to discard; Ruby's gap is the mirror image, honoring the caller and never consulting the operation. #485 has been rescoped accordingly, and #483's contradicting rationale paragraph corrected on that branch.
Note for the merge
The base is a stack branch, so GitHub shows no closing reference for #479. Retarget to main before final merge, or close #479 explicitly with landed evidence.
make check exits 0 — real exit code, captured into the log rather than read from a trailing echo.