Skip to content

perf(gateway): batch Web Push recipient preparation - #158595

Merged
steipete merged 4 commits into
mainfrom
perf/l38-web-push-preparation
Sep 26, 2026
Merged

steipete merged 4 commits into
mainfrom
perf/l38-web-push-preparation

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Web Push notifications perform synchronous per-subscriber database reads on the Gateway thread, delaying other work when many browsers subscribe.

User Impact

Ordinary attention notifications and approval requests/updates prepare account preferences and identity facts off-thread, while preserving current pairing, role, session visibility, and notification lifetime checks before dispatch. No protocol, configuration, schema, retention, or update migration changes are required.

Why This Change Was Made

The Web Push authority owner now shares batched preference reads and the resident profile catalog across both notification paths. Prepared session facts remove the remaining synchronous visibility reads. Preference changes and profile merges during preparation invalidate the batch; binding and pairing custody lasts through provider start, then releases before network completion. Both duplicate preference helpers are removed.

Evidence

Interleaved A/B component benchmark, 100 synthetic subscribers, 10 warmups and 60 measured samples per variant, with network/encryption excluded:

Recipient selection and effective preferences Before After
Median main-thread CPU 9.234 ms 0.408 ms
Median wall time 9.813 ms 0.414 ms
Synchronous main-thread SQLite statements 1,400 0

This is component proof, not an end-to-end latency claim.

134 focused tests passed on Blacksmith Testbox tbx_01m3dkbgm9bywrtnwb3fnwyf3r (lease workflow). Each file ran with node scripts/run-vitest.mjs <file> --maxWorkers=1:

File Tests Wall time
src/gateway/event-web-push.test.ts 48 14.641 s
src/gateway/approval-web-push.test.ts 25 10.361 s
src/gateway/event-web-push.storage-scope.test.ts 7 9.335 s
src/state/user-preferences.test.ts 12 21.274 s
src/state/user-profile-list.resident.test.ts 13 8.056 s
src/infra/push-web.test.ts 29 22.093 s

The real-session notification regression failed against the original delivery modules with 36 get, one all, and three iterate calls, then passed with zero calls on the candidate. It covers eligible delivery, device/profile downgrades, missing role policy, and generic-event visibility. Deferred tests also cover preference changes/profile merges during pairing preparation and approval settlement during preference preparation.

node scripts/check-changed.mjs ran on the same Testbox. Production typechecking and all 25 selected test graphs passed, as did the preceding format, boundary, and contract guards. The initial dead-export scan found the retired subscription-list facade; it and its barrel export are now removed, and its persistence tests use the scoped reader. The follow-up changed gate passed the final state/infra test graphs, then the lease ended during its dead-export scan. The final aggregate lint/guard tail remains unverified; hosted CI is authoritative. The lease was retired with crabbox stop.

Local installation hit an unrelated noVNC patch failure, and local focused-test worker compilation was stopped under host saturation. Native Testbox sync timed out; the repository wrapper stalled during source packaging. Final remote proof used the same leased box, a clean verified base, task-scoped file transfer, and SHA-256 verification of every changed file. No full build or end-to-end swarm run was performed.

Deslop completed. Independent Codex branch review plus fresh reviews of the fixture correction and retired-facade cleanup: scoped-clean through P2; no accepted or actionable findings.

Production: +497/−262 lines (net +235). Tests: +352/−80 (net +272). The production growth retains preference mutation settlement, catalog lifetime, and current session authority across worker waits; deleting the duplicate preference helpers alone could not fund those necessary checks. The existing catalog module was split along its prepared-identity responsibility to stay below its line cap.

Related non-duplicate changes inspected: #158586 and #158380 change session preparation (this PR only exports its existing read type); #158445 and #158235 add other read-worker commands; #158123 changes approval error reporting; #158035 changes task-failure notification classification. Their overlapping work remains separate.

Landing validation: hosted CI run 36213046146 found seven lint errors in the two Web Push test fixtures (redundant default type arguments and a copied callback type that omitted the production promise return). Commit 54b1e7283778451feadd0aee008dc75fd0580bc4 repairs those types without changing production behavior or completion ordering. Targeted lint passed; all 73 tests in event-web-push.test.ts and approval-web-push.test.ts passed in a combined single-worker run (127.93 s command wall, including cold compilation). Independent Codex review of the repair found no actionable issues. Hosted exact-head CI remains the landing gate; the cancelled jobs from the failed run are not passing evidence.

