Go: replay *WithBody request bodies across retries
Problem
The generated client's doWithRetry rebuilds each attempt's request via buildRequest(), which recreates it from the caller's single-use io.Reader. The raw *WithBody(..., body io.Reader) methods therefore shipped an empty (or, after a partial-read network failure, mid-stream) body on every retry attempt. All 42 idempotent raw *WithBody ops (Update*/Reposition*/Set*/Replace*/Toggle*/MarkAsRead, reaching BC3 over PUT/DELETE) retry, so a transient 429/503/network failure could resend a truncated body.
Fix
doWithRetry now decides once how a retry reproduces the first finalized body, under a documented, net/http-consistent contract that never rewrites req.Body:
- Attempt 1 always sends
req.Bodyexactly asbuildRequest+ the request editors left it — so an editor that compresses/encrypts/transforms the payload (and sets matching headers) is honored, even with no retry. - A retry replays via
req.GetBody, exactly as net/http replays a body on a 307/308 redirect — but only when the builder's body survived the editors unchanged (checked against the pre-editor reference) andGetBodyprobes OK. - If an editor replaced
req.Body, the builder'sGetBodyis stale and the finalized bytes can't be reproduced, so the request is sent once (not retried with the wrong body). An in-place mutation without aGetBodyupdate is undetectable and, like a redirect, would replayGetBody's snapshot — editors should replace the body or keepreq.GetBodyin sync. - No
GetBody/ non-idempotent → single attempt.nilandhttp.NoBodyare reproduced faithfully (the sentinel is installed unwrapped so retry framing stays identical —Content-Length: 0, never chunked).
The SDK's own hand-written idempotent updates (Todos/Cards/CardSteps/Checkins/Projects/People/Schedules.Update + UpdateAccountLogo) marshal bodies via marshalBody, which now returns *bytes.Reader (net/http snapshots it into GetBody) instead of the old rewindableReader, so they keep retrying. On a retry the replay body is installed before the editors run (so body-aware editors sign the sent bytes) and owned via a close-once handle released after the editor phase even if an editor replaces it. ContentLength is restored per path. The fix lives in go/templates/client.tmpl (regenerated) plus helpers.go.
Tests
Outside pkg/generated per the repo rule — 18 tests (9 fail against the shipped client): empty/truncated retry body, wrong retry ContentLength, no-GetBody stream sent once, partial-read byte-0 restart, replaced body sent verbatim then not retried (with and without a matching GetBody), in-place mutation sent on attempt 1, empty-body transfer framing through a real net/http Transport, orphaned/leaked replay handles (replacement + replace-then-error), a signing editor (reads GetBody) whose digest matches the sent body on both attempts, and empty-body-not-nil; the rest are regression proofs and controls. Each proof is individually red-proofed. Plus a public-service retry proof (ProjectsService.Update) and a marshalBody snapshotability test. Go conformance's naturally-idempotent PUT/DELETE cases pass; -race, drift, go vet, golangci-lint green.
Behavior note
Attempt 1 sends req.Body as the editors finalized it (honoring body-transforming editors); retries replay via req.GetBody when the body was not replaced, else the request is sent once. Editors that transform the body must keep req.GetBody in sync for retries (per the net/http contract). No API signature changes.
Part of the retry-contract follow-up (#456 / #460 / #461 / #476). #482 and #483 are merged; this branch is rebased on top of them (shared client.tmpl regions are disjoint) and regenerated.