Repository navigation
fix: reduce repeated SQLite work in session operations - #148366
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: needs maintainer review before merge. Reviewed September 14, 2026, 5:52 PM ET / 21:52 UTC (Revision 8). ClawSweeper reviewWhat this changesReduces repeated SQLite reads during session cleanup, transcript searches, and ACP replay recording, and corrects synchronization in supporting tests. Merge readiness✅ Ready for maintainer review Keep open: the retained optimizations remain useful and are absent from current main. No blocking correctness or security defect was found; the component measurements and verified hosted CI support the patch. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores session transcripts and replay history in SQLite. Cleanup requests, transcript searches, and agent-client updates enter these storage owners, which return search results or maintain retained history. flowchart TD
A[Session operations] --> B[SQLite storage owners]
B --> C[Cleanup age checks]
B --> D[Scoped transcript search]
B --> E[Replay sequence bounds]
C --> F[Preserved cleanup eligibility]
D --> G[Visible search results]
E --> H[Exact trimming and byte accounting]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +14, Tests +38. Total +52 across 9 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep the optimizations within the existing storage owners while preserving exact retention, search visibility, and generation semantics. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional defect: this is a behavior-preserving optimization with supplied comparative SQLite measurements; the broader Gateway-stall report was not reproduced here. Is this the best way to solve the issue? Yes: the patch removes avoidable work without introducing indexes, stored counters, competing owners, or changed retention rules. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d1e00bdd979c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
ea2b84a to
35e25d6
Compare
3467dad to
09e255d
Compare
f4ea60a to
a0b226d
Compare
a0b226d to
cbdcd26
Compare
|
Merged via squash.
|
* perf(sessions): reduce redundant SQLite scans * style(acp): avoid shadowed query builder names * test(ui): exercise session eviction through the wizard choice button * test(ui): wait for the current publication subscription * test(ci): protect wizard recovery broker routing Retain the routing regression from openclaw#148442 while inheriting the canonical registration repair in openclaw#148504. Require one infra registration and exclusion from the thread-based wizard project.
Related: #138042, #148057, #148442, #148445, #148504
What Problem This Solves
Cleanup, exact-session searches, and ACP replay appends repeat SQLite work over unrelated or already-protected history as stores grow.
User Impact
Reduces synchronous CPU spent on large session stores while preserving search visibility, cleanup eligibility, replay limits, and byte accounting. No schema change, new index, migration, configuration option, or retention change.
Why This Change Was Made
Cleanup rejects recently updated nodes before scanning transcript timestamps. Exact-session search narrows its dirty-state lookup to the selected session, and transcript generation creation stops reading back an unused value.
ACP replay uses indexed minimum/maximum sequence values to exclude histories that cannot exceed the event cap. Possible overflows still receive an exact count, preserving gapped sequences and stricter limits after reopening.
Evidence
Synthetic CPU measurements on Node 26.8.2 / SQLite 3.53.4, using existing canonical indexes:
Complete result comparisons passed for 6 cleanup shapes, 144 FTS cells, and 9 replay fixtures. The paired replay comparison used one warmed connection, seven alternating pairs of 40 appends, identical seeding, and 21 matching retained-row fingerprints. Its 100,000-event fixture is about 14.4 MB, with an explicit larger byte cap to isolate event-count work. Final emitted ACP SQL matches the measured query exactly.
These are component measurements. The search reconciliation preflight remains a separate cost (6.810 ms in the clean 10,000-state fixture). Removing the unused generation read has no reliable latency claim. A blanket search
NOT EXISTSrewrite and a fixed-status partial-index rewrite were rejected after opposite workloads regressed, including a 17× slowdown for a recent delivery hit.The retained SQL and Custodian source passed 192 focused cases: 142 session/ACP/recovery cases and 50 Custodian cases. After inheriting the canonical CI repairs, another 128 selected routing, recovery, auth, integration, and boundary cases passed. All 45 browser E2E cases across the six publication-helper consumers passed with the final dependency installation. Relevant changed-file gates, typechecks, lint, formatting, and independent P0–P2 reviews passed. Required hosted CI passed on the reviewed head.
Inherited fixes and test synchronization
Inventory counting through compact indexes is already on main (#148445), so this PR removes its superseded count change. All 20 actual-owner comparisons preserve expected counts. The retained SQL changes use existing owners and indexes.
Main also contains the canonical provider-integration and wizard-routing repair (#148504). The five scoped-config assertions reused from #148442 protect exactly one broker-backed recovery registration and exclusion from the thread-based wizard project. The new regression failed with the missing registration and passes with the canonical repair. The Custodian test waits for the enabled immediate-submit choice button introduced on main; its lifecycle assertions remain intact.
The publication LRU fixture could emit branch state for a previous session after navigation because it searched older requests even when the latest subscription was empty. An identical delayed-startup browser diagnostic fails before and passes after the fixture correction, while preserving the original publication retry parameters. The helper now honors only the latest subscription and waits for the selected session. Assertions and timeouts are unchanged; there are no production UI changes.