Skip to content

refactor(push-web): move web push store to shared SQLite state DB - #103294

Merged
steipete merged 5 commits into
openclaw:mainfrom
xydt-tanshanshan:refactor/push-web-sqlite
Jul 15, 2026
Merged

steipete merged 5 commits into
openclaw:mainfrom
xydt-tanshanshan:refactor/push-web-sqlite

Conversation

@xydt-tanshanshan

@xydt-tanshanshan xydt-tanshanshan commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #108399

What Problem This Solves

Web Push subscriptions and the generated VAPID signing identity still lived in whole-store JSON files. Concurrent Gateway processes could lose registrations or create competing identities, and upgrades had no verified path into the canonical shared database.

Why This Change Was Made

This rewrites the contributor PR around typed shared-SQLite rows and synchronous row-level transactions. Explicit openclaw doctor --fix repair now takes exclusive state ownership, validates and claims both retired files before one atomic import, verifies the committed rows, and removes only verified claims. Runtime has no JSON fallback and fails closed for registration, delivery, deletion, and key resolution while a retired source or interrupted Doctor claim remains.

Thanks @xydt-tanshanshan for the original SQLite migration direction and implementation work.

User Impact

Web Push registrations and VAPID identity now survive concurrent updates without whole-file lost writes. Existing JSON state is preserved through an explicit, retry-safe Doctor migration; operators must stop the Gateway before the upgrade repair. Expired-subscription cleanup remains best-effort so a cleanup failure cannot make callers retry notifications that were already delivered.

Release-note context: Web Push state now uses shared SQLite. On upgrades with retired push/vapid-keys.json or push/web-push-subscriptions.json, stop the Gateway and run openclaw doctor --fix before using Web Push.

Evidence

  • Focused runtime, Doctor, and migration suites: 82 tests passed on final rebased head.
  • Database-first legacy-store guard: passed.
  • Guard regression suite: 475 tests passed.
  • Whole-branch autoreview after compatibility, writer-fencing, retry, filesystem-confinement, and runtime-gate fixes: no accepted/actionable findings. The final export-visibility delta was separately reviewed clean; the final rebase was range-diff identical.
  • Patch-identical pre-rebase Testbox changed gate: passed (run).
  • Patch-identical pre-rebase Testbox production build: passed (run).
  • Exact-head hosted CI after rebasing onto the current main: passed (run).

Regression coverage includes concurrent registration and first-use key generation, compare-and-delete expiry races, pending-legacy runtime gates, cleanup failure and retry, missing/empty legacy VAPID subjects, malformed/conflicting stores, symlink and path-race confinement, source claiming and restoration, interrupted claims, and live-Gateway exclusion.

@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 14, 2026, 12:01 PM ET / 16:01 UTC.

Summary
The PR moves Web Push subscriptions and VAPID keys from legacy JSON files into the shared SQLite state database, adds startup migration and archival, and updates focused tests.

PR surface: Source +302, Tests +169. Total +471 across 6 files.

Reproducibility: yes. at source level: two concurrent subscription mutations can load the same snapshot and replace each other, and two first-use VAPID callers can generate different pairs before either persistence result is authoritative. No live concurrent-race transcript was provided.

Review metrics: 1 noteworthy metric.

  • Persisted Store Migration: 2 JSON stores moved to 2 SQLite tables. Both subscription continuity and VAPID identity must survive upgrade and archival, so this is a compatibility-sensitive data-model change rather than a behavior-neutral refactor.

Stored data model
Persistent data-model change detected: migration/backfill/repair: src/gateway/server-startup-plugins.ts, migration/backfill/repair: src/infra/push-web-migration.test.ts, migration/backfill/repair: src/infra/push-web-migration.ts, migration/backfill/repair: src/infra/push-web.test.ts, serialized state: src/infra/push-web-migration.test.ts, serialized state: src/infra/push-web-migration.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦐 gold shrimp
Patch quality: 🦪 silver shellfish
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Replace whole-table snapshot mutations and first-use VAPID persistence with atomic transactional operations.
  • [P1] Obtain the maintainer migration-owner and fail-closed startup decision.
  • Provide redacted exact-head gateway upgrade proof for valid and corrupt legacy stores.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The exact-head terminal transcript proves real SQLite migration and CRUD through production modules, but it bypasses actual gateway startup and therefore does not prove the upgrade, fail-closed outage, or recovery path; add a redacted gateway transcript or recording, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] Concurrent registration, removal, or expired-subscription cleanup can replace the complete table from a stale snapshot, dropping a newer subscription or restoring a removed endpoint.
  • [P1] Concurrent first-use VAPID resolution can return one generated public key while another key pair wins persistence, breaking later delivery to browsers registered with the losing identity.
  • [P0] A malformed legacy Web Push file now aborts gateway startup; operators need an explicitly approved upgrade and recovery contract rather than discovering the change through an outage.
  • [P1] The open Web Push concurrency PR at fix: prevent Web Push broadcasts from spiking outbound requests #103607 changes the same runtime and will require conflict resolution that preserves its bounded fan-out and compare-before-clear invariants.
  • [P1] The posted transcript does not prove that an actual gateway upgrade imports state successfully or surfaces the intended startup failure and recovery instructions.

