Repository navigation
improve: reduce idle delivery and notification database work - #168643
Conversation
Keep queue and Web Push presence in the existing physical-database receipt owner. Preserve separate audit durability points while omitting readback for current newly inserted events. Audit collection, retention, and schema are unchanged.
|
🦞👀 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 changes before merge. What this changesThis PR caches idle delivery and subscription-presence facts and avoids rereading newly inserted, unexpired audit events. Example: A warmed Gateway turn checks an empty outbound queue and Web Push presence while recording audit events.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains This PR delivers a useful, measured reduction in database work, and the previous wrapper-inventory finding is fixed. No new actionable code defect was found; the failed baseline-ratchet check remains unattributed. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherGateway delivery recovery, notification scheduling, and audit persistence use shared-state SQLite workers; committed writer receipts now let host callers reuse presence facts before dispatching another read. flowchart TD
A[Gateway callers] --> B[Physical database facts]
B --> C[Shared state workers]
C --> D[SQLite state database]
D --> E[Committed writer receipts]
E --> B
A --> F[Current send authorization]
F --> G[Notification transport]
Technical reviewBest possible solution: Retain this focused optimization with receipt-owned invalidation, unchanged send authorization, and the corrected wrapper inventory. Do we have a high-confidence way to reproduce the issue? Baseline source shows repeated presence-worker dispatch and audit readback; the supplied workload measurements quantify those paths, and this read-only review ran no target code. Is this the best way to solve the issue? The patch uses the existing physical-database receipt owner, removes the superseded delivery cache, and retains readback where retention can remove an expired append. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8d1c7bcbce48. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +78, Tests +79, Docs +8, Other +1. Total +166 across 13 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 10, 2026, 6:20 PM ET / 22:20 UTC (Revision 3). |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…w#168643) * perf(sqlite): reuse idle delivery and notification facts Keep queue and Web Push presence in the existing physical-database receipt owner. Preserve separate audit durability points while omitting readback for current newly inserted events. Audit collection, retention, and schema are unchanged. * fix(tooling): include delivery cache in extracted PR wrappers
Upstream first-parent #1297, stopping just before #1298 (tool-call XML grouping) so that change gets its own step. Four conflicts: - delivery-queue-sqlite-bound: keep both imports, upstream's emptyOutboundDeliveryQueueAdmission (openclaw#168643) and our row codec type. - attempt-execution: keep our startAttemptContinuation; take upstream's resolveCommandAuthProfileSelection (openclaw#168392). Upstream's other edits in the file (inlined pinnedHarnessId, internal-continuation promptCacheKey) merged cleanly; our resolveClaudeCliFallbackPrelude extraction is untouched by upstream. - session.test: keep our custody test state; take upstream's buildCommandContextForTest (openclaw#168482). - plugin-sdk-surface-report: measured 3683/2137 (upstream 3672/2133, +11/+4). Also: test-mock-exports baseline pruned 10162 -> 10142 (20 stale rows from #1433's fixes; shrink only, check --prune), worker-access-inventory regen. pnpm install after the lockfile change. tsgo core/core-test/ext/ext-projects 0; sdk --check 0; inventory 0; config docs 0; mock-export ratchet OK. db-worker ratchet 706 -> 709 vs upstream is #1432 (unchanged vs step 25). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
What Problem This Solves
Idle outbound recovery and Web Push presence checks kept making worker requests, and each current audit append reread the row it had just inserted.
User Impact
Reduces database and worker traffic during ordinary turns. Delivery custody, send authorization, audit collection, retained fields, retention limits, and durability points are unchanged. No schema or update migration is required.
Why This Change Was Made
Use the existing physical-database receipt owner for the empty outbound queue and bound-subscription boolean. Queue insertions/replacements invalidate the empty fact; subscription writers publish or invalidate presence. The host consumes those facts before dispatching a read. The old connection-local delivery cache is removed. Audit reuses its prepared inserted values and validated sequence, retaining readback for already-expired records that pruning can remove.
Mentions already has the corresponding head cache on this base. Audit start/end and trajectory flushes remain separate: they cross distinct durability boundaries, and trajectory's remaining read enforces its sequence and retained-byte window. The target of 4 requests / 14 statements is an aim; this PR ships the smaller verified saving.
Evidence
Focused owner and sibling proof passed: 7 files / 130 tests, via
node scripts/run-vitest.mjs ... --maxWorkers=1(the repositorypnpm testrunner), 568.38 s wall time including 126.77 s cold worker preparation; Vitest duration 424.44 s on the loaded macOS host. The changed cases took 1.28 s (expired audit append), 3.79 s (subscription presence lifecycle), 4.28 s (expired-send cleanup), and 5.74 s (worker/native queue writes and rollback). These exercise real writer/reader boundaries; there are no new sleeps, timers, serial configs, or test-only production seams. Existing broader store lifecycles account for the suite cost; no CI-seconds claim is inferred from these host timings.Codex autoreview: initial full-change review had no actionable P0–P2 findings; the second/final round reviewed the wrapper-inventory correction and had no actionable P0/P1 findings. Formatting and
git diff --checkpassed. The initial local two-case probe was invalidated before tests by concurrent source edits during worker compilation; the subsequent frozen-candidate suite passed. No schema/update/Doctor/service/plugin-loading/SDK change, so the published-driver update cell and SDK API diff do not apply.SQL measurement
Exact baseline
e40606fdea96135758ec5bc0b1a355d08ead0c7e, measured product candidate0d621268cd304261d8fe38573cce02d3ace2c608; final headb2bc97ff6b33c1e23c09ba81e17e2516dd40d822, same AWS host and shared full workload. Ran M,C,M,C,M,C, then the required extra M,C pair for raw warmed growth. The later one-line wrapper inventory correction changes no measured runtime code. Statistics below include all four pairs; warmed values are per turn.Warmed-window scope operations (per turn):
The targeted operations save 3.4 SQL statements and 1.4 requests per warmed turn (25.4 → 22 SQL; 5.4 → 4 requests). The first three pairs had raw warmed medians 683.9 → 691.8 SQL. The extra pair measured 691.3 → 689.5 warmed SQL and 15,382 → 15,331 whole-workload SQL, with requests 3,160 → 3,135. Across four pairs, raw warmed growth is 0.44%, within the unchanged-owner noise floor; the whole-workload median falls by 63 statements and 24.5 requests.
The additional warmed MAIN statements come from unchanged memory-admission cycles. Whole-workload family medians are identical:
database.domain.execute445 SQL / 32 requests,pluginState.compareDelete119 / 34,pluginState.compareUpdate102 / 17, andpluginState.observe51 / 17. These move from first-turn into warmed windows. The deferred-startup boot+connect+first combined median falls 4748.5 → 4678 SQL (base runs 4793, 4786, 4672, 4711; candidate 4789, 4657, 4626, 4699). All compared duration ratios are below 1.5.One candidate audit
BEGIN IMMEDIATEreturned busy before the changed readback path. The existing writer kept its queue head, retried after about 32 ms, inserted the record, and committed. Startup/shutdown lock diagnostics also occurred on the baseline. No warmed failures occurred in the extra pair.Static checks and CI
Remote Madge, standalone Knip, database worker/T1 ratchet, and dialect ratchet passed.
check:changedpassed its 28 type graphs and preceding guards, then failed the dead-export scan on 16 unrelated existing exports. Running the exact scanner on the pinned baseline produced the same 16 findings, with no candidate-only or baseline-only entries and zero full-tree scan findings.Initial required CI exposed a PR-caused extracted-wrapper dependency omission: the new delivery cache module was missing from
wrapper-components.txt. The follow-up adds that single inventory entry. The focused runtime-import closure regression passes (1 test, 36.18 s runner wall; 25.48 s test). The second/final Codex review is clean. On corrected headb2bc97ff6b33, the source-closure and provisioning suites pass: 19 passed / 1 skipped across two files, 188.48 s command wall (source closure 3.14 s; provisioning 165.19 s). The baseline provisioning suite also passes, confirming the initial CI failure was repaired rather than waived.The corrected-head CI database ratchets pass. The mock-export failure in
src/model-picker/apply-session-model-selection-placement.test.tsmatches main run 38090291712, job 114325165253, exactly. The identical Discord ambiguous-announcement timeout is confirmed in earlier PR #168316, run 38089565338 / job 114323332558, before this PR. Its test, queue cache kernel, and SQLite receipt code are byte-identical to this PR base. That cross-process fixture calls the runtime cached queue reader from a process other than the Gateway writer; it needs independent investigation against a direct committed snapshot. No passing CI result or completed fixture repair is claimed. Landing uses Peter’s authorized inherited-failure admin exception; the independent fixture investigation continues separately.Production +105/−27 lines; tests +132/−53; docs +8/−0; wrapper inventory +1/−0.
Attribution and accepted limits
Implementation by Peter Steinberger. No contributor PR was incorporated. The Gateway is the single runtime writer; external writers must use the Gateway or hold exclusive offline ownership. These presence facts are scheduling hints, never permission to send. Actual delivery and subscription policies retain their current checks.