Repository navigation
refactor(gateway): move Web Push preferences to SQLite workers - #163355
Conversation
Move notification preference reads and writes off the Gateway thread through the existing canonical preference worker APIs. Retain subscription binding custody through completion and use prepared profile authority at admission, commit, response, and publication. Schema, stored preferences, and update behavior are unchanged.
The Web Push settings cutover removes the last production consumers. Keep native fixture seeding and readback in test support while retaining the existing preference kernel and historical released-checkout fixture generator.
|
🦞👀 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 2, 2026, 4:50 AM ET / 08:50 UTC (Revision 7). ClawSweeper reviewWhat this changesMoves browser notification preference reads and writes to existing SQLite workers while preserving subscription ordering, and relocates synchronous fixture helpers into test support. Merge readiness✅ Ready for maintainer review Keep open: current main and the latest release still use synchronous Web Push preference access. The prior documentation finding is resolved, and no introduced blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherBrowser notification settings enter the Gateway as authenticated requests tied to a device subscription and user profile. The Gateway stores preferences and publishes changes to the user's connected clients. flowchart TD
A[Browser notification settings] --> B[Gateway request authority]
B --> C[Subscription snapshot lease]
C --> D[Current profile checks]
D --> E[SQLite preference workers]
E --> F[Guarded completion]
F --> G[Settings response and change event]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -4, Tests +350, Docs +3. Total +349 across 19 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep one canonical preference-worker path with live authority checks and FIFO subscription custody through completion. Do we have a high-confidence way to reproduce the issue? Not applicable as a behavior-preserving refactor; current-main source confirms synchronous access, and the supplied negative-control harness targets that execution boundary. No tests were run during this read-only review. Is this the best way to solve the issue? Yes: using the existing preference workers and subscription lease is a focused cutover that avoids another storage owner or compatibility facade. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2a390ec08773. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…law#163355) * refactor(gateway): await web push preference workers Move notification preference reads and writes off the Gateway thread through the existing canonical preference worker APIs. Retain subscription binding custody through completion and use prepared profile authority at admission, commit, response, and publication. Schema, stored preferences, and update behavior are unchanged. * refactor(state): retire synchronous preference host exports The Web Push settings cutover removes the last production consumers. Keep native fixture seeding and readback in test support while retaining the existing preference kernel and historical released-checkout fixture generator. * test(gateway): prepare push routing before timed cases * docs(storage): describe completed web push preference cutover
What Problem This Solves
Web Push user settings still read and write preferences synchronously on the Gateway thread. Simply awaiting the existing worker APIs would release subscription custody before the operation finished, allowing binding changes to overtake it.
Maintainer-requested wave 11
pushprefscutover, limited to the fixed settings flow.Why This Change Was Made
Use the existing canonical preference worker APIs. Keep preference operations inside the existing subscription snapshot preparation interval; device mutations still start after preparation so they can acquire the same FIFO lease. Prepare profile selection authority before awaiting preferences, recheck it at write admission, commit, and completion, and use the prepared profile catalog for postcommit recipient selection. Remove the now-unused synchronous preference host exports and move their fixture-only uses to test support. The preference kernel, worker operations, and broker are unchanged; no new cache is introduced.
User Impact
Notification settings and stored values retain their existing behavior. The real handler test observes 44 caller-thread SQLite preparations on the pinned original handler and zero after this cutover, including preference save, broadcast, and readback. It also verifies that a queued binding mutation cannot overtake the preference operation. This is execution-boundary proof, not a latency benchmark.
Inventory counts from
node scripts/database-worker-inventory.mjs --json, filtered to the affected caller and preference owner:src/gateway/server-methods/push.tssrc/infra/push-web-store.tssrc/state/user-preferences.tssrc/state/user-preferences.store.tssrc/state/user-preferences.worker.tsThe four synchronous preference sites reachable from the fixed settings flow are no longer reached on the caller thread. Raw T1 drops 10 → 9 by deleting the obsolete host transaction wrapper. The nine shared kernel sites remain in place; no inventory classifications or generated inventory were changed.
Production LOC for this lane: +136 / −140 / net −4, measured with
git diff --numstat 212a6b81d58d01624e787b097db01bb6bb5ef58c...HEAD -- src/gateway/server-methods/push.ts src/infra/push-web-store.ts src/state/user-preferences.ts. Changes inherited by merging main are not attributed to this lane.Evidence
Landing verification at
47c4ff8ae60134ac875db33835e1377323061059: independent Codex autoreview through P2 was scoped-clean on the full introduced code diff and on the documentation correction. ClawSweeper completed review of this exact head at 08:50 UTC with no actionable findings. Its prior P3 finding was fixed in55c9f526bfee484dfe949fb4008987b7bf4d89de: the storage guide now describes the completed worker cutover. The introduced diff remains byte-identical after conflict-free main integration. All five push suites passed on the corrected working tree before the final main integration: 57 tests, 120.10 seconds wall usingnode scripts/run-vitest.mjs <five push test files> --maxWorkers=1; formatting, targeted lint, and whitespace checks also passed. Earlier CI failures were independently reproduced on main, including worker-placement lint, an import cycle, duplicate logger keys, and missing normalization exports in the Windows declaration fixture. Existing main repairs were incorporated in merge commits6dc7fcc6fdeb12303f5a9b8db18a22c9a6c09b35,00366e5a2261322f1d5d964ac8085daf35eb548f, and47c4ff8ae60134ac875db33835e1377323061059, without changing the reviewed pushprefs implementation. Exact-head CI run 36985763247 supplies the integration result; native landing retains GitHub's enforced CI gate.All required local checks passed. Main
d507b68d43932f8746dbae4c4fca234db143174fwas merged without production conflicts; its authority-test deduplication was preserved.node scripts/worktree-setup.mjs gateway— passed after serializing build inputs;pnpm install --frozen-lockfilereconciled the merged main dependency pin.node scripts/check-changed.mjs --base 212a6b81d58d01624e787b097db01bb6bb5ef58c— passed on the completed lane before main integration: production types, all 27 core-test graphs, lint, zero unused exports, and all guards. No lane production change followed that run.node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfoandnode scripts/run-tsgo-core-test-shards.mjs --ci-graphs-json '["core-test-gateway-methods"]'— passed. The Gateway graph and scopednode scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/gateway/server-methods/push-authority-router.test.tspassed again after the fixture repair below.pnpm check:database-worker-ratchet --base 212a6b81d58d01624e787b097db01bb6bb5ef58c— passed after integration.pnpm check:madge-import-cycles— zero cycles after integration and again after the final test-import repair.git diff --check— passed.d507b68d43932f8746dbae4c4fca234db143174f, followed by review including the final fixture repair — scoped-clean at the requested P0 threshold.Each row used
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 /usr/bin/time -p pnpm test <file> --maxWorkers=1. All 187 tests across 13 files passed. Wall times include wrapper, imports, worker compilation, and artifact verification on the heavily loaded Mac. The five push files were rerun after main integration; other rows verify the fixture relocation before integration.src/gateway/server-methods/push-preferences.worker.test.tssrc/gateway/server-methods/push-authority.test.tssrc/gateway/server-methods/push.test.tssrc/gateway/server-methods/push-authority-router.test.tssrc/gateway/server-methods/push-authority-in-process.test.tssrc/state/user-preferences.test.tssrc/state/user-profiles.test.tssrc/state/user-profiles-multi-account.test.tssrc/agents/git-coauthor-attribution.test.tssrc/gateway/github-publication-attribution.test.tssrc/gateway/github-user-identity.oidc.test.tssrc/gateway/server-methods.users-merge.test.tssrc/gateway/server-methods/themes.test.tsThe new real-worker test took 2.87 s of test execution before integration and 25.58 s on the overloaded post-integration run; real storage and the caller-thread probe are required to prove this boundary. The added delayed-operation cases use deferred promises, without sleeps or polling. The existing OIDC, user-merge, and theme suites took 99.73 s, 43.13 s, and 56.36 s of test execution respectively; only their fixture imports changed. Their real sign-in/profile binding, RPC merge, and concurrent theme/preference storage contracts cannot be replaced with fixture-only assertions. No test cases, boots, timers, retries, or timeouts were added to those suites. CI timing is not available at PR creation.
The first post-integration router run timed out during the first case's lazy dispatcher import, then its late continuation reached the next case's mock (two persistence calls). The fixture now loads that runtime at collection and closes its owned device authority on test completion. The same five cases passed without increasing timeouts, retries, or weakening assertions.
The negative-control run failed on the pinned original handler at the no-caller-thread-SQL assertion, recording 44 preparations. Initial new-fixture mistakes (an invalid preference value, an import, and an optional connection ID type) were corrected. A compiler run that overlapped setup's
dist-runtimerebuild was rejected before running tests; setup and tests were subsequently serialized.Compatibility retained
Removed production exports:
getUserPreferencesandsetUserPreferences. They had no production consumers after the callback cutover, no public plugin-SDK export, and no documented external contract. Native fixture seeding/readback now lives inuser-preferences.test-support.ts; existing limits, conflict, rollback, merge, and identity tests still exercise the unchanged storage kernel. The released-state fixture generator deliberately imports an older checkout's API and remains unchanged.The endpoint snapshot callback now accepts asynchronous preparation, matching the existing scope owner and sibling adapter. The native Web Push mutation path for opaque synchronous SDK guards (documented since v2026.9.4) remains unchanged. No runtime synchronous preference facade or compatibility alias is retained.
Update behavior
No schema, state shape, stored preference bytes, retention, durability, configuration, or permission change. No migration or updater/Doctor change is needed.
Overlapping open PRs
push.web.preferences.getand its tests; this cutover retains the existing response shape.hasValidWebPushQuietHoursTimeZone; that helper is unchanged here.push-web-store.ts; its diff does not rewrite the endpoint snapshot adapter changed here.These are different goals; none implements this preference-worker cutover.