Maintainer options:

  1. Atomicize and Use Doctor Migration (recommended)
    Replace snapshot persistence with row-level transactions, add atomic VAPID get-or-create, and route legacy import through the doctor-owned repair path before merge.
  2. Accept a Startup-Migration Exception
    A maintainer may explicitly own fail-closed gateway startup after atomicity fixes, documented recovery behavior, and exact-head gateway upgrade proof.
  3. Pause This Migration
    Close or defer the PR if the availability and migration-owner tradeoff is not worth introducing for the current Web Push surface.

Next step before merge

  • [P1] A maintainer must choose the migration and fail-closed upgrade contract before the contributor or an automated repair lane can safely finalize the atomicity changes.

Maintainer decision needed

  • Question: Should legacy Web Push JSON import be owned by openclaw doctor --fix, or may gateway startup automatically import it and fail closed on malformed files?
  • Rationale: Repository policy assigns persistent legacy-state migration to one doctor-owned path, while the recently merged device-pairing migration provides a conflicting startup-import precedent; the resulting gateway availability and operator-recovery contract requires maintainer intent.
  • Likely owner: steipete — The adjacent device-pairing SQLite migration is the closest merged precedent for this gateway startup and shared-state decision.
  • Options:
    • Use Doctor-Owned Migration (recommended): Move import, verification, and archival into the doctor repair path, keep runtime SQLite-only, and provide an actionable startup diagnostic until repair succeeds.
    • Approve Startup Fail-Closed: Keep startup import as an explicit exception, document the outage and recovery contract, and provide real gateway upgrade proof for valid and corrupt legacy stores.
    • Pause the Storage Swap: Leave the JSON runtime unchanged until a shared, maintainer-approved persistent-state migration framework is available.

Security
Cleared: The diff adds no dependency, workflow, permission, secret-exposure, or third-party execution change, and no concrete security regression was identified.

Review findings

  • [P1] Make subscription mutations atomic — src/infra/push-web-store.ts:3
  • [P1] Arbitrate first-use VAPID creation atomically — src/infra/push-web-store.ts:122
Review details

Best possible solution:

Use row-level transactional subscription mutations and an atomic insert-or-read VAPID helper, settle whether legacy import is doctor-owned or an explicitly approved startup exception, then demonstrate both fresh and upgrade behavior through an exact-head gateway run.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: two concurrent subscription mutations can load the same snapshot and replace each other, and two first-use VAPID callers can generate different pairs before either persistence result is authoritative. No live concurrent-race transcript was provided.

Is this the best way to solve the issue?

No. Moving the state to SQLite is appropriate, but the maintainable solution needs row-level transactional mutations, atomic VAPID creation, and an explicitly approved migration owner rather than whole-table snapshot replacement plus an undecided startup failure contract.

Full review comments:

  • [P1] Make subscription mutations atomic — src/infra/push-web-store.ts:3
    The new store assumes an async lock, but this PR removes that lock and persists the entire subscription table from a snapshot loaded before the transaction. Concurrent register, clear, or expired-cleanup operations can therefore overwrite each other, dropping a valid subscription or restoring a removed endpoint; use row-level insert/update/delete helpers or reread and validate authoritative rows inside one synchronous transaction.
    Confidence: 0.99
  • [P1] Arbitrate first-use VAPID creation atomically — src/infra/push-web-store.ts:122
    Separate load, generate, and persist steps allow concurrent first-use callers to return different key pairs, with the last writer changing the stored VAPID identity after another public key has already been handed to a browser. Add a transactional insert-if-absent followed by an authoritative reread and return that canonical row.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8251976cf6c7.

Label changes

Label justifications:

  • P2: This is a valuable but non-emergency storage improvement with bounded Web Push impact and clear pre-merge blockers.
  • merge-risk: 🚨 compatibility: The PR changes two shipped persisted-state locations and introduces legacy import, archival, and corrupt-file upgrade behavior.
  • merge-risk: 🚨 message-delivery: Stale snapshot replacement or VAPID identity races can remove valid subscriptions or make existing browser registrations unusable.
  • merge-risk: 🚨 availability: Malformed legacy JSON intentionally aborts gateway startup and requires manual operator recovery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The exact-head terminal transcript proves real SQLite migration and CRUD through production modules, but it bypasses actual gateway startup and therefore does not prove the upgrade, fail-closed outage, or recovery path; add a redacted gateway transcript or recording, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +302, Tests +169. Total +471 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 383 81 +302
Tests 2 180 11 +169
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 563 92 +471

