Go + Python: honor per-operation retry.max as a ceiling; add parity guard
Problem (A4b2)
Every operation carries a per-op retry.max in behavior-model.json (183 ops at 3, 43 at 2). TypeScript, Swift, and Kotlin honor it; generated Go and Python did not — Python shipped it in metadata.json as dead data, Go emitted no per-op table. So a customized Go/Python client retried the more side-effect-sensitive ops more times than the other SDKs.
Fix — per-op ceiling min(client_cap, op_max)
The per-op field is named max, so it composes with the client cap by taking the smaller (an upper bound on attempts). TypeScript and Swift expose no numeric client cap (only an on/off) and use op_max directly. Kotlin does expose BasecampConfig.maxRetries, but resolves opRetry?.maxRetries ?: config.maxRetries — the per-op value overrides rather than bounds the client cap, so it behaves as a floor (a divergence from the ceiling contract, tracked in #485). Because every op's max ≤ the default cap of 3, min() makes a default-or-raised Go/Python client produce exactly the per-op attempt count (parity), while uniquely honoring a client that lowered its cap to 0/1 to disable/restrict retries.
- Go: emit a separate
operationRetryMaxmap (opId → max) fromx-basecamp-retry.maxAttempts, plus an additiveGetOperationRetryMax(operationId)accessor;doWithRetryreads it and applies the ceiling byoperationId. Kept off the exportedOperationMetadatastruct so wiring it up doesn't change that struct's shape (which would break external unkeyed composite literals) —OperationMetadatais byte-identical tomain. - Python: thread the canonical (PascalCase) operationId into
_request_with_retry(sync + async) for every retryable path. Notably the generated GET/list/pagination methods now passoperation="<OpId>"too — previously they passed nothing or the snake_caseOperationInfo.operation(not a metadata key), so the ceiling silently never applied to the 118 GET ops.
⚠️ Observable behavior change (release-noted in SPEC)
- Default client (
max_retries = 3): only the 9 idempotentmax:2ops (account/gauge/preference writes) change — they now retry at most twice instead of three times. - Client that raised its cap above 3: all 187 retry-eligible ops are now clamped to their per-op
max(the intended meaning of a per-op ceiling, matching TS/Swift/Kotlin). - Client that lowered its cap to
0/1: unchanged.
A4c — retry-metadata parity guard
New scripts/check-retry-metadata-parity.py (wired into make check):
- Criterion 1 (static): emitted per-op retry values EQUAL
behavior-model.jsonacross all six emitters (Python/Ruby/TS/Kotlin/Swift full tuple; Gomax-only from theoperationRetryMaxmap — Go consumes onlymax, so emitting the full inert tuple would be dead data). Fails on missing and stale/extra ops. Distinct from the regenerate-and-diff freshness gates. - Criterion 2 (token-smoke classification, not behavioral proof): usage-form token presence/absence per consuming source classifies TS/Swift/Kotlin = full tuple, Go/Python =
maxonly, Ruby = none. Behavioral proof lives in each SDK's retry tests.
Tests / Verify
- Go per-op ceiling test + Python sync/async ceiling tests, each red-proofed.
- Integration tests through real generated services + the real bundled metadata (
projects.list→ListProjectsmax:3;account.update_account_name→UpdateAccountNamemax:2), proven to fail against the snake_case-key bug (5 attempts vs 3). make py-check(480 tests, mypy, ruff, drift), Go drift + tests, and the parity guard (self-tested against injected stale/extra entries) all green.
Part of the retry-contract follow-up (#456 / #460 / #461 / #476). Shares go/templates/client.tmpl with #481; whichever merges second should be rebased and regenerated (make -C go generate) — disjoint regions, no textual conflict.