Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 9:15 AM ET / 13:15 UTC. ClawSweeper reviewWhat this changesThis PR moves automatic SQLite session maintenance out of normal session-entry writes into a coalesced, handle-bound deferred owner, with targeted candidate queries and lifecycle-race coverage. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open. The introduced patch is a coherent owner-boundary repair with no concrete correctness finding from source review, and current main does not contain it. Its changed automatic-cleanup timing and protected maintainer status require session-storage owner review before merge. Priority: P1 Review scores
Verification
How this fits togetherChannel ingress records session metadata and route state before dispatching a turn. The session-maintenance subsystem later archives or removes stale entries and their unreferenced transcript state. flowchart LR
A[Inbound channel message] --> B[Session metadata and route write]
B --> C[Deferred maintenance owner]
C --> D[Targeted candidate selection]
D --> E[Lifecycle revalidation]
E --> F[Archive or remove stale state]
B --> G[Turn dispatch]
Decision needed
Why: This changes the timing of retention work on persisted session state without adding a schema or configuration contract; source review supports the design, but accepting that operational tradeoff requires owner intent. Before merge
Agent review detailsSecurityNone. PR surfaceSource +259, Tests +277. Total +536 across 16 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the handle-bound, coalesced maintenance owner if a session-storage owner accepts eventual automatic cleanup on ordinary writes; preserve explicit cleanup’s synchronous contract and merge only after exact-head CI succeeds. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: seed an unprotected stale session entry and send a channel inbound event; current main remains on the pre-PR entry-maintenance path, while the added boundary test models dispatch-before-cleanup. Is this the best way to solve the issue? Yes, subject to the stated lifecycle decision: moving maintenance to the post-commit owner addresses the implicated serialized-write boundary while retaining exact-entry and transcript-state revalidation before deletion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against abb565ea5f9f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Owner acceptance for the ClawSweeper before-merge items:
|
|
Thanks @obviyus! Proof: Published channel ingress dispatched before automatic maintenance on a large SQLite session store, then cleanup completed.
|
## Summary - Move automatic logical session maintenance out of ordinary entry-write latency. - Coalesce writes per SQLite store and rerun from a fresh snapshot when another write lands during maintenance. - Select indexed age and cap candidates before loading exact entry payloads. - Continue independent cleanup after one planned entry changes. ## Problem Discord and Telegram channel ingress records metadata and last-route state before dispatch. Both writes synchronously ran logical maintenance in the store-writer queue. One stale candidate caused each write to materialize every `session_nodes` payload. The Control UI `chat.send` preparation path uses one exact-row lookup and does not run this two-write channel burst. Closes openclaw#135905. ## Root cause The entry accessor owned both the user write and the full maintenance plan. The maintenance owner first found a stale row, then called the unbounded full-store reader inside the serialized write transaction. The detached metadata write and awaited route write could both plan the same stale removal before finalization deleted it. ## Fix - The entry accessor commits and publishes the entry, then kicks one process-local per-store maintenance owner. - A generation counter retains one pending rerun when writes land during awaited planning or archive work. - The planner reads lightweight key projections, indexed age candidates, and only enough oldest cap candidates. - Full entry JSON loads only for selected archive or removal rows. - Final deletion still reacquires the lifecycle and writer owners, rechecks the exact entries and references, and preserves archive-before-delete. - A changed planned entry is skipped and logged while independent entries in the batch continue. - Each deferred owner is bound to the exact open database handle. It cannot reopen a closed store, act on a replacement handle, or delete a replacement owner. No configuration, schema, sidecar, freshness poll, production timeout, retry, or compatibility path was added. The implementation reuses the current SQLite projections, Kysely query layer, writer queue, and lifecycle fences; no external library or plugin fits this internal ownership repair. ## Proof Baseline: `fe94f8cb0cb732328c03553425dd2fb2c1ae9f81`. - Independent 537 MB store, 256 rows, five warm samples: channel ingress averaged 1,864.23 ms; web preparation averaged 1.838 ms. - Each baseline channel call ran two full-store materializations plus three full metadata projections; those queries accounted for 97.75% of latency. - Production commit `b64e731b22584ca3030bfe8a96999e710f0a1d18`, 135 MB store: channel ingress completed in 199.10 ms with zero maintenance full-store materializations; stale cleanup completed at 332.63 ms. - Final candidate `a2c9c7ae4886980692f47e163a064291297e3d71`: the published Plugin SDK ingress, shipped `recordInboundSession`, exact-handle lifecycle, and changed maintenance regressions passed. - The published `runChannelInboundEvent` test fails on baseline because cleanup completes before dispatch; it passes on the repair and then observes stale cleanup complete. - A 337 MB head run completed channel ingress in 452.56 ms with zero maintenance full-store materializations; stale cleanup completed at 925.88 ms. - Independent final-runtime run on a 167 MB store, five samples: channel ingress averaged 5.438 ms; web preparation averaged 1.387 ms; full entry materializations stayed at zero; stale cleanup completed 5/5 at 169.37 ms mean. - Detached maintenance still performs two reference metadata projections after dispatch, measured at 139.0 ms on the 167 MB store. They no longer run inside or delay entry writes; indexed selection bounds full entry payload loading to changed candidates. - Input-size probes covered 33, 65, 129, 321, and 641 rows. ## Tests - `node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-maintenance-writer.test.ts src/config/sessions/session-history-eviction.test.ts src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts src/config/sessions/session-accessor.test.ts src/channels/session.test.ts src/channels/turn/run-channel-turn.pipeline.test.ts` - `node scripts/run-vitest.mjs src/plugin-sdk/channel-inbound.test.ts` - Focused CI repairs: 47 conformance, 88 agent session-store, 30 Plugin SDK session-store, 22 unchanged Gateway corruption/disposal, 11 handle-lifecycle, and 8 parent-fork tests passed. - Direct Oxlint and Oxfmt checks for all changed files. - Max-lines, assertion-safety, import-cycle, coercion-helper, deprecated-API, dead-export, database-first, schema-version, and conflict-marker guards. Host policy forbids local OpenClaw type-check and build commands. CI owns those checks. ## Scope and risk - Production: +464 / -205, net +259. - Tests: +349 / -72, net +277. - The production growth is the new coalesced owner, bounded candidate-query boundary, and exact-handle lifecycle fence. It removes 205 lines of synchronous and fail-stop paths; no smaller existing owner can retain fresh reruns, candidate selection, and archive-before-delete revalidation. - Explicit `sessions cleanup --enforce` remains synchronous and preserves its immediate semantics. - Sibling coverage includes shared channel ingress, Control UI/web preparation, explicit cleanup, physical disk-budget maintenance, dashboard archive ordering, protected sessions, lifecycle races, and session accessor behavior. Co-authored-by: Ayaan Zaidi <[email protected]>
Summary
Problem
Discord and Telegram channel ingress records metadata and last-route state before dispatch. Both writes synchronously ran logical maintenance in the store-writer queue. One stale candidate caused each write to materialize every
session_nodespayload.The Control UI
chat.sendpreparation path uses one exact-row lookup and does not run this two-write channel burst.Closes #135905.
Root cause
The entry accessor owned both the user write and the full maintenance plan. The maintenance owner first found a stale row, then called the unbounded full-store reader inside the serialized write transaction. The detached metadata write and awaited route write could both plan the same stale removal before finalization deleted it.
Fix
No configuration, schema, sidecar, freshness poll, production timeout, retry, or compatibility path was added. The implementation reuses the current SQLite projections, Kysely query layer, writer queue, and lifecycle fences; no external library or plugin fits this internal ownership repair.
Proof
Baseline:
914059d0a630685954d16a992c4105f924dc0e64.b64e731b22584ca3030bfe8a96999e710f0a1d18, 135 MB store: channel ingress completed in 199.10 ms with zero maintenance full-store materializations; stale cleanup completed at 332.63 ms.a2c9c7ae4886980692f47e163a064291297e3d71: the published Plugin SDK ingress, shippedrecordInboundSession, exact-handle lifecycle, and changed maintenance regressions passed.runChannelInboundEventtest fails on baseline because cleanup completes before dispatch; it passes on the repair and then observes stale cleanup complete.Tests
node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-maintenance-writer.test.ts src/config/sessions/session-history-eviction.test.ts src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts src/config/sessions/session-accessor.test.ts src/channels/session.test.ts src/channels/turn/run-channel-turn.pipeline.test.tsnode scripts/run-vitest.mjs src/plugin-sdk/channel-inbound.test.tsHost policy forbids local OpenClaw type-check and build commands. CI owns those checks.
Scope and risk
sessions cleanup --enforceremains synchronous and preserves its immediate semantics.