Repository navigation
perf(trajectory): converge retention during sustained appends - #165678
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 October 5, 2026, 12:55 PM ET / 16:55 UTC. ClawSweeper reviewWhat this changesTrajectory cleanup reconciles committed appends with a sweep snapshot and revalidates small deletion batches so historical events can expire during continued writes. Merge readiness⛔ Blocked before merge - 3 items remain This remains useful work: current main still has the retention starvation mechanism, and the recorded campaigns demonstrate convergence during sustained appends. One introduced lifecycle defect needs repair. Priority: P2 Review scores
Verification
How this fits togetherTrajectory stores diagnostic events from agent runs in each agent’s SQLite database. Retention removes historical runs according to age and byte limits while sharing the database writer with other agent operations. flowchart TD
A[Agent run events] --> B[Append and trim session]
B --> C[Committed session receipts]
D[Reader snapshot] --> E[Retention sweep owner]
C --> E
E --> F[Revalidate bounded batch]
F --> G[Delete historical runs]
G --> E
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +201, Tests +437, Docs +18. Total +656 across 13 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep the receipt-based convergence design and explicitly retire each sweep’s in-memory state when either caller finishes or cancels it, without retiring a newer sweep. Do we have a high-confidence way to reproduce the issue? Yes: current main’s database-wide revision check explains starvation during sustained writes, and the captured campaign records the failing baseline. The introduced snapshot-retention defect is source-proven; this read-only review executed no target code. Is this the best way to solve the issue? Yes, with the lifecycle repair: reconciling committed session summaries and revalidating bounded candidates addresses starvation through the existing owner without changing stored data or retention policy. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 122967ae9f07. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
What Problem This Solves
Fixes global trajectory cleanup being starved by continued event appends. The database-wide revision handshake invalidated every historical selection, leaving expired events and bytes above the default budget. Related: #165274.
User Impact
Cleanup makes progress during managed event appends while preserving whole runs, current-session protection, oldest-first ordering, the 14-day age rule, and the default 512 MiB budget. No schema, stored counter, trigger, configuration, durability, or upgrade migration changes are introduced by this PR.
Why This Change Was Made
The read worker aggregates run summaries once per sweep. The retention owner reconciles committed session summaries and selects a bounded batch before writer admission. Each deletion transaction revalidates only its selected candidates: at most 16 runs / 10 MiB, preserving the existing oversized-whole-run exception.
Sweep-scoped mutation receipts account for appends and concurrent trims without double counting changes that overlap snapshot creation. Unknown foreign or unaccounted local mutations require a read-worker refresh; one refresh is allowed before deferring to the next append. Lease revocation and native close/replacement invalidate the receipts. Completion follows the deleting commit's remaining byte/age facts, without waiting for a quiet reader pass. Both callers use this owner; the global-revision handshake is removed. SQL-generated byte-order keys preserve SQLite BINARY ties in UTF-8 and UTF-16 stores.
Production LOC: +201 (437 additions, 236 deletions), excluding tests, test support, and docs. The approved schema-free freshness contract requires post-commit receipts, snapshot reconciliation, and lifecycle/freshness fencing. No parallel cleanup implementation or persisted counter is retained.
Measurement
Both final fixtures started with 700 MB of logical events across 450 sessions and ran sustained 50/100/200 events/s for 30 minutes. Every one of the 30 pressure sweeps at each scale completed under budget, with zero invalidations, zero freshness refreshes, and exact retained-row equality against a single-pass reference.
The full 20M maximum was 3.748 ms SQL + 123.360 ms COMMIT/checkpoint, with no overlapping GC. Deletion p99 was 7.023 ms. The maintainer accepted this result on 2026-10-05: the bounded SQL work meets the lane's intent; WAL checkpoint scheduling belongs to its existing owner. All hold measurements include COMMIT, and the measured 127.108 ms is not presented as below 100 ms.
Follow-up: WAL checkpoint scheduling during retention deletes.
These are recorded campaign results, not controlled same-host speedup claims. Final runs used Testbox / Node v24.19.0; prior v5 20M evidence used a shared Linux rig / Node 26.8.1. Maximum final append holds were 25.920 ms at 200K and 95.050 ms at 20M. The original starvation baseline's append maximum was 57.224 ms with a different arrival clock/host, so these measurements do not establish append-latency nonregression.
Resolved maintainer decision from #165274
ClawSweeper asked:
Its recommendation was:
Resolved: both final-source 30-minute campaigns demonstrate progress and convergence during continued writes. The original 20M starvation baseline invalidated all 1,100 selections, deleted no historical rows, and ended 208,369,770 bytes over budget.
Evidence
Provider for all final remote validation:
blacksmith-testbox, profileopenclaw-check.node scripts/run-vitest.mjs src/trajectory/runtime-store.sqlite.test.ts src/trajectory/runtime-retention.sqlite.test.ts src/trajectory/runtime-store-writer.test.ts src/trajectory/runtime-retention.test.ts --maxWorkers=1tbx_01m463bfs4m049dztkd491dtzbcd326f915580with the same commandtbx_01m46eksxb2eyb5eh7aw72fmtnnode scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <12 changed TS files> --threads=1tbx_01m463bfs4m049dztkd491dtzbnode scripts/check-changed.mjs --stagedRIG_ROWS=200000 RIG_ROW_BYTES=3500 RIG_LIVE_EVENT_BYTES=3500 RIG_APPEND_INTERVAL_MS=5 RIG_RATE_CLOCK=elapsed RIG_DURATION_SECONDS=1800 bash .local/lane455/run-rig.sh candidatetbx_01m466anq8e314rm5m87x9g770RIG_ROWS=20000000 RIG_ROW_BYTES=35 RIG_LIVE_EVENT_BYTES=0 RIG_APPEND_INTERVAL_MS=250 RIG_RATE_CLOCK=elapsed RIG_DURATION_SECONDS=1800 bash .local/lane455/run-rig.sh candidatetbx_01m4689bx64k729gst2dwvcbwcA native-owner negative control records one full-store writer-held aggregate in v5 and zero in the candidate. Restoring the former JavaScript comparator makes the Unicode tie regression fail for the intended retained-row difference; the candidate passes. The original starvation and settlement regressions also failed on their preceding implementations. Independent detached P0–P2 review completed scoped-clean, with no actionable findings. The subsequent rebase changed no trajectory or relevant SQLite implementation source; its schema-file delta only adds unrelated voice-cache indexes.
The inherited export findings concern
BranchSummaryResult,renderRootHelpText,stripEnvelopeFromMessage, and seven media-default constants. They were neither changed nor suppressed here.Benchmarks were pinned to base
0043be77a33e; publication was rebased ontocd326f915580. Source and exact executed-driver hashes were verified. The rig exercises actual append/retention owners with a separate reader worker and canonical schema/index/WAL policy; it does not measure Gateway broker latency. Unknown mutations outside the receipt owner may conservatively refresh/defer. At pressure stop, subsequent writes had refilled 2,528,486 bytes above target on the 20M fixture; every pressure-sweep commit receipt met the budget, and the final quiet sweep reached 536,867,279 bytes with zero eligible expired runs. This preserves hourly retention semantics.