What I checked:

  • Subscription writes remain non-atomic: The new store describes subscription mutations as protected by an async lock, but the PR removes that lock from the domain module and persists whole-table snapshots, allowing concurrent read-modify-write operations to overwrite one another. (src/infra/push-web-store.ts:3, 713004b4d382)
  • VAPID creation lacks create-if-absent arbitration: The storage API provides load and persist operations but no atomic get-or-create operation, so concurrent first-use callers can generate different key pairs and return a key pair that is immediately replaced in SQLite. (src/infra/push-web-store.ts:122, 713004b4d382)
  • Migration can block gateway startup: Gateway bootstrap runs the Web Push migration as a startup task and deliberately propagates malformed or unreadable legacy-file failures, changing an existing upgrade into a process-availability failure requiring operator action. (src/gateway/server-startup-plugins.ts:105, 713004b4d382)
  • Exact-head proof bypasses gateway startup: The PR body provides an exact-head Linux transcript with real SQLite I/O for migration and CRUD, but directly imports the modules rather than starting the gateway and observing successful and corrupt-file upgrade behavior through the production startup boundary. (713004b4d382)
  • Adjacent migration precedent: The merged device-pairing migration established a closely related shared-state SQLite pattern, but its startup-migration precedent must be reconciled with the repository policy assigning persistent legacy-state migration and repair to a single doctor-owned path. (src/gateway/server-startup-plugins.ts:85, e6a8feb9c256)
  • Prior blockers remain acknowledged: The latest PR description explicitly notes that concurrent subscription atomicity remains a separate P1 concern; the final commit restores VAPID generation fallback but does not establish atomic first-use ownership. (src/infra/push-web.ts:1, 713004b4d382)

Likely related people:

  • steipete: The merged device-pairing SQLite migration changed the same gateway startup boundary and shared state database, making this the strongest available history signal for the migration-owner and upgrade-contract decision. (role: introduced adjacent storage migration precedent; confidence: medium; commits: e6a8feb9c256; files: src/gateway/server-startup-plugins.ts, src/infra/device-pairing-migration.ts, src/infra/device-pairing-store.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-10T12:52:52.378Z sha 4284b03caed0aea81a9c4b698321d1c64201e073 :: needs real behavior proof before merge. :: [P1] Move legacy import out of runtime reads
  • reviewed 2026-07-10T13:59:52.494Z sha 5e1c8474bf824cd43bdf9f0b40f4b48e148fae2c :: needs real behavior proof before merge. :: [P1] Remove the undeclared T from readJsonSync | [P1] Prevent legacy subscriptions from being re-imported | [P1] Fail safely when legacy state is unreadable
  • reviewed 2026-07-10T14:10:59.178Z sha 5e1c8474bf824cd43bdf9f0b40f4b48e148fae2c :: needs real behavior proof before merge. :: [P1] Remove the undeclared T from readJsonSync | [P1] Block empty-store startup when legacy state is unreadable | [P1] Prevent legacy subscriptions from being re-imported
  • reviewed 2026-07-13T03:56:23.266Z sha be05ad5c061290f71abda81453a82e1b37f78090 :: needs real behavior proof before merge. :: [P1] Fail startup when legacy Web Push state is unreadable
  • reviewed 2026-07-14T01:12:44.734Z sha 0eea5fc41a7e8c3dbbd497e4f24837959cf2fbb3 :: needs real behavior proof before merge. :: [P1] Fail startup when legacy Web Push state is unreadable
  • reviewed 2026-07-14T01:31:47.153Z sha 0eea5fc41a7e8c3dbbd497e4f24837959cf2fbb3 :: needs real behavior proof before merge. :: [P1] Fail startup when legacy Web Push migration fails | [P3] Update the documented Web Push storage locations
  • reviewed 2026-07-14T11:36:12.355Z sha 8f31d3834bb384fb960032402d905f4886f678a7 :: needs real behavior proof before merge. :: [P2] Keep the replacement repair function after importing the original module | [P3] Update the documented Web Push storage locations
  • reviewed 2026-07-14T12:25:42.580Z sha 789011d55d24db4e372f0b8aac8de7b1c41af4fe :: needs real behavior proof before merge. :: [P1] Make subscription mutations atomic | [P1] Arbitrate first-use VAPID key creation atomically

@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 10, 2026
@xydt-tanshanshan
xydt-tanshanshan force-pushed the refactor/push-web-sqlite branch from ef783c8 to fcadb17 Compare July 10, 2026 13:20
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Jul 10, 2026
@xydt-tanshanshan

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@xydt-tanshanshan
xydt-tanshanshan force-pushed the refactor/push-web-sqlite branch from c926268 to 33eacb9 Compare July 10, 2026 13:24
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling and removed agents Agent runtime and tooling labels Jul 10, 2026
@xydt-tanshanshan
xydt-tanshanshan force-pushed the refactor/push-web-sqlite branch 4 times, most recently from f25949d to 5e1c847 Compare July 10, 2026 13:49
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 14, 2026
@xydt-tanshanshan
xydt-tanshanshan force-pushed the refactor/push-web-sqlite branch 3 times, most recently from 713004b to e2840fc Compare July 15, 2026 07:14
@steipete
steipete force-pushed the refactor/push-web-sqlite branch from e2840fc to c23b6f3 Compare July 15, 2026 19:28
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts and removed gateway Gateway runtime labels Jul 15, 2026
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move Web Push subscriptions and VAPID identity to shared SQLite

2 participants