Skip to content

refactor(gateway): move Web Push preferences to SQLite workers - #163355

Merged
steipete merged 8 commits into
mainfrom
dbasync/pushprefs
Oct 2, 2026
Merged

steipete merged 8 commits into
mainfrom
dbasync/pushprefs

Conversation

@steipete

@steipete steipete commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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 pushprefs cutover, 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:

File Tier Before After
src/gateway/server-methods/push.ts No direct counted primitive 0 0
src/infra/push-web-store.ts No direct counted primitive 0 0
src/state/user-preferences.ts T1 → no counted primitive 1 0
src/state/user-preferences.store.ts T1 9 9
src/state/user-preferences.worker.ts W 1 1

The 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 in 55c9f526bfee484dfe949fb4008987b7bf4d89de: 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 using node 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 commits 6dc7fcc6fdeb12303f5a9b8db18a22c9a6c09b35, 00366e5a2261322f1d5d964ac8085daf35eb548f, and 47c4ff8ae60134ac875db33835e1377323061059, 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 d507b68d43932f8746dbae4c4fca234db143174f was merged without production conflicts; its authority-test deduplication was preserved.

  • node scripts/worktree-setup.mjs gateway — passed after serializing build inputs; pnpm install --frozen-lockfile reconciled 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.
  • After integration: node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo and node scripts/run-tsgo-core-test-shards.mjs --ci-graphs-json '["core-test-gateway-methods"]' — passed. The Gateway graph and scoped node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/gateway/server-methods/push-authority-router.test.ts passed 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.
  • Codex autoreview of the merged branch against 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.

Test file Passed Wall seconds
src/gateway/server-methods/push-preferences.worker.test.ts 1 1137.89
src/gateway/server-methods/push-authority.test.ts 23 212.08
src/gateway/server-methods/push.test.ts 25 210.39
src/gateway/server-methods/push-authority-router.test.ts 5 133.40
src/gateway/server-methods/push-authority-in-process.test.ts 3 182.39
src/state/user-preferences.test.ts 12 116.92
src/state/user-profiles.test.ts 23 30.08
src/state/user-profiles-multi-account.test.ts 6 34.21
src/agents/git-coauthor-attribution.test.ts 9 108.42
src/gateway/github-publication-attribution.test.ts 11 271.46
src/gateway/github-user-identity.oidc.test.ts 31 129.79
src/gateway/server-methods.users-merge.test.ts 5 144.69
src/gateway/server-methods/themes.test.ts 33 163.13

The 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-runtime rebuild was rejected before running tests; setup and tests were subsequently serialized.

Compatibility retained

Removed production exports: getUserPreferences and setUserPreferences. 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 in user-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

These are different goals; none implements this preference-worker cutover.

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

clawsweeper Bot commented Oct 2, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 2, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 4:50 AM ET / 08:50 UTC (Revision 7).

ClawSweeper review

What this changes

Moves 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
Reviewed head: 47c4ff8ae60134ac875db33835e1377323061059

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused worker cutover with meaningful boundary coverage and no remaining actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state classifies this as maintainer-authored, so ordinary external-contributor proof is exempt. The inspected production-handler/real-SQLite-worker harness supports thread placement and ordering; mocked revocation tests are supplemental. No stored-data contract changes or unresolved authority-chain violation were identified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state classifies this as maintainer-authored, so ordinary external-contributor proof is exempt. The inspected production-handler/real-SQLite-worker harness supports thread placement and ordering; mocked revocation tests are supplemental. No stored-data contract changes or unresolved authority-chain violation were identified.
Evidence reviewed 9 items Pinned introduced change: Reviewed the pinned base-to-head production, test, fixture, and documentation changes. The stale GitHub test merge was not used to infer removal of current-main behavior.
Current-main necessity: Fetched main still calls the synchronous preference facade in the browser settings handlers; existing workers have not yet replaced this caller.
Latest-release check: The v2026.9.7 source imports and calls getUserPreferences and setUserPreferences, confirming this caller cutover is not already shipped.
Findings None None.
Security None None.

How this fits together

Browser 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -4, Tests +350, Docs +3. Total +349 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 3 136 140 -4
Tests 15 401 51 +350
Docs 1 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 543 194 +349

Review metrics

None.

Technical review

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This bounded Gateway worker cutover improves runtime execution discipline without an identified urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state classifies this as maintainer-authored, so ordinary external-contributor proof is exempt. The inspected production-handler/real-SQLite-worker harness supports thread placement and ordering; mocked revocation tests are supplemental. No stored-data contract changes or unresolved authority-chain violation were identified.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the pinned base-to-head production, test, fixture, and documentation changes. The stale GitHub test merge was not used to infer removal of current-main behavior. (src/gateway/server-methods/push.ts:150, 47c4ff8ae601)
  • Current-main necessity: Fetched main still calls the synchronous preference facade in the browser settings handlers; existing workers have not yet replaced this caller. (src/gateway/server-methods/push.ts:378, 2a390ec08773)
  • Latest-release check: The v2026.9.7 source imports and calls getUserPreferences and setUserPreferences, confirming this caller cutover is not already shipped. (src/gateway/server-methods/push.ts:47, c074824a27c9)
  • Authority and ordering: The handler prepares canonical profile authority, rechecks it after awaits, and supplies the same current-authority guard to the existing worker's transaction and commit admissions. The subscription snapshot owner awaits preparation before releasing its FIFO lease; device mutations retain deferred start. (src/state/user-preferences.ts:93, 47c4ff8ae601)
  • Boundary validation: The added harness invokes the production settings handlers and real SQLite workers, verifies save, targeted publication, readback, and queued binding ordering, and probes caller-thread SQL preparations. The captured body reports a 44-preparation negative control and zero after the cutover; five push suites passed 57 tests in 120.10 seconds. These are contributor-reported results, not reviewer execution. (src/gateway/server-methods/push-preferences.worker.test.ts:22, 47c4ff8ae601)
  • Existing-state compatibility: The preference storage kernel, worker commands, schema, serialization, and broker have no introduced changes. Removed synchronous exports have only fixture callers after the cutover and no plugin-SDK references; no stored-data migration is introduced. (src/state/user-preferences.store.ts:151, 47c4ff8ae601)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Takhoffman: 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 (6 earlier review cycles)
  • reviewed 2026-10-02T07:23:36.510Z sha 18c5023 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T07:34:03.167Z sha 18c5023 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T07:45:10.450Z sha 6dc7fcc :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T08:03:56.789Z sha 6dc7fcc :: needs changes before merge. :: [P3] Update the storage guide after retiring the preference facade
  • reviewed 2026-10-02T08:21:26.097Z sha 00366e5 :: needs changes before merge. :: [P3] Update the storage guide after retiring the preference facade
  • reviewed 2026-10-02T08:37:23.557Z sha 55c9f52 :: needs maintainer review before merge. :: none

@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 2, 2026
@steipete

steipete commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 2a85384 into main Oct 2, 2026
127 checks passed
@steipete
steipete deleted the dbasync/pushprefs branch October 2, 2026 09:00
@steipete

steipete commented Oct 2, 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 3, 2026
…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
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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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