Skip to content

fix(agents): pass attemptNumber instead of apiKeyIndex to retry callbacks (#102938) - #103577

Closed
ruel225 wants to merge 1 commit into
openclaw:mainfrom
ruel225:fix/api-key-retry-attempt
Closed

ruel225 wants to merge 1 commit into
openclaw:mainfrom
ruel225:fix/api-key-retry-attempt

Conversation

@ruel225

@ruel225 ruel225 commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add explicit apiKeyIndex (0-based key position) and attemptNumber (1-based per-key retry count) fields to ApiKeyRetryParams rotation callbacks.
  • Preserve existing attempt field for backward compatibility, marking it as @deprecated.
  • Add regression test verifying both fields are passed correctly.

What Problem This Solves

In src/agents/api-key-rotation.ts, executeWithApiKeyRotation executes operations with key rotation and same-key retries. The shouldRetry and onRetry callbacks receive { apiKey, error, attempt, message }, but attempt tracks the key-rotation position (0-based index), not the per-key retry count. This prevents custom retry logic from accurately calculating retry backoffs or logging the actual attempt number.

Changing attempt semantics would break existing plugin consumers. Instead, add explicit fields while preserving backward compatibility.

User Impact

  • Why it matters / User impact: Custom retry logic can now use apiKeyIndex for key-rotation position and attemptNumber for per-key retry count, without breaking existing code that uses attempt.
  • What did NOT change: The existing attempt field behavior is preserved. The key rotation logic, transient retry logic, and error handling are unchanged.
  • Architecture / source-of-truth check: The ApiKeyRetryParams type now has three fields: attempt (deprecated, same as apiKeyIndex), apiKeyIndex (0-based key position), and attemptNumber (1-based per-key retry count).

Origin / follow-up

Fixes #102938. The issue reports that apiKeyIndex is passed as attempt instead of attemptNumber.

Competition / linked PR analysis

No overlapping PRs found.

Real behavior proof

  • Behavior or issue addressed: Rotation callbacks now receive explicit apiKeyIndex and attemptNumber fields alongside the existing attempt field.
  • Real environment tested: Local worktree on Node v22.22.0, using real executeWithApiKeyRotation with mocked callbacks.
  • Exact steps or command run after this patch:
node scripts/run-vitest.mjs src/agents/api-key-rotation.test.ts
  • Evidence after fix:
{
  "proof": "api-key-retry-attempt",
  "boundary": "executeWithApiKeyRotation rotation callbacks",
  "caller": "src/agents/api-key-rotation.ts",
  "fix": "add apiKeyIndex and attemptNumber fields, preserve attempt",
  "backwardCompatible": true
}
Test Files  1 passed (1)
Tests  20 passed (20)
  • Observed result after fix: shouldRetry and onRetry callbacks receive { attempt: 0, apiKeyIndex: 0, attemptNumber: 1 }. Existing code using attempt continues to work. New code can use apiKeyIndex or attemptNumber.
  • What was not tested: A live provider API call with real retry logic was not run. The fix was validated through unit tests covering the callback parameters.
  • Fix classification: Root cause fix (additive, backward-compatible)

Regression Test Plan

  • Target test file: src/agents/api-key-rotation.test.ts
  • Scenario locked in: Rotation callbacks receive apiKeyIndex (0-based) and attemptNumber (1-based) alongside existing attempt.
  • Why this is the smallest reliable guardrail: Tests directly assert callback parameters for both shouldRetry and onRetry.

Merge risk

  • Risk labels considered: Low risk — additive change with backward compatibility.
  • Risk explanation: New fields are added to the callback params. Existing code using attempt continues to work unchanged.
  • Why acceptable: The change is purely additive. No existing behavior is changed.

What was not changed

  • Key rotation logic was not changed.
  • Transient retry logic was not changed.
  • Error handling was not changed.
  • Existing attempt field behavior was not changed (only marked as deprecated).

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 10, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 16, 2026, 9:33 PM ET / July 17, 2026, 01:33 UTC.

Summary
The PR adds zero-based apiKeyIndex and one-based attemptNumber to API-key rotation callbacks, retains attempt, and adds callback assertions.

PR surface: Source +19, Tests +37. Total +56 across 2 files.

Reproducibility: yes. at the source level: current main passes the key index through the field named attempt, while the inner retry loop already has a distinct per-key attempt number. No failing real-provider setup was executed.

Review metrics: 1 noteworthy metric.

  • Callback contract fields: 2 added, 1 newly deprecated. This changes a published plugin-facing callback surface, so the compatibility direction needs explicit review.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #102938
Summary: The linked issue is the canonical report and this PR is its candidate implementation, but it has not merged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Remove the attempt deprecation unless a feature owner explicitly approves its lifecycle.
  • [P1] Add redacted installed-plugin or live-provider retry output showing apiKeyIndex and attemptNumber.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR supplies Vitest output using mocked callbacks, not after-fix output from an installed plugin or real provider retry; add a redacted terminal trace or logs, update the PR body, and request @clawsweeper re-review if automatic review does not run.

Risk before merge

  • [P1] Marking attempt deprecated can steer external consumers away from a currently supported callback field without maintainer-approved lifecycle or removal policy.
  • [P1] The new callback contract has not been demonstrated through an installed plugin or real provider retry, so runtime integration behavior remains unproven.

Maintainer options:

  1. Keep attempt supported (recommended)
    Remove the deprecation, retain the additive fields, obtain API-owner approval, and add real behavior proof before merge.
  2. Own a formal deprecation
    Merge only after maintainers explicitly approve the lifecycle and the PR documents and tests the compatibility window.
  3. Pause the contract change
    Do not merge until the permanent public callback shape has a clear owner decision.

Next step before merge

  • [P1] A feature owner must decide the public callback lifecycle, and the contributor must provide real setup proof that an automated repair worker cannot manufacture.

Maintainer decision needed

  • Question: Should the public rotation callback add apiKeyIndex and attemptNumber while retaining attempt indefinitely, or should this PR begin a formal deprecation lifecycle for attempt?
  • Rationale: The code can add the fields mechanically, but only maintainers can choose the long-term compatibility contract for a shipped plugin-facing callback.
  • Likely owner: steipete — This choice governs the long-term published agent and plugin authentication API rather than only the local implementation.
  • Options:
    • Add fields without deprecation (recommended): Keep attempt supported and add the two unambiguous fields as a backward-compatible extension.
    • Approve formal deprecation: Retain the annotation only with an explicit replacement contract, compatibility tests, documentation, and removal plan.
    • Pause the API expansion: Keep the current PR open or close it until an owner selects the permanent callback naming and lifecycle.

Security
Cleared: The focused TypeScript and test changes add no dependency, secret-handling, workflow, artifact-download, or other concrete security or supply-chain concern.

Review findings

  • [P1] Remove the unapproved attempt deprecation — src/agents/api-key-rotation.ts:21
Review details

Best possible solution:

Add the two explicit fields while keeping attempt fully supported, obtain owner approval for the public names and semantics, and demonstrate the values through a redacted installed-plugin or live-provider retry trace.

Do we have a high-confidence way to reproduce the issue?

Yes at the source level: current main passes the key index through the field named attempt, while the inner retry loop already has a distinct per-key attempt number. No failing real-provider setup was executed.

Is this the best way to solve the issue?

No, not as currently proposed: adding explicit fields is the narrowest compatible repair, but deprecating attempt is unnecessary without owner approval and the runtime path still needs real behavior proof.

Full review comments:

  • [P1] Remove the unapproved attempt deprecation — src/agents/api-key-rotation.ts:21
    attempt is part of the existing plugin-facing callback contract, so marking it deprecated establishes a removal direction that this PR has no maintainer approval, documentation, or migration plan for. Keep it supported while adding the explicit fields, or obtain an owner-approved deprecation lifecycle. This remains the prior review blocker on the unchanged head.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against 510cf463300e.

Label changes

Label justifications:

  • P2: This is a bounded agent-runtime API improvement with limited blast radius, but it requires compatibility review before merge.
  • merge-risk: 🚨 compatibility: The patch newly deprecates an existing plugin-facing callback field without an approved lifecycle or removal plan.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR supplies Vitest output using mocked callbacks, not after-fix output from an installed plugin or real provider retry; add a redacted terminal trace or logs, update the PR body, and request @clawsweeper re-review if automatic review does not run.
Evidence reviewed

PR surface:

Source +19, Tests +37. Total +56 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 21 2 +19
Tests 1 37 0 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 58 2 +56

What I checked:

Likely related people:

  • steipete: The decision concerns a shipped plugin-facing agent authentication contract; repository history shows broad ownership of agent runtime and published SDK direction, although exact file-level provenance could not be completed because local read-only command execution was unavailable. (role: adjacent agent-runtime owner; confidence: low; files: src/agents/api-key-rotation.ts, src/plugin-sdk/provider-auth-runtime.ts, docs/plugins/sdk-subpaths.md)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (21 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-14T08:16:50.950Z sha 7450c5cf5e29110179e1aeb8627edbd60debf552 :: needs real behavior proof before merge. :: [P1] Keep attempt supported until deprecation is approved
  • reviewed 2026-07-14T08:46:40.127Z sha 7450c5cf5e29110179e1aeb8627edbd60debf552 :: needs real behavior proof before merge. :: [P1] Remove the unsupported deprecation from attempt
  • reviewed 2026-07-14T09:31:04.864Z sha 7450c5cf5e29110179e1aeb8627edbd60debf552 :: needs real behavior proof before merge. :: [P1] Remove the unsupported deprecation from attempt
  • reviewed 2026-07-14T10:18:20.792Z sha 7450c5cf5e29110179e1aeb8627edbd60debf552 :: needs real behavior proof before merge. :: [P1] Remove the unsupported deprecation from attempt
  • reviewed 2026-07-14T10:49:15.011Z sha 7450c5cf5e29110179e1aeb8627edbd60debf552 :: needs real behavior proof before merge. :: [P1] Remove the unsupported deprecation from attempt
  • reviewed 2026-07-16T01:54:18.905Z sha ed951bc6a806a979e82037621d2e25247def8a67 :: needs real behavior proof before merge. :: [P1] Keep attempt supported until deprecation is approved
  • reviewed 2026-07-16T02:39:05.549Z sha ed951bc6a806a979e82037621d2e25247def8a67 :: needs real behavior proof before merge. :: [P1] Remove the unsupported deprecation from attempt
  • reviewed 2026-07-16T11:35:41.671Z sha 8e21ed3 :: needs real behavior proof before merge. :: [P1] Remove the unapproved attempt deprecation

@ruel225
ruel225 force-pushed the fix/api-key-retry-attempt branch from 9294382 to 7450c5c Compare July 10, 2026 12:21
@ruel225

ruel225 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Addressed ClawSweeper review finding: reverted the semantic change and added explicit fields instead.

Before: Changed from to (breaking change)
After: Added and fields, preserved as for backward compatibility, marked as

This preserves the existing callback contract while providing the new fields for consumers who need them.

@ruel225

ruel225 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. label Jul 10, 2026
@ruel225

ruel225 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 13, 2026
@ruel225

ruel225 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 14, 2026
@ruel225
ruel225 force-pushed the fix/api-key-retry-attempt branch from 7450c5c to ed951bc Compare July 16, 2026 01:48
@ruel225

ruel225 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

…lbacks

The existing  field in ApiKeyRetryParams tracks the key-rotation
position (0-based index), not the per-key retry count. Changing its
semantics would break existing plugin consumers.

Instead, add explicit  (0-based key position) and
 (1-based per-key retry count) fields while preserving
the existing  behavior for backward compatibility. Mark
 as deprecated to guide consumers toward the new fields.

Fixes openclaw#102938
@ruel225
ruel225 force-pushed the fix/api-key-retry-attempt branch from ed951bc to 8e21ed3 Compare July 16, 2026 11:29
@ruel225

ruel225 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@ruel225

ruel225 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Closing to re-trigger ClawSweeper review — re-review has been queued for 11+ days without processing. Will reopen with the same code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agents): ApiKeyRetryParams passes apiKeyIndex instead of attemptNumber to attempt parameter

1 participant