Repository navigation
perf(sessions): aggregate validated inventory counts - #146158
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 12, 2026, 12:08 PM ET / 16:08 UTC. ClawSweeper reviewWhat this changesThe PR reduces temporary allocations when counting stored sessions by aggregating validated entries in SQLite while preserving parsing and archive filtering for raw entries. Merge readiness✅ Ready for maintainer review The optimization remains useful: current main and the latest release still count validated sessions row by row. No introduced correctness or security defect was found, and the protected maintainer PR should remain in the normal landing workflow. Priority: P2 Review scores
Verification
How this fits togetherSession inventory reads OpenClaw’s per-agent SQLite database and supplies counts to maintenance planning and lifecycle reporting. Validated entries can be counted directly; raw entries still require the existing JSON parser. flowchart TD
A[Per-agent session database] --> B[Archive filter]
B --> C[Validated entries]
B --> D[Raw entries]
C --> E[SQLite aggregate]
D --> F[Existing JSON parser]
E --> G[Combined session count]
F --> G
G --> H[Maintenance and lifecycle reporting]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +35, Tests +35. Total +70 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep counting inside the existing inventory owner, using SQLite aggregation for validated rows and the established parser for everything else. Do we have a high-confidence way to reproduce the issue? Not applicable as a correctness-bug reproduction: this is a performance optimization, and source confirms the existing per-session materialization. The PR supplies bounded before/after allocation measurements. Is this the best way to solve the issue? Yes. Aggregating the existing validated partition preserves one-statement consistency and raw-parser behavior without adding persistence or another counting owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 28c97ff7b97a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
Session inventory counting materializes one JavaScript row per stored session even when the writer has already validated the entry. Maintenance and lifecycle counts repeat this work on populated Gateways.
Why This Change Was Made
Aggregate writer-validated rows in SQLite and stream the remaining raw rows through the existing JSON parser. Both branches share one SQL statement and the same archive filter. Cache the two compiled query shapes weakly by connection; the existing iterator still owns each private native statement. No session data, schema, writer, transaction, retention, or recovery behavior changes.
User Impact
Counting a large session store allocates substantially less temporary memory. Empty stores, archived entries, raw writes, malformed JSON, and retained placeholders keep their existing count semantics.
Evidence
The actual count owner was measured on parent6d0c1c9fcf5a and the candidate using synthetic owner-written sessions, 1,000 reads per case, and identical expected counts:
These are bounded allocation samples. Instrumented wall times varied, including a slower empty-store sample; they do not establish a general latency or retained-memory improvement.
All219 tests passed across session accessors, cache/data-version behavior and raw-row/exclusion contracts. The added mixed validated/raw/archive case also passes the original implementation. During development, these tests caught and rejected an incorrect UNION column order; the final query selects the same columns in both branches. Fresh independent P0-P2 review is scoped-clean. Formatting and whitespace pass; changed-lane planning selects core and core tests. Aggregate local checks remain unrun after host resource exhaustion; exact-head hosted CI 34703977545 passed all required checks.
Connection-lifetime proof exercised both compiled modes on 30 actual owned database connections, closed their owners, and observed zero retained connections after garbage collection. This verifies cache lifetime without claiming a retained-memory size reduction.