Repository navigation
improve(outbound): batch delivery ownership checks during recovery - #154591
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 21, 2026, 6:06 AM ET / 10:06 UTC (Revision 6). ClawSweeper reviewWhat this changesMoves delivery ownership lookups into the existing SQLite worker and batches restart-recovery checks while preserving receipt expiry and namespace precedence. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this remains a useful optimization absent from current main. No blocking defect was found. The prior import-cycle concern is resolved, and the earlier migration blocker does not apply to the preserved storage contract. Priority: P2 Review scores
Verification
How this fits togetherThe outbound delivery queue records whether a message is pending, completed, or failed. Restart recovery consults those records to decide whether to defer, resume, or settle interrupted work. flowchart TD
A[Interrupted sessions] --> B[Collect delivery IDs]
B --> C[Shared SQLite worker]
C --> D[Read queue namespaces]
D --> E[Apply existing receipt expiry]
E --> F[Ordered ownership results]
F --> G[Defer resume or settle recovery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +65, Tests +79. Total +144 across 24 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep ownership reads and receipt cleanup in the existing worker, with one ordered batch per recovery decision and the existing transaction-bound API for compound operations. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional bug: current source establishes repeated synchronous per-ID lookups, and the supplied benchmark measures their overhead. Is this the best way to solve the issue? Yes. Extending the existing worker and transaction kernel avoids a competing storage owner, and the inspected diff preserves the persisted contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c2d8511f0e1d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
455c48e to
0e19a88
Compare
0e19a88 to
7d526cf
Compare
|
Merged via squash.
|
…penclaw#154591) * improve(outbound): batch delivery ownership checks during recovery * fix(delivery): isolate ownership lookup kernel * fix(delivery): retain raw query justification on expression
What Problem This Solves
Restart recovery checks delivery custody one ID at a time on the Gateway thread, repeatedly reading namespaces and pruning the same receipt group.
User Impact
Recovery can check multiple pending deliveries in one worker operation, keeping these SQLite reads and receipt cleanup off the Gateway thread. Namespace precedence, settled/failed ownership, receipt retention, and stored data stay unchanged. Single-ID calls incur worker overhead; the measured latency benefit is in batches.
Why This Change Was Made
The existing delivery owner now reads bounded ID batches in one transaction, prunes each encountered producer prefix once, and rereads only after an actual deletion. The outbound lookup and all its callers await the existing shared-state worker. Restart recovery submits its complete delivery list once and rechecks cancellation afterward. The connection-bound single-ID API still serves existing compound transactions through the same kernel.
This is part of the maintainer-requested SQLite optimization campaign. It introduces no schema, configuration, upgrade, durability, or retention migration.
Stored-data compatibility: the state schemas, schema version, migrations, queue serialization, and completion-retention parser are unchanged from base
94a88aa994e. The existing pruning SQL retains the same predicates; only its deletion count is returned to avoid an unnecessary reread. Existing database fixtures cover canonical and retired namespace receipts, pending/failed ownership, and expiry. The files flagged by the automated data-model check change lookup routing, not persisted layout or backfill behavior; no migration is required.Evidence
Hosted CI exposed a type-inclusive import cycle. Moving the unchanged ownership lookup into a leaf kernel removes the broad payload-type dependency: the complete import graph now has zero cycles, all 47 focused tests pass, and full changed-code validation passes.
CI confirms both cycle guards pass. Its Kysely guard also required moving the existing raw-query justification onto the query expression after the new result binding; the full guard now passes, and emitted JavaScript is identical.
Refreshed onto main
761725d03f294aaddc399a759a0755d34a0e1ecf. This incorporates merged fix(update): keep model authentication from blocking updates #154453, which removes the failing in-update repair test path, and the Discord pacing fixture repair: readiness now waits for the first encoded source packet rather than playback admission. The upstream deferred-encoder regression and recorded 20 standalone/three original-suite runs cover that premature-readiness defect; they do not prove the historical hosted zero-packet failure had the same cause. All three optimization/CI-repair commits remain patch-identical after rebase (git range-diff). New-head CI remains required. The earlier ACP Doctor warning did not recur in the subsequent hosted job; interrupted local reproduction did not establish its cause.707 tests passed across the affected delivery, Gateway, recovery, and channel callers (269.48 s wall). A further 47 focused tests passed (38.10 s wall, one worker; overlaps the captured-context tests).
Real public worker coverage checks captured state and supervisor mode, preserves duplicate/missing results, and observes zero main-thread SQLite statements. Receipt and namespace tests cover expiry and pending/failed precedence. The original owner violates the retained-receipt SELECT budget (2); the candidate uses 1.
Synthetic indexed SQLite parity also covers 1,201 IDs, duplicate IDs, and missing IDs. No platform network I/O was involved.
Full changed-code validation passed (2,766.48 s wall): production and test types, typed lint, dead exports, schema, import-cycle, and repository guards. The final obsolete-wrapper cleanup also passed 43 affected tests (68.73 s wall).
Warm latency in a real isolated shared-state database, comparing the original per-ID store admission/read calls with the public batch worker API (Node 26.8.2; 20 warmups, five alternating rounds, 50 iterations per round or 20 for 100 IDs):
The source worker's first cold operation took 5.825 s and is excluded from the warm table; packaged startup was not measured. End-of-run RSS was 705 MB, not a before/after memory comparison. Query-only measurements separately show ten pending owners falling from 0.143 to 0.031 ms and ten bounded receipts from 1.638 to 0.192 ms. These measurements do not establish end-to-end message delivery latency.