Review follow-up: the table-existence finding does not apply to admitted connections: tableExists consumes getAdmittedSqliteSchemaFacts(db).tables, and selectUserPreferenceValues predates this PR. The catalog alias projection still scans resident profiles per identity lookup; large-catalog scaling has not been measured and remains a follow-up limitation of the component benchmark. The coordinator approved this bounded recipient-preparation change; no claim of constant-time identity fan-out is made.

Share canonical profiles, preferences, and prepared session visibility across ordinary and approval notifications. Retain current authority through provider start and refresh batches across preference changes and profile merges.
@clawsweeper

clawsweeper Bot commented Sep 26, 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 size: XL labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 02:52
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 25, 2026, 10:59 PM ET / September 26, 2026, 02:59 UTC (Revision 2).

ClawSweeper review

What this changes

The branch moves Web Push preference and session-visibility preparation into shared worker-backed reads for browser attention and approval notifications.

Merge readiness

⛔ Blocked before merge - 4 items remain

The Web Push performance problem remains on current main, and this branch addresses the right delivery path. Two findings from the prior review remain at the unchanged head: profile lookup still scans the full resident catalog for each subscriber, and the new worker read invokes a per-call schema check.

Priority: P2
Reviewed head: ed2721cbf30ac2936c601843da35a8cffa8767b1

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The component benchmark and focused tests give useful evidence, but two unchanged hot-path findings still limit merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The maintainer-authored PR is exempt from the external contributor proof gate. Its A/B component benchmark exercises recipient preparation with synthetic subscribers, while large distinct-profile scaling remains unmeasured; no stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external contributor proof gate. Its A/B component benchmark exercises recipient preparation with synthetic subscribers, while large distinct-profile scaling remains unmeasured; no stored-data contract changes.
Evidence reviewed 10 items Introduced recipient path: The pinned PR diff adds catalog and preference preparation to the shared Web Push authority path.
Repeated catalog projection: The new catalog reader calls identity projection for each subscription during preference preparation and recipient selection; that projection scans all resident rows to build aliases.
Catalog scan cost: Identity projection filters every resident profile row for one canonical profile, making repeated calls scale with subscribers multiplied by catalog size.
Findings 2 actionable findings [P2] Batch profile identity projection before selecting subscribers
[P2] Use admitted schema facts for the new preference read
Security None None.

How this fits together

The Gateway turns attention events and approval changes into Web Push notifications for subscribed browsers. It selects recipients using subscription bindings, device pairing, profiles, preferences, and session visibility before sending to a push service.

flowchart LR
  A[Attention or approval event] --> B[Bound browser subscriptions]
  B --> C[Profile and preference preparation]
  C --> D[Pairing and session access checks]
  D --> E[Eligible recipients]
  E --> F[Web Push sender]
Loading

Before merge

  • Batch profile identity projection before selecting subscribers (P2) - Each new readCurrentIdentity call builds aliases by scanning every resident profile. Web Push calls it during batch preparation and again while selecting subscriptions, so many distinct subscribers on a large catalog restore subscriber-count × profile-count synchronous Gateway work. Build aliases once in the catalog owner and measure that scale.
  • Use admitted schema facts for the new preference read (P2) - This new worker command calls the existing selector's tableExists check for every notification read. Table availability belongs to database admission; carry that admitted fact into this hot path instead of adding another per-read schema query.
  • Resolve merge risk (P1) - The 100-subscriber benchmark does not cover many distinct subscribers against a large profile catalog; repeated synchronous alias scans could stall the Gateway as that catalog grows.
  • Complete next step (P2) - Batch or index profile aliases, use admitted schema facts for the worker preference read, and validate distinct-subscriber scaling before merge.

Findings

  • [P2] Batch profile identity projection before selecting subscribers — src/state/user-profile-list.ts:604
  • [P2] Use admitted schema facts for the new preference read — src/state/openclaw-state-read.worker.ts:633
