feat: retry 403 on GET for eventually consistent reads #112
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #112"
general
weight: 0.35
sdahal-bt
Pull Request
Description
Reads are eventually consistent: an object that was just written may not yet be visible to an immediately following
GET, and the API reports that as403rather than404. Previously these surfaced as generic errors and failed an apply intermittently, with nothing the operator did to cause them.DoRequestnow retriesGETon the secrets path when it fails with403, backing off exponentially up to a 500ms cap:| attempt | nominal sleep | probe at |
|---|---|---|
| 1 | — | 0ms |
| 2 | 25ms | 25ms |
| 3 | 50ms | 75ms |
| 4 | 100ms | 175ms |
| 5 | 200ms | 375ms |
| 6 | 400ms | 775ms |
| 7 | 500ms | 1275ms |
| 8 | 500ms | 1775ms |
The schedule is front-loaded because reads normally converge quickly, so nearly every stale read clears on the second or third attempt. The long tail exists only to absorb rare outliers and costs nothing in the common case. The bounds were chosen from internal service latency measurements.
Capping a single sleep at 500ms rather than letting it double to 800ms lets the same budget fit one more probe, so the schedule both reaches further (1775ms, up from 1575ms) and leaves a smaller worst-case gap between probes (500ms, down from 800ms), for one extra request.
Every duration above is nominal. Each sleep is then scaled by a random factor within 25% of it, because Terraform applies resources in parallel and without jitter every worker that hits a stale read would retry in lockstep. Jitter is proportional rather than full — a uniform value in
0, d)would halve the expected schedule and with it the tail coverage the budget was sized for. The budget is accounted against the nominal schedule, so the attempt count is fixed at 8 and only the timing varies; a single sleep can reach 625ms and the total 2218ms.Scope and deliberate omissions
GETon the secrets path only. Writes do not observe eventually consistent reads, and other surfaces of the API do not share the behaviour — a403from the auth service behindBuildAuthPathfails on the first attempt. The one external non-GETcaller ofDoRequest(aPATCH) is unaffected.403only, checked directly rather than viaIsPermissionError, which also matches401. An invalid token will not become valid, so retrying it would only add latency — expired tokens still fail on the first attempt.403that outlives the budget is returned unchanged. It is deliberately not mapped to not-found: that would conflate a genuine authorization failure with a deleted object, and could empty state on a permission regression.APIError rather thanctx.Err(), so callers keep the typed error they classify failures on.Retries rebuild the request per attempt instead of replaying one, which is free for
GETand keeps body rewinding correct if this is later extended to writes.StaleReadInitialBackoffandStaleReadMaxElapsedare exposed onClientso the budget is tunable without touching the loop; a zero backoff disables retrying entirely.Reviewer notes
403, and the not-found helpers (resource_common.go,workload_identity_helpers.go) remain 404-only, so drift detection still cannot self-heal from out-of-band deletion. Pre-existing and unchanged here.429/502/503/504and network-level errors is a separate change;go-retryablehttpis already an indirect dependency. Note504onPOSTmust not be retried, since a duplicate create is not recoverable.Testing
7 new tests in
internal/client/client_test.go, following the existinghttptest+ table-driven style with atomic attempt counters:403→200succeeds on retry (2 requests)403returns typedAPIErrorafter exactly 7 attemptsPOST/PUT/PATCH/DELETEnever retry (1 request each)400/401/404/409/500never retry (1 request each)*APIErrorNewClientwires the budget; schedule fits inside itgo build ./...,go vet,gofmt, and the fullgo test ./...all pass. No existing test required changes.One test sleeps through the real schedule (~1.6s), taking the package from 0.5s to ~1.9s. That is deliberate — it is the only end-to-end check of the production budget.
Jira tickets and links
Checklist
🤖 Generated with Claude Code
[SMOP-1690]: https://beyondtrust.atlassian.net/browse/SMOP-1690?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