Repository navigation
improve: reduce repeated work loading session history - #153161
Conversation
Reuse the message-query owner, keep archive fallback policy in the transcript kernel, and avoid parsing saved prompts for boolean presence checks. Preserve bounded reset-tail chunks and cache lifetime guards. Local synthetic latest-message p50 improves about 22%; other latency results are mixed. Refs #153160.
|
🦞👀 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 19, 2026, 4:58 PM ET / 20:58 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR reuses session-history queries, reads smaller session metadata for presence checks, and decompresses retained archives only when examined. Merge readiness✅ Ready for maintainer review The PR remains useful: current main retains repeated query construction and the unused archive-reader mode. Source review found no actionable introduced defect, and the previous review has no outstanding findings. Priority: P2 Review scores
Verification
How this fits togetherGateway history requests read session messages from SQLite, with the transcript kernel deciding when retained reset archives may supply fallback history. These readers return bounded message pages and metadata to history consumers. flowchart TD
A[History request] --> B[Transcript read kernel]
B --> C[SQLite snapshot]
C --> D[Shared message queries]
D --> E[Bounded history results]
B --> F[Archive fallback decision]
F --> G[Read selected reset archive]
G --> E
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -108, Tests -79. Total -187 across 10 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep query compilation and archive fallback with their existing owners while preserving history ordering, byte caps, snapshot boundaries, and stored formats. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional bug: this is an efficiency cleanup. Repeated work is visible in main's source, and the body supplies synthetic comparisons; this review did not execute benchmarks or tests. Is this the best way to solve the issue? Yes. Reusing existing query and metadata owners and removing a production-unused archive mode is a focused simplification without a new API, schema, or configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a8046858b9ea. LabelsLabel 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)
|
* perf(sessions): reduce repeated history reader work Reuse the message-query owner, keep archive fallback policy in the transcript kernel, and avoid parsing saved prompts for boolean presence checks. Preserve bounded reset-tail chunks and cache lifetime guards. Local synthetic latest-message p50 improves about 22%; other latency results are mixed. Refs openclaw#153160. * refactor(sessions): build numeric set reads through Kysely
Closes #153160. Continues #153010.
What Problem This Solves
Session-history reads still rebuild repeated queries, parse saved prompts for presence checks, and decompress an archive they may never examine.
User Impact
History behavior stays the same, with less latest-message query construction and smaller presence-read payloads. No schema changes, migration, or operator action is required. Component latency is mixed; this is not a claim of uniformly faster history or measured live Gateway latency.
Why This Change Was Made
Reuse the existing message-query owner and compiled readers, remap imported controls with indexed set lookups, and keep archive fallback policy in the transcript kernel. The archive reader now serves only retained reset archives, matching every production caller. Anchored reads materialize each candidate when examined.
Net 108 production lines and 79 test lines removed. Existing 500-position retained-message chunks remain because packing the entire range made a byte-capped early exit 4.5× slower. Cache lifetime, database ownership, reset visibility, byte caps, and retention remain unchanged.
Evidence
Local synthetic before/after measurements on Node 24.21.0 / SQLite 3.53.4:
The range matrix uses medians of four round percentiles; presence uses ABBA processes; archive stability uses 1,000 interleaved AB/BA pairs after 100 warmup pairs. Shared-host timings vary. Statement, parsed-byte, and decompression counts describe the concrete work changes more reliably.
Validation: 390 focused tests across 22 files passed, followed by 137 affected tests across 10 files after final refinements. Baseline archive suites passed 90 tests. Final changed-code gate passes, including typechecks, lint, dead-code scans, and storage guards. Additional experiments checked 33 range comparisons, 402 sparse-control comparisons with index-plan assertions, 18 presence behavior cells, and 2,201 archive-result comparisons. Independent P0–P2 review passed with no actionable findings.
Hosted CI caught an additional Kysely guard violation in the numeric-set SQL. The follow-up uses the existing structured table-valued-function pattern. All 33 comparisons pass again, with identical statement and returned-row counts across 26 workloads; the repository-wide Kysely guard, core typecheck, and targeted lint now pass. The timing table predates this equivalent query-construction rewrite; latest-message, presence, and archive execution paths are unchanged.