Agent review details

Security

None.

PR surface

Source +235, Tests +272. Total +507 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 15 497 262 +235
Tests 6 352 80 +272
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 849 342 +507

Review metrics

Metric Value Why it matters
Measured foreground SQLite reads 1,400 → 0 statements for 100 synthetic subscribers The component benchmark supports the main-thread read reduction but does not cover catalog-size scaling.
Production and test code production +497/−262 (net +235); tests +352/−80 (net +272) The PR explains production growth through mutation settlement and retained authority, but the remaining repeated catalog projection needs repair.

Merge-risk options

Maintainer options:

  1. Fix catalog scaling before merge (recommended)
    Index aliases once per catalog revision, remove the new per-read schema probe, and measure distinct subscribers against a large profile catalog.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve Web Push recipient authority and delivery behavior while replacing repeated full-catalog alias projection with a catalog-owned batch or index. Use admitted schema facts for the new worker preference read. Add focused regression coverage and measure distinct subscribers with a large profile catalog before merge.

Technical review

Best possible solution:

Build or reuse a catalog-owned alias index and carry table availability from database admission into preference reads while preserving the existing binding, role, and session revocation checks.

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

Yes, from source: current main performs a synchronous preference read for each eligible Web Push target. The PR body reports an A/B component benchmark, but this read-only review did not execute it.

Is this the best way to solve the issue?

No, not yet. Shared recipient preparation is the right boundary, but its catalog projection still scales with subscribers times profiles and its new worker read repeats a schema check.

Full review comments:

  • [P2] Batch profile identity projection before selecting subscribers — src/state/user-profile-list.ts:604
    Each new readCurrentIdentity call builds aliases by scanning every resident profile. Web Push calls it during batch preparation and again while selecting subscriptions, so many distinct subscribers on a large catalog restore subscriber-count × profile-count synchronous Gateway work. Build aliases once in the catalog owner and measure that scale.
    Confidence: 0.94
  • [P2] Use admitted schema facts for the new preference read — src/state/openclaw-state-read.worker.ts:633
    This new worker command calls the existing selector's tableExists check for every notification read. Table availability belongs to database admission; carry that admitted fact into this hot path instead of adding another per-read schema query.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 37259b7cab6b.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway performance improvement with two normal-priority repair findings.
  • merge-risk: 🚨 availability: Repeated full-catalog alias projection can add synchronous Gateway work as distinct subscriber and profile counts grow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The maintainer-authored PR is exempt from the external contributor proof gate. Its A/B component benchmark exercises recipient preparation with synthetic subscribers, while large distinct-profile scaling remains unmeasured; no stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/event-web-push.test.ts src/gateway/approval-web-push.test.ts src/state/user-profile-list.resident.test.ts src/state/user-preferences.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs.

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Batch or index profile identities and measure a large catalog with distinct subscribers.
  • Replace the new preference read's table-existence query with admitted schema facts.

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 (1 earlier review cycle)
  • reviewed 2026-09-26T02:51:13.842Z sha ed2721c :: blocked before merge. :: [P2] Batch profile identity projection before selecting subscribers | [P2] Use admitted schema facts for the new preference read

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 54b1e7283778451feadd0aee008dc75fd0580bc4
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/web-push-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

Match the push snapshot action promise contract and omit default deferred type arguments. Fixes exact-head CI run 36213046146; targeted lint and 73 Web Push tests passed. Independent review found no actionable issues.
@steipete
steipete merged commit 5dc4df5 into main Sep 26, 2026
203 checks passed
@steipete
steipete deleted the perf/l38-web-push-preparation branch September 26, 2026 03:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
* perf(gateway): batch Web Push recipient preparation

Share canonical profiles, preferences, and prepared session visibility across ordinary and approval notifications. Retain current authority through provider start and refresh batches across preference changes and profile merges.

* test(state): control preference broker settlement

* refactor(push): retire unscoped bound subscription listing

* test(gateway): fix Web Push fixture lint contracts

Match the push snapshot action promise contract and omit default deferred type arguments. Fixes exact-head CI run 36213046146; targeted lint and 73 Web Push tests passed. Independent review found no actionable issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant