Repository navigation
perf(gateway): move post-ready notice sweeping off the main thread - #165331
Conversation
Replay retained notices through the existing shared-state and session readers, with cursor rereads and current watcher grants in the state writer. Preserve acknowledged publication and startup close settlement; remove the native sweep path.
|
🦞👀 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 5, 2026, 1:02 AM ET / 05:02 UTC (Revision 3). ClawSweeper reviewWhat this changesMoves startup recovery of retained session-change notices into existing database workers while preserving cursor updates, notice publication, and shutdown settlement. Merge readiness✅ Ready for maintainer review The previous older-store compatibility finding is resolved. No additional actionable defect was found, and current main still performs the synchronous sweep, so this PR remains useful. Priority: P2 Review scores
Verification
How this fits togetherSession watches retain change watermarks so OpenClaw can restore pending notices after restart. Gateway startup reads those watches, validates their receiving sessions, updates the watermarks, and returns notices to the system-event queue. flowchart TD
A[Gateway startup] --> B[Pending watch reader]
B --> C[Watcher session reader]
C --> D[Current identity checks]
D --> E[Cursor writer transaction]
E --> F[System-event queue]
E --> G[Retention pruning]
A --> H[Shutdown settlement]
H --> E
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +162, Tests +260, Docs +10. Total +432 across 14 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep notice recovery with the existing reader and writer owners, preserving older-store tolerance, current watcher identities, and accepted-work settlement. Do we have a high-confidence way to reproduce the issue? Yes, the synchronous post-ready database path is identifiable on current main, and the supplied startup measurements establish its observed SQL activity; this review did not execute it. Is this the best way to solve the issue? Yes, reusing the existing database workers and admission owner is a focused solution, and the revised projection preserves the supported older-store contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c5baaee54b00. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles) |
Keep pending cursor discovery tolerant of the first-use watcher store column and compare absent bindings consistently. Extend the existing older-store regression through recovery and pruning without changing schema or unbound notice suppression.
|
@clawsweeper re-review Fixed the older-schema discovery finding in 5c05afe. Discovery uses the prior tolerant row projection, and the transaction normalizes the absent binding to null. The extended older-reader regression proves cursor advancement and forced pruning without installing the first-use column. It preserves intentional suppression of notices with an unbound store, then verifies a distinct feature write installs the column without changing the version. All 10 worker-boundary tests pass; the pre-fix query fails the cursor assertion (0 instead of 2). |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
|
@steipete — this Gateway fixture needs a separate follow-up. Hosted job 111649085414 fails TS2739 at The tested merge is The existing runtime-store fixture supplies both dependencies with |
…penclaw#165331) * perf(gateway): move post-ready notice sweeping into workers Replay retained notices through the existing shared-state and session readers, with cursor rereads and current watcher grants in the state writer. Preserve acknowledged publication and startup close settlement; remove the native sweep path. * fix(sessions): preserve notice recovery for older stores Keep pending cursor discovery tolerant of the first-use watcher store column and compare absent bindings consistently. Extend the existing older-store regression through recovery and pruning without changing schema or unbound notice suppression.
What Problem This Solves
Post-ready session-watch recovery reads watcher entries and writes cursor watermarks on the Gateway thread. A synthetic Gateway startup reproduced two main-thread
BEGIN IMMEDIATEfailures (database is locked) after/readyzsucceeded. With retained notices, the sweep also scales synchronous session reads with the number of watchers.Why This Change Was Made
Move pending-cursor discovery into the existing shared-state reader and the sweep transaction into the existing
sessionStatewriter. Prepare watcher identities through the session reader, then recheck physical sources and current session identities at transaction and commit admission. The transaction rereads cursor bindings and watermarks, so acknowledgments and replacements during preparation are respected. Only committed notices return to the existing system-event queue; the startup lifetime joins accepted work before worker teardown.The native sweep and its synchronous existence helper are removed. Registration, acknowledgment, and sweep share the same extracted admission helper. No schema, configuration, retention, durability, or existing SDK method-signature change; no update migration or new
OPENCLAW_*name.User Impact
The measured durable startup sweep performs no caller-thread SQL. The existing 30-day/50,000-row pruning policy and notice text remain unchanged. This is a main-thread SQL reduction, not a claim that total SQL or latency decreases.
Production diff: +246 / −84 / net +162; 330 changed lines, excluding tests and documentation.
Evidence
Measurement uses the retained sqlmeasure3 native SQLite observer: successful executions at
DatabaseSync.execandStatementSync.get/all/run/iterate, excluding prepares and failed statements. Fixtures and stores are synthetic and isolated; boot admission and teardown are outside the focused sweep window.session-state-events.ts:354— watcher existence and metadatasession-state-events.ts:374— cursor transactionsession-state-events.ts:366— shared-state openingsession-state-events.ts:367— pending cursor inventoryBaseline:
e76032fbab8d; candidate base:a37950a0b4a0, integrated for the pre-existing architecture-cycle fix in #165284. The notice implementation is unchanged between those bases. The full-Gateway 45-second post-ready idle window improved 34 → 16 successful main-thread statements. The empty sweep fell 18 → 0, and failed main-thread BEGIN attempts fell 2 → 0. The remaining 16 statements are eight cron startup device-identity reads and eight GitHub OAuth maintenance reads. Both Gateways shut down cleanly. These are phase-window counts, not latency measurements.Validation on Node 24.21.0 (macOS arm64):
--maxWorkers=1, 522.41s wall including compiled-worker preparation. The replay regression took 22.058s; the real close regression took 27.463s. These exercise actual SQLite owners and Gateway teardown; mocked storage would not prove the boundary.--maxWorkers=1, 611.90s wall. The new acknowledgment/rebinding race took 20.892s; its final nine-test boundary file took 174.34s including transformation and setup.qaRuntime): passed; build phases 408.8s. Existing worker-deploy source-map warnings remain; the focused source harness independently supplies caller attribution.OPENCLAW_*names: 0.1d1fc936). Inspected deltas are the additivesessionState.sweep/sessionState.pendingNoticescontracts, the cursor-address type, and declaration movement from extracting the sweep; existing service methods retain their signatures.node scripts/check-changed.mjs: passed in 2761.23s wall, including core typechecking, all 27 test typecheck graphs, formatting, lint, all three dead-export scans, database/auth guards, and zero runtime import cycles. Validation ran on a heavily loaded host; these wall times are not performance claims.The worker-cutover caller census found the real sweep tests already in the host-owned database/Gateway projects; no routing changes were needed. The wrapper source-closure tests confirm that the two new host modules require no wrapper inventory addition.
An intermediate test preparation collided with a concurrent runtime rebuild (
ENOENTfordist-runtime/extensions/arcee/package.json); final runtime build and test preparation ran sequentially.The zero-caller-SQL regression failed on the original implementation. Coverage also includes missing watchers, cursor acknowledgment/rebinding while discovery yields, latest material watermarks, and the real Gateway close prelude joining accepted persistence after scheduler/connection cancellation.
Catalog refresh #165034 is already merged and worker-backed. Related parallel lanes: #165028, #165205, #165193, #165129; potential umbrella overlap #162433. The adjacent notice-formatting work in #126890 changes a different part of the notice flow. Also adjacent to the replysnap/readamp/sqlmeasure4, incognito P7e/P7f2/P7h/P7i/P7j, and other SQL phase lanes. These do not change this focused sweep ownership.
Remaining scope limits: the idle workload does not populate managed outgoing-media retention. Its remaining session lookups are separate background SQL debt. Retained-plugin cleanup is scheduled at 30 seconds with busy retries, so a 45-second window does not guarantee execution; its ledger reader is already worker-backed. The static inventory's old boot-sweep classification is not used to claim the measured runtime reduction.
Landing compatibility repair
ClawSweeper identified that admitted older stores may omit the first-use
watcher_store_pathcolumn. Pending-cursor discovery now retains the previous tolerant row projection, and the writer compares absent bindings asnull. The existing older-reader fixture covers cursor advancement and forced retention pruning before the first feature write, while preserving intentional suppression of notices without a physical store binding. No schema repair or authorization change is introduced.The released-surface audit compared
v2026.9.8with this candidate: the sweep is internal, with no releasedsrc/plugin-sdk/**,api.runtime, or documented SDK-subpath exposure. This PR preserves its merge-base async signature. The extracted admission helper is internal; worker operations are additive. The original SDK comparison report remains valid because the compatibility repair changes implementation only, without declaration changes.Final compatibility repair
5c05afea19f8: the worker-boundary suite passed 10/10 tests in 128.25s wall on Node 26.10.0, including the older-store regression (13.117s). The pre-fix query leaves its notification watermark at 0 instead of 2. The final fixture also verifies that the expired event is present before recovery and pruned afterward, the optional column stays absent through recovery, and a distinct subsequent feature write installs it without changing the user version. Focused lint, formatting, andgit diff --checkpassed. The other 38 owner tests passed during the earlier two-file run; its only failure was the then-incorrect legacy-notice fixture expectation.Exact-head CI run 37265752016 completed successfully for
5c05afea19f8, with no failed jobs. Summed reported CI job duration is 9,068 seconds (parallel job time, not elapsed or billed time; per-file CI seconds are not separately exposed). Final exact-head Codex P2 autoreview is scoped-clean, with no actionable findings.ClawSweeper completed the repaired-head review at 2026-10-05 05:02 UTC: the older-store finding is resolved and no actionable findings remain.
Published-driver update proof passed on isolated Linux: published
2026.9.8upgraded to candidate commit5c05afea19f8f91d283370ecf2a6ea9651c2a9c4using the repository'spublished-driver-update-docker.shcell. Both packages carry version2026.9.8; exact build identity distinguishes the candidate (2026.9.8-5c05afea19f8-2026-10-05T06-06-18.584Z). The updater exited 0 in 454.135s, phasefinished; running-build and durable/incognito checks passed;/readyzreturned HTTP 200 withready: trueand no failing checks. Fixture shutdown exited 0. Canonical packaging also passed all 151 public SDK subpath checks, CLI bootstrap checks, and UI budgets. Candidate tarball SHA-256:d90c681ad114aae68db82a54efc4df4080eb365d84360cda6b7bb2f5af4aec6a.Infrastructure attempts were separate from product proof: Testbox remained queued and was stopped; AWS quota fallback was undersized and stopped before the payload; the successful host required the supported Docker setup. A concurrent local Node installation change was recovered with an already-installed supported runtime. All task-owned leases are stopped/released.