Repository navigation
fix(agents): separate retry count from API key position (#102938) - #115507
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 9:34 PM ET / August 25, 2026, 01:34 UTC. ClawSweeper reviewWhat this changesThe PR makes API-key rotation callbacks report the one-based per-key retry count as Merge readinessKeep open. This is a coherent, narrow repair: current main passes the key position as Likely related people: Peter Steinberger, based on current-main line attribution (low confidence due shallow local history). Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherAPI-key rotation wraps provider operations that fail from a key-specific limit or transient failure. It decides whether to retry the same key, rotate to the next key, or return the final error, and callback consumers receive that retry context. flowchart LR
A[Provider operation] --> B[API-key rotation]
B --> C[Run current API key]
C --> D{Failure decision}
D --> E[Rotation callback]
D --> F[Same-key retry]
E --> G[Next API key]
F --> C
G --> C
C --> H[Result or final error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +15, Tests +74. Total +89 across 2 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Land the focused callback-contract repair with its regression tests, retaining Do we have a high-confidence way to reproduce the issue? Yes. Current main directly shows the mismatch: the loop maintains Is this the best way to solve the issue? Yes. Changing the two callback payloads at the rotation owner and adding a divergent-counter regression is the narrowest maintainable fix; existing in-repo consumers do not use these callbacks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b840a3c84e2c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Added real behavior proof to the PR body: a script driving the real @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
P2 addressed: removed the duplicate @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Re-ran the proof on the exact final head (aa815a46c8b). The transcript now shows only attempt and apiKeyIndex — attemptNumber is no longer emitted (duplicate field removed). PR body Evidence updated to match the submitted head. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
The |
|
Updated the PR body to match the final head — removed all references to the deprecated @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
ClawSweeper recorded closeout evidence for this proposed close.
|
|
Thanks @ruel225! Proof: A controlled two-key run on exact main reported callback
Example
|
Summary
attemptthe one-based execution count for the current API key.apiKeyIndexas the zero-based key position.What Problem This Solves
API-key rotation tracked both a one-based retry count and a zero-based key position. The callback field named
attemptreceived the key position, so callbacks could not tell a same-key retry from a move to another key.Fixes #102938
Why This Change Was Made
The rotation owner now builds one callback context from the current execution.
attemptcomes from the per-key execution loop, whileapiKeyIndexcomes from the key loop. BothshouldRetryandonRetryreceive that same context.The earlier
attemptNumbercallback field from #103577 was not retained. It never shipped, and it duplicated the correctedattemptfield. The separate transient-retry classifier keeps its existingattemptNumbercontract.Compatibility
Maintainer decision: Accept the semantic correction to
attempt. A stable release exposed the old index-valued callback throughplugin-sdk/provider-auth-runtime, but that subpath is now private-local and JavaScript-only. No in-repo caller supplies either rotation callback.Private-local consumers must read key position from
apiKeyIndexafter this change. Keeping index position inattemptwould preserve the reported naming defect, while addingattemptNumberwould create a second name for the same retry count.User Impact
attempt, such as0, 0, 1across two keys.attempt(1, 2, 1) and key positions asapiKeyIndex(0, 0, 1).Evidence
Real behavior proof: The production
executeWithApiKeyRotationowner ran with two controlled keys. The first key failed twice, the second key failed once, and the fourth execution succeeded. The second callback requested rotation. Both revisions executedkey-1, key-1, key-2, key-2and performed two same-key retry sleeps.629a47e3cc20a9f8b6d19c105f840b8a693ec4aa:attemptwas0, 0, 1;apiKeyIndexwas absent.ee3e95ac04e85d2324881d25bac18a473b09f06a:attemptwas1, 2, 1;apiKeyIndexwas0, 0, 1;attemptNumberwas absent.onRetryreceivedattempt: 2andapiKeyIndex: 0before rotation.{ "contractPass": true, "result": "ok:key-2", "executions": ["key-1", "key-1", "key-2", "key-2"], "sameKeyRetrySleeps": 2, "shouldRetry": [ { "attempt": 1, "apiKeyIndex": 0 }, { "attempt": 2, "apiKeyIndex": 0 }, { "attempt": 1, "apiKeyIndex": 1 } ], "onRetry": [{ "attempt": 2, "apiKeyIndex": 0 }], "attemptNumberPresent": false }Regression test:
node scripts/run-vitest.mjs src/agents/api-key-rotation.test.tsChanged-scope checks: formatting, lint, production types, test types, dependency checks, dead-export checks, import-cycle checks, and selected repository guards passed.
Production LOC: +8/-8 (net 0) | Tests: +41/-0