Skip to content

perf(auth): settle OAuth refresh through workers - #165658

Merged
steipete merged 3 commits into
mainfrom
dbasync/w4oauth
Oct 5, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/w4oauth

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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 authProfiles worker 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.ts shrinks 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 ensureAuthProfileStore exported by provider-auth in 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. Main 11d3d04a1279 is incorporated through merge commit 08f137efa8d0; 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

  • Pre-integration focused OAuth, shutdown, account-owner, indirect CLI/model-generation, SDK compatibility, runtime build graph, worker import closure, reply import closure, and wrapper inventory suites passed with --maxWorkers=1: 2,135.83 s wall. Indirect consumers already use host-owned projects; no routing or wrapper-inventory change is needed.
  • Final pre-integration OAuth/shutdown rerun: 43 tests across six files passed, 304.90 s wall, including zero caller-thread data SQL, replacement during provider preparation, live pin revocation, conflict/unknown outcomes, real lost-result reconciliation, callback mutation isolation, and cancellation. The cancellation regression failed before its guard (389.43 s wall). Separate negative controls reproduced a mutable lost-reply postimage (220.32 s), formatter mutation (103.64 s), and validation/capability/refresh callback corruption (82.01 s); all now pass.
  • Post-integration OAuth, real Gateway close, worker/import-closure, runtime build graph, and wrapper inventory checks passed: 164.31 s wall, --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.
  • Final P2 Codex autoreview: scoped-clean. Typed lint, formatting, line-cap ratchet, core types, and the affected test type graph passed after the final fix. The original changed check also passed all 27 core-test type graphs.
  • Madge: 0 cycles, 245.77 s. Runtime import-cycle guard and database-worker ratchet passed. SDK surface budget passed; API diff reports zero changes, 2,067.82 s. Later refinements remain in the private owner/manager and tests; no public export or signature changed.
  • The integrated check-changed run passed core types and all 27 test type graphs, then stopped after 728.00 s on inherited unused exports: resolvePolicyPluginActivationState in src/plugins/config-policy.ts, and seven default re-exports in src/media-understanding/defaults.ts. Definitions, complete reference sets, and scanner configuration are unchanged from 745efb1629b6. All nine remaining checks were run directly and passed. No skip, ignore, cap, or baseline exception was added.
  • Published-driver update cell passed on AWS Linux using published 2026.9.8: recorded phase 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 377fe52f92fce awaits 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 d5fbbe86a8074 and 8ccf43d1764cf are now included. Released SDK signatures were checked against both v2026.10.1-beta.1 and v2026.9.8; no public signature changed, and the existing zero-change SDK API report remains applicable.

Post-integration tsgo:core passed (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: resolveBrowserOpenCommand in src/commands/onboard-helpers.ts and src/infra/browser-open.ts, and normalizeMediaUnderstandingChatType in src/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 base 11d3d04a1279. The exports have no production consumers outside their own modules and the unused onboarding re-export. Newer main already fixes them in b2750b234605, 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 08f137efa8d0cb448c1777edead9d93b9508b6b7
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/oauth-manager.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/personal-profiles.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/personal-store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store.worker-contract.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/store.worker.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 5:30 PM ET / 21:30 UTC (Revision 4).

ClawSweeper review

What this changes

Move 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
Reviewed head: 08f137efa8d0cb448c1777edead9d93b9508b6b7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker migration with strong boundary evidence, resolved prior findings, and successful exact-head CI.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied after-fix results map the personal OAuth owner to real SQLite worker transport, credential replacement, pin revocation, actual result-frame loss, and production Gateway close. Inspected scenarios verify rejected stale credentials, no unauthorized replacement persistence, exact acknowledged recovery, and settlement before database teardown; provider callbacks are synthetic because the changed contract is local ownership and transport. No stored-data model changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Supplied after-fix results map the personal OAuth owner to real SQLite worker transport, credential replacement, pin revocation, actual result-frame loss, and production Gateway close. Inspected scenarios verify rejected stale credentials, no unauthorized replacement persistence, exact acknowledged recovery, and settlement before database teardown; provider callbacks are synthetic because the changed contract is local ownership and transport. No stored-data model changes are introduced.
Evidence reviewed 10 items Pinned introduction: Reviewed the introduced delta from the pinned merge base to the original PR head, including the personal-store owner, OAuth settlement extraction, worker operations, resolver guards, documentation, and both changed test files.
Still necessary on main: Fetched main still loads the personal OAuth profile synchronously inside its existing resolver; it does not contain this PR’s retained personal-store worker path. The merged prerequisite #165547 explicitly leaves OAuth settlement as separate follow-up work.
Authority and exact settlement: The retained owner rechecks database and callback authority at transaction and commit admission. The worker compares the complete credential-and-usage preimage, verifies the encoded postimage, and publishes a native commit receipt; lost-result recovery accepts only the matching digest and never replays the write.
Findings None None.
Security None None.

How this fits together

OpenClaw’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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +386, Tests +528, Docs +8. Total +922 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 9 628 242 +386
Tests 2 528 0 +528
Docs 1 11 3 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 1167 245 +922

Review metrics

Metric Value Why it matters
Production growth justification production +628/-242, net +386; tests +528 Growth supplies retained worker settlement, exact postimage reconciliation, and authority checks; the new tests exercise distinct transport and lifecycle boundaries.
Caller-thread SQL reported personal OAuth interceptions: 92 → 0 The performance claim is tied to the production refresh owner and checked by the inspected real-worker boundary scenario.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Supplied after-fix results map the personal OAuth owner to real SQLite worker transport, credential replacement, pin revocation, actual result-frame loss, and production Gateway close. Inspected scenarios verify rejected stale credentials, no unauthorized replacement persistence, exact acknowledged recovery, and settlement before database teardown; provider callbacks are synthetic because the changed contract is local ownership and transport. No stored-data model changes are introduced.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded auth-runtime performance and ownership improvement without an established urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Supplied after-fix results map the personal OAuth owner to real SQLite worker transport, credential replacement, pin revocation, actual result-frame loss, and production Gateway close. Inspected scenarios verify rejected stale credentials, no unauthorized replacement persistence, exact acknowledged recovery, and settlement before database teardown; provider callbacks are synthetic because the changed contract is local ownership and transport. No stored-data model changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied after-fix results map the personal OAuth owner to real SQLite worker transport, credential replacement, pin revocation, actual result-frame loss, and production Gateway close. Inspected scenarios verify rejected stale credentials, no unauthorized replacement persistence, exact acknowledged recovery, and settlement before database teardown; provider callbacks are synthetic because the changed contract is local ownership and transport. No stored-data model changes are introduced.

Evidence

What I checked:

  • Pinned introduction: Reviewed the introduced delta from the pinned merge base to the original PR head, including the personal-store owner, OAuth settlement extraction, worker operations, resolver guards, documentation, and both changed test files. (src/agents/auth-profiles/personal-store.ts:73, 08f137efa8d0)
  • Still necessary on main: Fetched main still loads the personal OAuth profile synchronously inside its existing resolver; it does not contain this PR’s retained personal-store worker path. The merged prerequisite perf(models): prepare personal model pin authority through workers #165547 explicitly leaves OAuth settlement as separate follow-up work. (src/agents/auth-profiles/oauth-manager.ts, 0e54386a4634)
  • Authority and exact settlement: The retained owner rechecks database and callback authority at transaction and commit admission. The worker compares the complete credential-and-usage preimage, verifies the encoded postimage, and publishes a native commit receipt; lost-result recovery accepts only the matching digest and never replays the write. (src/agents/auth-profiles/store.worker.ts:54, 08f137efa8d0)
  • Authority boundary proof: The supplied after-fix results report passing real-worker and SQLite boundary cases. Inspected coverage exercises allowed refresh, credential replacement during provider preparation, identity reassignment revoking a retained pin, callback mutation isolation, conflict refusal, and an actual worker result-frame loss. The revoked-pin case rejects resolution and verifies that the replacement credential was not persisted. (src/agents/auth-profiles/oauth-personal.worker.test.ts:196, 08f137efa8d0)
  • Prior finding resolved: The public resolver now awaits either resolution path and checks cancellation before returning. This directly addresses the earlier review’s cancellation finding; personal worker reads also check cancellation before returning an API key. The supplied landing verification records both defects failing before correction and passing afterward. (src/agents/auth-profiles/oauth.ts:370, 08f137efa8d0)
  • Shutdown settlement proof: The inspected production Gateway-close scenario cancels caller observation while keeping the database open, then releases provider completion and verifies the refreshed credential survives database closure. The supplied body records all four close cases passing again after main’s close-sequencing integration. (src/gateway/server-lifecycle.catalog-write.test.ts:312, 08f137efa8d0)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-05T16:15:46.765Z sha 6171f37 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T18:43:59.519Z sha 6171f37 :: needs changes before merge. :: [P2] Recheck cancellation after awaiting the outer resolver result
  • reviewed 2026-10-05T19:23:08.212Z sha 08f137e :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
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.
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 5, 2026
@steipete
steipete merged commit f48c19d into main Oct 5, 2026
148 of 152 checks passed
@steipete
steipete deleted the dbasync/w4oauth branch October 5, 2026 22:02
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant