Skip to content

fix(anthropic): rebind reasoning-replay owner after pool rotation - #7193

Closed
vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
vadymhimself:fix/anthropic-rotation-replay-owner
Closed

vadymhimself wants to merge 1 commit into
lidge-jun:devfrom
vadymhimself:fix/anthropic-rotation-replay-owner

Conversation

@vadymhimself

@vadymhimself vadymhimself commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The Anthropic OAuth pool rotation arms (429/403/401) in main adapter dispatch (adapter-dispatch.ts) and the terminal continuation retry (adapter-continuation.ts) commit the next account B but never rebind the route's replay scope. commitResolvedOAuthSelection already updates replayOAuthCredentialSnapshot, but nothing calls bindRouteReasoningReplayScope with it, so the reasoning-replay serving identity, the native-reasoning owner and the provider-continuation owner stay bound to the refused account A.
  • Observed effects on dev (reproduced by the new test):
    • B's retry is built with A's provider-private continuation (private-a).
    • The turn served by B is persisted with __ocxOwner.credentialIdentity = A.
    • The next turn on B, same thread, finds a serving-identity change. It sets _stripReasoningEncryptedContent, which makes the Anthropic adapter drop replayed thinking blocks, and it discards B's continuation as foreign. The client loses reasoning continuity, and the changed history breaks the prompt-cache prefix, so the cache gets written again.
  • Fix: after admission, rebind with transportState.replayOAuthCredentialSnapshot. This is the same call the key-429 and generic OAuth (Kiro/Antigravity) arms already make. The continuation arm rebinds both nextParsed and the outer parsed that persists the response, as its key-429 arm does. No new helper or state.
  • The rotated send to B still strips A's reasoning blobs, because the strip flag stays set for the whole outbound request. Only the persisted owner and the next turn change.
  • Kept off the recovery-kind ternary lines that open PR fix(anthropic): record account 403 rotations as oauth-account-403, not a 429 #7185 edits. git merge-tree against that branch merges cleanly.

Verification

  • Red on dev (60bf4c7) with the source change reverse-applied: both new tests/adapters/terminal-continuation-owner-rotation.test.ts cases (Anthropic pool rotation on the initial send … and … on the terminal continuation …) fail. The persisted owner is A, B's build carries private-a, and the follow-up build on B has stripReasoning: true with no continuation.
  • Green after the fix: bun test tests/adapters/terminal-continuation-owner-rotation.test.ts gives 3 pass, 0 fail.
  • bun run typecheck: passes.
  • bun run structure:check: passes.
  • bun run privacy:scan: passes.
  • bun run test:changed (against dev 60bf4c7): 14561 pass, 1 fail across 575 files. The failure is tests/cli/cli-connect-readiness.test.ts › connected-client runtime probe scope > a rejected preferred runtime falls back without rewriting the saved selection. It also fails on a clean dev worktree and is unrelated to this change.
  • I did not run the full bun run test locally. test:changed covers the import graph of both changed source files, and CI covers the rest.
  • No GUI changes.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Anthropic account failover when a request is rate-limited. Retries and ongoing terminal continuations now consistently use the selected account and its session state, reducing the risk of interrupted or mismatched responses.
    • Improved handling of protected reasoning content during account changes, with appropriate safeguards applied when requests are retried.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@vadymhimself

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d75b68b6-7e3a-4a88-b77e-022eea43b35c
📥 Commits

Reviewing files that changed from the base of the PR and between 60bf4c7 and ac78226.

📒 Files selected for processing: 3
  • src/server/responses/adapter-continuation.ts
  • src/server/responses/adapter-dispatch.ts
  • tests/adapters/terminal-continuation-owner-rotation.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

Anthropic OAuth account failover now binds the replay credential snapshot to the parsed request and continuation clone. Tests cover rotation from account A to account B during initial sends and terminal continuations.

Changes: Anthropic OAuth Rotation

Layer / File(s) Summary
Bind replay scope after rotation
src/server/responses/adapter-dispatch.ts, src/server/responses/adapter-continuation.ts
The failover paths bind the replay reasoning scope to the replay OAuth credential snapshot. The continuation path applies this binding to both nextParsed and the outer parsed request.
Verify rotated account ownership
tests/adapters/terminal-continuation-owner-rotation.test.ts
Parameterized tests cover initial sends and terminal continuations. They check account authorization order, response ownership, provider continuation state, and whether reasoning is stripped. Test setup and teardown also clear Anthropic account-pool state.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Suggested reviewers: lidge-jun

Merge Risk: ⚪ Minimal · up to ac782

The reviewed rotation paths bind replay ownership to the admitted account. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the Anthropic fix and the specific reasoning-replay ownership issue after OAuth pool rotation. It accurately summarizes the main change.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 15, 2026
@vadymhimself
vadymhimself force-pushed the fix/anthropic-rotation-replay-owner branch from ac78226 to 84eba62 Compare October 15, 2026 20:35
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

The Anthropic OAuth 429/403/401 rotation arms in adapter dispatch and the
terminal continuation committed account B but left the reasoning-replay
scope, native-reasoning owner, and provider-continuation owner bound to
the refused account A. B was sent A's private continuation, the turn's
state was persisted as owned by A, and the next turn on B stripped the
replayed reasoning and dropped B's continuation as foreign. Rebind with
the admitted credential snapshot, as the key-429 and generic OAuth arms
already do; the continuation arm rebinds both parsed requests.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Being carried into #7224 with your authorship preserved; this PR will be closed when the bundle lands.

lidge-jun added a commit that referenced this pull request Oct 16, 2026
…evidence fixes (#7191, #7204, #7187, #7209, #7175, #7185, #7193, #7197, #7198) (#7224)

Carried from #7191, #7204, #7187, #7209, #7175, #7185, #7193, #7197, #7198 (one commit per source PR, original author preserved). Security review follow-up: the Anthropic 402 combo cooldown now validates the sending credential's ownership before cooling an account.

Remote validation (hosted GitHub Actions unreliable; local tests not run by maintainer rule): union candidate codex/prr-integ-8 = dev c03eafd + #7224 + #7223 + #7225 + #7217 + #6454 + #6594 plus a Gentle Shell import-cycle fix (integ-9 e1f289c: typecheck + full suite on mini (Windows) and lidge (Linux), compared with the same host's dev runs) and a test-only Windows path-escaping fix for the reasoning-retention routing test (integ-10 0d4cba7, tree a2b309a: that file re-run on both hosts).

Co-authored-by: Vadym O <bolein95@gmail.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Landed on dev in 6ccb47a via #7224 (your change is its own commit in that bundle, and the squash keeps your authorship as Co-authored-by). Thank you!

@lidge-jun lidge-jun closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants