Repository navigation
improve: reduce overhead when counting transcript events - #149238
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 15, 2026, 3:02 PM ET / 19:02 UTC (Revision 10). ClawSweeper reviewWhat this changesReuse compiled transcript-count queries with fresh session and reset values, and extend tests for counts across sessions and appends. Merge readiness✅ Ready for maintainer review This remains a useful optimization beyond the merged scalar-count work. No actionable correctness or security defect was found, and the documented acceptance of timing uncertainty resolves the earlier decision concern. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw counts visible transcript events when Gateway updates need a fallback sequence number. The SQLite history reader combines visible messages and markers within one validated read snapshot. flowchart TD
A[Transcript update] --> B[Fallback count reader]
B --> C[Validated SQLite snapshot]
C --> D[Choose marker, branch, or reset query]
D --> E[Reuse compilation with fresh bindings]
E --> F[Count visible events]
F --> G[Gateway sequence number]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +61, Tests +13. Total +74 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the shared visibility predicate and snapshot owner while reusing bounded compiled query forms through the existing SQLite executor. Do we have a high-confidence way to reproduce the issue? Not applicable to a correctness bug: current-main source directly shows repeated query construction, and the supplied public-reader comparison measures its removal. Is this the best way to solve the issue? Yes. The patch reuses the established compilation helper while preserving fresh bindings, shared selection semantics, and native execution ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against eee60cd68fc0. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
216eb4b to
f772cd6
Compare
f772cd6 to
4919a0f
Compare
Related: #146371
What Problem This Solves
Repeated transcript count reads rebuild the same SQL query trees even when only the session or reset bound changes.
User Impact
Transcript-update fallback counts do less repeated JavaScript work. Counts, visibility, errors, cold restoration and read snapshots retain their existing behavior; no operator action is needed.
Why This Change Was Made
Lazily retain three compiled count-query forms per physical database connection and supply fresh session/reset bindings on every read. The full history reader and count reader still share the same selection predicate and index choices. Native statements and their lifecycle remain with the existing SQLite executor; no rows or authorization results are cached.
Evidence
One complete public-facade comparison on Node 26.8.2 / SQLite 3.53.4 against main
067c75b8aa65607a41d0a5b7cd102d80eec33bd6passed all 14 timing cells, two branch cells, 14 malformed-data cells, two real cold restorations, and 70 reads across 13 shared-database binding/lifecycle checkpoints. Each timing cell used three warmup pairs and 21 alternating blocks. SQL, runtime bindings and native query plans match exactly; warm count-query compilations drop from one to zero while each native count query still executes once.The one-marker medians were 1.443 → 1.327 ms before ANALYZE and 1.468 → 1.307 ms afterward (8.1–10.9% less elapsed time). Larger marker fixtures showed smaller observed reductions; the unchanged message-only path varied by roughly ±1%, including a 1.0% regression. Concurrent source-review and Git worktree-copy I/O overlapped this run, so the precise timing differences cannot be isolated from that interference. All samples were retained; no timings were retried or discarded. These are warm synthetic reader measurements, not whole-Gateway throughput or production latency guarantees.
Read-interval schema, typed rows, integrity and persisted database/WAL/journal hashes stayed unchanged. Four sessions share one database in the extra checks, covering fresh session/reset bindings, branch changes, append/replace, ANALYZE, message-only transitions, a new physical handle after close/reopen, and writes after reopening. Cold restore intentionally writes and preserves exact canonical event rows.
Independent review completed with no actionable P0–P2 findings and verified unchanged source. The focused Windows run passed all 28 tests across history-events, history-query-plan, history-marker-gap, and history-window on original head
216eb4bae64a36ce6165d3110aeb64859c252610. The current head4919a0f6b6f968508ae2a8063b09ff249f6d8d42is rebased onto main273b6c5e11462e309ade080d620a03b9fb5021ca; range-diff reports a patch-identical change, and both touched files, the public history readers, and dependency pins retain their exact bytes. This preserves the independent review and focused proof for the unchanged patch.Current-head CI run 35006650770 has passed all 12 relevant static jobs, covering production/core-test types, lint, schema, architecture, dependencies, and baseline guards. These exact-head hosted results cover the larger checks under local host scheduling constraints. The local changed-check command was inspected in dry-run mode; no full local-controller pass is claimed. All seven supplemental guards passed locally on current head 4919a0f: changelog attribution, extension and SDK wildcard exports, dependency pins, plugin boundaries, media helper use, and runtime sidecar loaders. Targeted formatting and whitespace checks also passed; the source remained clean and the check processes exited. Current-head CI run 35006650770 completed successfully, including the required openclaw/ci-gate (job 104525395303). All five previously failing fixture shards and both Windows jobs passed on this head.
The timing uncertainty identified in review is accepted for this bounded compilation change. Its acceptance criterion is the directly verified removal of repeated query construction (one warm count-query compilation becomes zero), exact SQL/binding/plan equivalence, preserved public behavior, and passing required gates. The retained three query forms per connection are the explicit memory tradeoff. The shared visibility predicate, snapshot owner, invocation-local bindings, and native executor already implement the review's proposed mitigation. Whole-Gateway latency improvement and an isolated percentage speedup are not established or required for this change; the timing table remains descriptive evidence with its interference disclosed.
The previous CI failures were outside the count change. The refreshed base includes the canonical QA fixture repair #149243, native PR fixture repair #149294 (
7dc8a1e79659afb833df4bbfe363744c8d775e5c), and Codex model-attribution fixture repair #149301 (273b6c5e11462e309ade080d620a03b9fb5021ca). Both latter repairs have merged after their required CI passed. No failing or cancelled job is counted as a passing gate. The final integrated-main measurement below completed after the verified merge.Final integrated measurement
Merged as
5b1912fd0cd3d574db201506f31e234c1a983f5c. One fixed comparison on that clean commit, Node 26.8.2 / SQLite 3.53.4 / Windows x64, passed all 14 timing cells, two branch cells, 14 malformed-data cells, two real cold restorations, and 70 fresh-binding/lifecycle reads. The three complete reader-owner modules match the reviewed candidate, and recorded shared dependencies and package pins match the before-owner baseline067c75b8aa65607a41d0a5b7cd102d80eec33bd6.The run used three warmup pairs and 21 alternating blocks per cell. All 588 timed block samples were retained; no retries or samples were discarded. The coordinator held other application benchmarks, tests, builds, installs and source snapshots for the run. Ordinary OS activity, lightweight coordination and saved-data audits remained possible. The process ran from 19:38:05.941Z to 19:39:27.439Z on September 15, 2026, exited 0, and left no direct children; source, dependency and harness checks passed after it settled.
One-marker medians were 6.8–8.0% lower and reset-prefix medians 4.5–14.6% lower. The analyzed consecutive-marker case was 2.1% slower, and the unchanged message-only path was 0.3–1.6% slower. All adverse results remain visible. These are descriptive warm synthetic medians, not isolated population estimates, p95 guarantees, whole-Gateway throughput, or a comparison of absolute timings across runs.
All 12 marker-containing cells again reduced warm count-query compilation from one to zero while retaining one native execution and one aggregate row. SQL, fresh bindings, query plans, counts, errors and read-interval storage fingerprints matched. Cold restoration intentionally writes and preserved exact canonical rows. No concurrent-writer race or cold-latency speedup is claimed.