Repository navigation
fix(auth): prevent concurrent OAuth turns from failing after refresh - #185880
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
| JSON.stringify([ | ||
| "mcp-auth-profile-v1", | ||
| profileId, | ||
| selectedPath, | ||
| ...lineage.map((target) => [target.databasePath, target.incarnation]), | ||
| ]), |
Serialize authorization capture across overlapping canonical stores so first-use lifetime enrollment cannot invalidate another capture of the same shared account. Keep each caller's own authority and the native writer's strict stale comparison, revocation checks, and uncertain-settlement refusal. Preserve same-account peer inheritance, restart behavior, and fail-closed mismatch and logout behavior. Regress the concurrent capture and independent disposal. Related: #185732, #184791
Preserve the concurrent OAuth authority regression and its diagnostic assertion. The synchronized base already exceeds the ceiling by 472 lines; this change adds 17. Set the ceiling to the exact measured total with no extra headroom. Independently reviewed; the failed ratchet now passes.
2939f3c to
bb71315
Compare
|
Codex review: blocked before merge. What this changesThis PR serializes authorization capture across overlapping credential stores while preserving each caller’s independent authority. Example: Two agents concurrently capture the unchanged authority-proof:default OAuth account for the first time.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this maintainer PR repairs a current authorization-enrollment race with a focused change; no introduced correctness defect was found. Priority: P1 Before merge
FindingsNone. Agent review detailsHow this fits togetherThe authorization owner reads canonical local and shared credential stores and returns token-free handles that guard subsequent credential resolution and provider requests. flowchart TD
A[Concurrent agent turns] --> B[Canonical store keyed queue]
B --> C[Read and enroll authorization]
C --> D[Independent authority handles]
E[Credential writer publications] --> D
D --> F[Guarded provider requests]
Technical reviewBest possible solution: Retain the owner-level serialization and strict credential comparisons, then land once the existing CI and alert-disposition gates are satisfied. Do we have a high-confidence way to reproduce the issue? The unqueued main implementation and strict whole-row enrollment comparison explain the failure, corroborated by the PR’s before/after Gateway results and the independent report at #185919; this review ran no target code. Is this the best way to solve the issue? Serializing the complete initialization sequence in the existing authorization owner is the smallest complete fix: it prevents enrollment collisions without weakening reconnect detection or sharing caller authority. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a4a8f632da0a. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +13, Tests +17, Docs +5, Other 0. Total +35 across 5 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 27, 2026, 9:00 AM ET / 13:00 UTC. |
|
Inherited-CI landing evidence for head Run 40506151388 failed only the cron OAuth continuity test job (plus its downstream CI gate). The refreshable-control and access-only HTTP adoption cases both fail at line 580 with no observed HTTP request, despite successful synthetic model output. The exact single-file command All other selected CI jobs passed, including the repaired test-line ratchet, and the original OAuth refresh Gateway file passes all three cases. Independent review is clean; exact-head security-sensitive/dependency review passed. Landing under the requested inherited-failure exception, without rerunning CI or claiming the failed run green. CodeQL alert #1171 was independently verified as a false positive on the unchanged UUID-based identifier hash; delegated dismissal request #74 remains pending. |
Initialize the complete agent transport host before provider interception so lazy runtime setup cannot retain a copied spy past teardown. Preserve all credential continuity, revocation, restart, and real HTTP assertions. Repairs the inherited cron integration failure recorded in #185880; no production behavior changes.
* test(cron): isolate auth continuity transport spies Initialize the complete agent transport host before provider interception so lazy runtime setup cannot retain a copied spy past teardown. Preserve all credential continuity, revocation, restart, and real HTTP assertions. Repairs the inherited cron integration failure recorded in #185880; no production behavior changes. * test(cron): keep transport setup explanation inline
…penclaw#185880) * fix(auth): prevent concurrent OAuth turns from failing after refresh Serialize authorization capture across overlapping canonical stores so first-use lifetime enrollment cannot invalidate another capture of the same shared account. Keep each caller's own authority and the native writer's strict stale comparison, revocation checks, and uncertain-settlement refusal. Preserve same-account peer inheritance, restart behavior, and fail-closed mismatch and logout behavior. Regress the concurrent capture and independent disposal. Related: openclaw#185732, openclaw#184791 * chore(test): refresh measured test-line ceiling Preserve the concurrent OAuth authority regression and its diagnostic assertion. The synchronized base already exceeds the ceiling by 472 lines; this change adds 17. Set the ceiling to the exact measured total with no extra headroom. Independently reviewed; the failed ratchet now passes.
* test(cron): isolate auth continuity transport spies Initialize the complete agent transport host before provider interception so lazy runtime setup cannot retain a copied spy past teardown. Preserve all credential continuity, revocation, restart, and real HTTP assertions. Repairs the inherited cron integration failure recorded in openclaw#185880; no production behavior changes. * test(cron): keep transport setup explanation inline
What Problem This Solves
Fixes concurrent OAuth turns failing after a successful shared-account refresh with
MCP_AUTHORIZATION_UNAVAILABLE.User Impact
The refreshing agent and its waiting peer can both use the verified same-account rotation, including after restart. Account mismatches and logout still refuse credentials.
Why This Change Was Made
#184791 correctly added live authorization capture to OAuth turns, exposing a latent race in first-use enrollment. Concurrent captures inspect the same canonical store; one enrollment can invalidate the other's read or strict enrollment comparison even though both requested the same account.
The authorization owner now uses the existing keyed queue for the complete read/enroll/capture sequence, keyed by both canonical database paths. Each caller keeps its own closure, live owner checks, readers, and disposable handle. The native writer's strict comparison, revocation/rebinding checks, pending-write fence, and unknown-settlement refusal remain intact. Ignoring authorization-lifetime differences would lose identical-byte reconnect protection, so the fix coordinates enrollment instead.
Captures sharing a database serialize initialization; disjoint stores remain independent. Production growth is 13 lines (the larger diff is indentation), needed to retain the existing security contract. This is a correctness repair with no performance claim.
Evidence
Current-main reproduction at
69ad14ea81bc47ad658c9fc3a4b669f90eeab348: the actual built-Gateway file fails the same-account peer withMCP_AUTHORIZATION_UNAVAILABLE; mismatch and logout pass (1 failed, 2 passed).Adjacent revision comparison with the unchanged Gateway test:
c00af62f03e6ab9929234a998693f53341a4e126passes the same-account/restart case; the immediately following fix: renew OAuth credentials during long custom transport attempts #184791 commitc152c5976b218bf62f7c7666c4703d1a39ecfa80fails its peer-success assertion. Both revisions were rebuilt independently in this lane.The new native-owner regression fails before the fix: two concurrent first-use captures produce one fulfilled and one rejected result. It also checks independent disposal and replacement invalidation.
Focused validation: 54 tests passed across the authorization owner, native writer observation, request-auth controller, and prompt-prefix stability files. The command took 652.70 seconds including worker preparation on a loaded Mac; the new concurrent-capture case took 2.447 seconds. Core typecheck, changed-file lint, formatting, and
git diff --checkpassed.Built-Gateway candidate proof on pushed head
2939f3c824e9b19897f3f70fbf2e5493fdfe269f: all 3 original cases passed (same-account peer/restart, account-mismatch refusal, and logout revocation before stale refresh settlement). The prebuilt Gateway test command took 157.74 seconds; test cases took 43.002, 16.515, and 25.085 seconds respectively. No authority assertion was weakened.Independent subagent review (autoreview route unavailable): scoped-clean at P1/P2. The configured autoreview route failed its configuration preflight; no operator configuration was changed. The subsequent exact test-line ceiling refresh was independently reviewed and verified against the script's counting method.
First PR CI run 40503408340: all selected tests, typechecks, lint, source contracts, and guards passed except the test-line ceiling. It reported 6,281,655 lines versus 6,280,000, with only +17 from this PR. After the required main rebase, the measured total is 6,282,728 versus the updated 6,282,239 ceiling (472 inherited excess +17 here). The ceiling now equals that exact total, with zero headroom; the failed ratchet passes locally. This preserves the native concurrency regression and Gateway diagnostics without weakening any assertion. Authorization sources, queue, state sources, affected tests, package manifest, and lockfile are unchanged from the tested head. Final exact-head CI is recorded below.
Related: #185732, whose failed OAuth CI job and maintainer attribution identified this inherited red. No Team load or Testbox lease was used; all runtime proof uses isolated synthetic local Gateways.
CodeQL triage
Alert #1171 reports
js/insufficient-password-hashon the unchanged SHA-256 authorization-ID calculation moved inside the queued block. Source inspection and the independent reviewer confirm a false positive: the complete hash input is a namespace, profile ID, canonical database paths, and owner-issued incarnation UUIDs, never credential bytes.authorization-observation.tsobtains incarnations throughreadAuthProfileAuthorizationLifetime;authorization-lifetime.tscreates/rotates them withrandomUUID()and overrides incoming lifetime metadata.auth-controller.tsseparately extracts the API key and profile ID; only the latter reaches capture. Live caller/owner and incarnation/status checks enforce authority independently of the digest.GitHub requires delegated dismissal approval. False-positive dismissal request #74 was submitted and is pending; no scan rule or security check was disabled.
Final CI attribution
Final head
bb71315b1a58ec8356a8173a22fe82b13ccf7d70completed CI run 40506151388. The ratchet, all typechecks/lint, security-fast, and all other selected test jobs passed. The only non-aggregate failure is checks-node-changed-3: the two final HTTP adoption cases insrc/cron/isolated-agent.auth-continuity.integration.test.tsreport successful synthetic responses but observe no loopback requests at line 580.The identical single-file command,
node scripts/run-vitest.mjs src/cron/isolated-agent.auth-continuity.integration.test.ts --maxWorkers=1, reproduces exactly 2 failed, 7 passed on both the final PR head (175.74 seconds) and unchanged CI main parent83274dfe3218ea394900afc3fb7cb91416a3a80c(230.48 seconds). CI checkout821ce829a70774c0349b9f27487fe3b7acefe71dhas those exact main/PR parents. The fixture and transport-host sources are unchanged by this PR. Its fetch spy can be copied into a replacement host during lazy transport initialization, while mock restoration restores the prior object; later HTTP cases then receive the retained synthetic response. This is a separate fixture-isolation failure, not an authorization rejection.Landing uses the maintainer-authorized inherited-CI exception with the failed run retained as failed. No CI rerun was requested. Exact-head security-sensitive and dependency review both passed. CodeQL's separately reviewed false-positive dismissal remains pending as described above; no security rule was disabled.