Repository navigation
fix(auth): keep OAuth sign-ins through safe refresh failures - #178646
fuller-stack-dev merged 21 commits into
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. |
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
|
Codex review: blocked before merge. What this changesThis PR preserves saved OAuth credentials after narrowly identified transient xAI refresh failures so later requests can retry. Example: The xAI token endpoint returns HTTP 503 while refreshing xai:default.
Review scores
ProductKind: Preference · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open for an auth-owner decision on the proposed replay policy; both prior findings are addressed, and no remaining discrete code defect was identified. Priority: P2 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherThe auth-profile manager claims persisted credentials, invokes the provider refresh hook, and settles owner and peer stores before returning access credentials or a typed failure to agent callers. flowchart TD
A[Agent auth candidate] --> B[OAuth manager]
B --> C[SQLite credential claim]
B --> D[xAI refresh transport]
D --> E[Failure admission]
E --> F[Authority and exact claim checks]
F --> C
B --> G[Access credential or typed failure]
Technical reviewBest possible solution: Retain provider-owned admission and exact-claim restoration only if the auth owner accepts the documented token-replay tradeoff. Do we have a high-confidence way to reproduce the issue? Current-main source terminally fences completed refresh failures, and the supplied real-HTTP comparison demonstrates that behavior for HTTP 503; this review executed no target code. Is this the best way to solve the issue? The implementation uses the existing provider, claim, store, and health owners and preserves invalid-success rejection; whether uncertain refresh-token replay is desirable remains an explicit owner choice. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bd2dbfdeb493. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +200, Tests +370, Docs +14. Total +584 across 16 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 20, 2026, 6:26 PM ET / 22:26 UTC (Revision 2). |
a830546 to
32625d2
Compare
|
Updated for the round-1 review (head
The narrow replay policy is stated for the maintainer decision. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Baseline-Refresh: 91f87f47f1318e4c3388e524c61746a00795ca41
|
/allow-security-sensitive-change |
1 similar comment
|
/allow-security-sensitive-change |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…w#178646) * fix(auth): temporary OAuth refresh failures force repeated sign-in * fix(auth): transient refresh recovery bypasses validation and caller policy * fix(auth): fence transient refresh recovery by current owner * test(auth): prove scoped refresh failure sharing * fix(auth): share evidence-based OAuth refresh recovery * fix(auth): close OAuth refresh-recovery review gaps - Vertex ADC: drop the external durable claim; recover via the shared outcome. - Microsoft Teams: reusable delegated claims keep the original grant; terminal rejection erases recovery material; publication failure retries safely. - Google Meet, Twitch, MCP: preserve completed exchanges and reconcile exact committed claims instead of stranding or replaying rotating grants. - xAI: bounded retries only for a verified Cloudflare challenge; transport and pre-header failures stay uncertain. - GitHub: classify personal preparation failures as before-dispatch; fold the refresh-boundary suite into the lifecycle helper root; scheduling test waits for the dispatched refresh after the pre-dispatch claim write. - Anthropic: safe local refresh diagnostics. - Document operator reconnect after a rotating-grant crash. * fix(xai): keep sign-in after plain 429/5xx refresh responses xAI token responses with HTTP 429 or 5xx and no OAuth error field now report an owner-accepted provider retry, so the stored sign-in is restored and refreshed later. Structured OAuth errors, lost or unreadable responses, and invalid success bodies stay fenced. * fix(xai): keep sign-in after transient OAuth errors on 429/5xx xAI 429/5xx token responses with transient or unrecognized OAuth error codes now keep the stored sign-in for a later refresh. Final OAuth errors stay terminal at any status. * fix(auth): keep Google and Microsoft grants through unreadable refresh responses Meet and Teams classify an HTML or unreadable 5xx/429 refresh body by status with documented reusable-grant evidence, and an unreadable success body like a lost response. The xAI SDK boundary test now expects a kept sign-in after an HTML 503. Fold the three new auth-storage OAuth test roots into one to keep the agents-sessions type shard at 720. Docs describe per-owner recovery, Twitch reauthorization and the provider-owner decision behind owner-accepted-provider-retry. * docs(auth): scope final OAuth reasons and Vertex recovery wording * refactor(x): drop retired client-wide OAuth signal Main removed the unused client-wide signal from createXApiClient; the token exchange keeps its own 30 second deadline and callers still cancel observation. * fix(auth): align OAuth refresh correction with current main Use main's positional Twitch token resolver, keep Teams claim parsing within its assertion budget, reuse main's OAuth manager test helper, and give the caller-policy test typed reusable-grant evidence instead of the retired retryable boolean. * fix(auth): keep MCP sign-in and lease aborts working with refresh fences - start interactive MCP authorization after a failed refresh while the dispatched claim stays fenced; align forced-effects expectations - forward caller aborts to MCP OAuth lease waiting only; detach after admission - cover Codex flow-owner refresh context and fail-closed facade branch - break the X api/oauth type cycle, keep the Vertex test on public helpers, add the shared outcome module to the PR wrapper inventory, and annotate the Meet grant fingerprint for CodeQL * chore(google-meet): drop ineffective CodeQL suppression comment * fix(mcp): start a new sign-in when a refresh claim fences fresh tokens * fix(mcp): let Gateway sign-in prepare authorization past a fenced refresh claim * fix(mcp): keep reporting this sign-in's own failed refresh --------- Co-authored-by: Stronggenetics <[email protected]> Co-authored-by: Jason (Json) <[email protected]>
Related: #89278 (OAuth timeout symptoms, not a claim to fix its older Codex timeout path).
Builds on @Stronggenetics's original transient-refresh fix; maintainer corrections replace status-only retry admission with provider-owned evidence.
What Problem This Solves
A temporary OAuth refresh failure could permanently fence an OpenClaw-owned sign-in and force re-login, and concurrent callers could each repeat the same failing refresh. On main, an xAI token-endpoint 429/5xx was terminal.
User Impact
Fewer forced re-logins for xAI, Google and Microsoft integrations and for failures before dispatch; no replay of possibly consumed rotating grants elsewhere. No config or database schema change; stored OAuth credential JSON records gain optional refresh-claim fields.
Why This Change Was Made
Refresh routes report a typed, credential-free outcome (
src/shared/oauth-refresh-outcome.ts, additive exports inopenclaw/plugin-sdk/provider-oauth-runtime). The credential owner restores the exact claimed credential for a later retry only with positive evidence:authorized_userADC) and Microsoft (Teams delegated): transport loss, an unreadable or HTML response, and 429/5xx keep the sign-in;invalid_grant,invalid_client,invalid_request,access_denied, …); a verified Cloudflarecf-mitigated: challengeis retried up to 3 times.Other owners (OpenAI, Anthropic, GitHub, X, MCP, Chutes, MiniMax, Radius, Twitch) rotate grants or don't document reuse, so a lost response or post-dispatch 429/5xx stays fenced and asks for reconnect; definitive rejections stay terminal everywhere. Twitch documents that one refresh token can back many access tokens, but not reuse after a lost rotation, so a Twitch 429/5xx or lost response still requires reauthorizing the bot. Queued callers share one settled failure instead of replaying it. Rotated results are persisted before use (X, GitHub, Twitch), and Vertex never rewrites gcloud's ADC file.
owner-accepted-provider-retryis an SDK evidence kind for an explicit provider-owner decision; the classifier cannot verify it, and docs say so.Excluded: Gemini CLI and other tool-owned CLI homes, setup tokens, static API keys.
Evidence
Exact candidate tree
f354ff361c812e14e3289b5a6959aa5509e23727(correction integrated with maind175030f056), verified in isolated, secretless AWS Crabbox guests with synthetic credentials only:Regression tests for each correction (several first shown failing on the prior head): transient xAI 429/5xx (structured and HTML), Google Meet and Microsoft Teams HTML/unreadable 5xx, queued-caller sharing, merged personal-owner disconnect, authority capture before claim persistence.
Focused suites (102 files, 1,737 tests; one inherited main failure in
doctor-lint.state-isolationfrom fix: updates tolerate missing legacy OAuth directories #180174's advisory OAuth-dir change, untouched by this PR) across the auth-profile manager/queue/classifier, GitHub personal OAuth lifecycle/publication, SDKAuthStorageboundary (139 cases), Vertex, Meet, Teams, Twitch, xAI, X, MiniMax and auth-controller consumers, plus every MCP OAuth consumer (Gatewaymcp.authLoginforced effects, CLI login, doctor lint state isolation); import-cycle, extension-boundary and line-cap guards; core and extension types and test types, lint, format, docs, assertion-safety and test-mock-export ratchets,git diff --check, andpnpm build.Main conflicts resolved semantically: Meet keeps its refresh helpers shared with the plugin owner; X keeps the OAuth owner without main's retired client-wide signal; MCP redirect and refresh-queue tests keep the uncertain-outcome assertions on main's fixtures; test path lists and the assertion baseline take both sides; GitHub personal OAuth keeps main's pending-write tracker with the typed refresh outcomes, and the worker test list drops the enterprise MCP tests main reverted.
Hosted CI fixes on the previous head: interactive MCP sign-in now starts authorization after a failed refresh (the possibly consumed grant stays fenced until the new code exchange replaces it); a caller abort while waiting for the MCP OAuth lease keeps its informational lease outcome; Codex refresh tests cover the full credential context and the flow-owner fail-closed path; X type cycle, Vertex test helper import and PR wrapper inventory.
Latest correction: Control UI MCP sign-in no longer reports success while an earlier lost forced refresh leaves a fenced claim beside locally fresh tokens; it starts a new authorization, and the code exchange clears the claim (Gateway
mcp.authLoginregression shown failing on the prior head). A sign-in's own failed refresh still reports as before. Added a direct test for cancelling a caller while another holds the MCP OAuth lease. The Meet grant lineage hash keeps its deterministic SHA-256 (persisted, must survive restarts; not password storage) and its ineffective inline CodeQL comment is removed. Integrating main picks up fix: terminal lifecycle tests fail during module loading #180156, which fixes the inheritedagent-lifecycle-terminaltest failure from main.Not covered: live provider refresh against real accounts. Exact-head CI runs on this PR.