Repository navigation
perf(auth): settle OAuth refresh through workers - #165658
Conversation
Move personal credential reads, refresh compare-and-swap, and final acceptance through the existing authProfiles worker. Retain physical store ownership and accepted settlement through cancellation and Gateway shutdown, and reconcile only exact acknowledged postimages after lost results. Isolate retained credentials from provider, validator, and updater callbacks. Extract store settlement, rollback, and terminal fencing from oauth-manager. Preserve published SDK signatures and existing storage formats.
|
🦞👀 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: needs maintainer review before merge. Reviewed October 5, 2026, 5:30 PM ET / 21:30 UTC (Revision 4). ClawSweeper reviewWhat this changesMove personal OAuth credential reads, refresh persistence, and final acceptance into the existing database worker while retaining cancellation and shutdown settlement. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still performs personal OAuth settlement synchronously. The previous cancellation finding is resolved, and this review found no remaining actionable defects. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s auth resolver turns a selected personal model account into credentials for a provider request. Its database worker checks the current credential and retained authority before storing or accepting refreshed credentials. flowchart TD
A[Selected personal account] --> B[Auth resolver]
B --> C[Retained database owner]
C --> D[Provider preparation and refresh]
D --> E[Current authority and credential checks]
E --> F[Worker transaction and settlement]
F --> G[Accepted provider credential]
H[Cancellation or shutdown] --> F
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +386, Tests +528, Docs +8. Total +922 across 12 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep personal OAuth settlement with the existing worker owner, preserving exact credential acceptance, live-authority checks, and shutdown custody. Do we have a high-confidence way to reproduce the issue? Not applicable as a new bug report; the prior cancellation regression has a concrete boundary reproduction and is corrected in the reviewed head. This read-only review inspected source and supplied results without executing tests. Is this the best way to solve the issue? Yes. Reusing the existing worker and storage kernel preserves one authoritative owner while moving personal settlement off the Gateway thread. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0e54386a4634. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
Recheck cancellation after awaiting the public credential resolver and keep post-acceptance validation scoped to personal credentials. Shared fallback validation retains its existing callback behavior. Both regressions reproduced five times on the PR and passed five times on the merge base. The repaired cancellation, fallback, and personal worker suites pass all 16 tests without changing assertions.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* perf(auth): settle OAuth refresh through workers Move personal credential reads, refresh compare-and-swap, and final acceptance through the existing authProfiles worker. Retain physical store ownership and accepted settlement through cancellation and Gateway shutdown, and reconcile only exact acknowledged postimages after lost results. Isolate retained credentials from provider, validator, and updater callbacks. Extract store settlement, rollback, and terminal fencing from oauth-manager. Preserve published SDK signatures and existing storage formats. * fix(auth): preserve OAuth cancellation and validation boundaries Recheck cancellation after awaiting the public credential resolver and keep post-acceptance validation scoped to personal credentials. Shared fallback validation retains its existing callback behavior. Both regressions reproduced five times on the PR and passed five times on the merge base. The repaired cancellation, fallback, and personal worker suites pass all 16 tests without changing assertions.
What Problem This Solves
Personal OAuth refresh still performed credential reads and settlement on the Gateway main thread. It also retained shared/agent peer discovery during personal settlement, despite personal credentials having a separate owner.
Why This Change Was Made
Use the existing
authProfilesworker for personal reads, exact credential-and-usage compare-and-swap, and final credential acceptance. Capture the physical store before yielding, retain its actor through provider preparation and settlement, and recheck current authority at transaction/commit. Callback inputs and returned refresh data are copied so providers, validators, and updater drafts cannot mutate the retained generation or the acknowledged postimage. Acceptance returns the owner’s verified credential. A lost result frame can publish only that exact postimage; uncertain writes never replay. Gateway shutdown joins accepted settlement after canceling the caller's observation.Extract store settlement, terminal fencing, and rollback into
oauth-store.ts.oauth-manager.tsshrinks from 1,215 to 1,180 counted lines without changing its cap. The new awaited personal read also checks cancellation before returning an API key; a regression demonstrated the missing check before the fix.User Impact
Personal OAuth refresh drops from 92 → 0 caller-thread data-SQL interceptions (the handoff's intermediate result was 44). Global static T1 measured 861 → 861 on the original reviewed base because native kernels still serve retained synchronous contracts, including
ensureAuthProfileStoreexported byprovider-authin v2026.9.8 and the documented synchronous model-account Gateway SDK methods. Shared/agent refresh fencing and generation behavior remain intact.No schema, credential format, retention, durability, public SDK signature, or environment-name change. Production delta: +628 / −242 / net +386; 870 changed lines across nine production files.
The prerequisite #165547 merged, so this PR targets
main. Main11d3d04a1279is incorporated through merge commit08f137efa8d0; the OAuth production files were unchanged by that integration. Known overlapping work: #152111 and #153046 in the auth store, plus the incidental umbrella #162433. These changes stay within the personal refresh owner.Evidence
--maxWorkers=1: 2,135.83 s wall. Indirect consumers already use host-owned projects; no routing or wrapper-inventory change is needed.--maxWorkers=1, OAuth MAIN data SQL 0. The twelve worker cases took 24.977 s combined test time; all four close cases took 13.838 s (46.33 s shard wall). Real SQLite transport, lost replies, and server close ordering require these boundaries; cold compilation/import and host contention dominate wall time. The final exact-head CI workflow passed in 1,051 s elapsed across all selected checks; isolated per-case CI timing was not collected.check-changedrun passed core types and all 27 test type graphs, then stopped after 728.00 s on inherited unused exports:resolvePolicyPluginActivationStateinsrc/plugins/config-policy.ts, and seven default re-exports insrc/media-understanding/defaults.ts. Definitions, complete reference sets, and scanner configuration are unchanged from745efb1629b6. All nine remaining checks were run directly and passed. No skip, ignore, cap, or baseline exception was added.finished,readyz=200, running version/build identity verified, durable state retained, incognito cleanup verified, and service cleanup passed. The updater command took 387.99 s; package build plus cell took 1,188.68 s (remote end-to-end 1,958.17 s). The AWS lease was confirmed released. Candidate tarball SHA-256:4ab9df31b228e976263ed880598ad5ca71681d30cccfab2dbd72ff9bbdf4f4a5. This proof used the reviewed OAuth tree before the patch-identical rebase; integration checks are recorded separately.Landing verification
CI run 37338704301 exposed a PR-caused cancellation regression: the added public async wrapper could return a fallback credential after cancellation won. A focused sibling check also exposed an extra shared-profile validator callback. Commit
377fe52f92fceawaits the public result and checks cancellation before returning, and scopes the new final validation to personal credentials. Existing test assertions are unchanged.Each defect reproduced in five PR runs and zero of five merge-base runs at
745efb1629b66. Final focused proof passed 16 tests across three files,--maxWorkers=1, 237.092 s wall (Vitest 200.00 s), including zero caller-thread personal OAuth data SQL. Full-candidate P2 review and the corrective-delta P2 review both completed with no actionable findings.The eight unused exports were independently verified as inherited: definitions, complete references, and scanner inputs matched the merge base. Main fixes
d5fbbe86a8074and8ccf43d1764cfare now included. Released SDK signatures were checked against bothv2026.10.1-beta.1andv2026.9.8; no public signature changed, and the existing zero-change SDK API report remains applicable.Post-integration
tsgo:corepassed (29.36 s) and all 27 core-test type graphs passed (711.62 s). Madge passed with zero cycles, 173.16 s wall. Because main changed Gateway close sequencing, the real close suite was rerun on this head: 4/4 tests, 400.711 s wall, including accepted personal OAuth settlement before database closure.The full local changed-check command remains recorded as failed, after 1,682.82 s, on three inherited unused exports:
resolveBrowserOpenCommandinsrc/commands/onboard-helpers.tsandsrc/infra/browser-open.ts, andnormalizeMediaUnderstandingChatTypeinsrc/media-understanding/scope.ts. All 24 preceding checks passed. All nine remaining checks were run directly and passed in 382.64 s; no scanner, assertion, baseline, or cap was weakened. Definitions, all 21 reference lines, and scanner inputs match base11d3d04a1279. The exports have no production consumers outside their own modules and the unused onboarding re-export. Newer main already fixes them inb2750b234605, whose commit records clean-main reproduction and verified repair. This PR does not touch those files, so the normal merge preserves that repair. Native review retains the local failure and attribution; no CI waiver is requested.CI run 37362005724 completed successfully on
08f137efa8d0cb448c1777edead9d93b9508b6b7(1,051 s workflow elapsed). ClawSweeper review completed on that head at 2026-10-05 19:23 UTC, confirmed the prior cancellation finding resolved, and reported no remaining actionable findings. Both P2 autoreviews are clean. No CI rerun or admin exception was used.