Repository navigation
fix: avoid slow task lookups and maintenance as history grows - #153548
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: blocked before merge. Reviewed September 20, 2026, 5:43 AM ET / 09:43 UTC (Revision 4). ClawSweeper reviewWhat this changesAdds three SQLite indexes and reduces cleanup-query work so task ownership checks, session counting, and maintenance handle growing history more efficiently. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: the narrowed patch provides useful improvements still absent from main, and the current compatibility evidence addresses the earlier review concern. No actionable correctness or security findings remain. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores task and worker records in its shared SQLite database and session records in per-agent databases. Recovery and maintenance query these records to identify ownership, count readable sessions, and retain completed-operation results. flowchart TD
A[Task and session history] --> B[SQLite databases]
C[Canonical writable schema owner] --> D[Three nonunique indexes]
D --> B
B --> E[Ownership and session queries]
B --> F[Scoped cleanup and byte accounting]
E --> G[Recovery and session counts]
F --> H[Retained results and receipts]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +32, Tests +385, Docs +11, Generated 0. Total +428 across 24 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: 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 optimization within the existing database owners, preserving stored bytes, retention decisions, and compatible reopening. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main hydrates retained inference payloads for byte counting and lacks the added lookup indexes. The supplied benchmarks and regression coverage support the mechanism; this read-only review did not execute a reproduction. Is this the best way to solve the issue? Yes. The narrowed patch reuses canonical schema repair and preserves query semantics, while dropping expression indexes made unnecessary by merged identifier normalization. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1bbd60d9c2b2. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Add compatible nonunique lookup indexes through canonical schema repair and preserve state 17 / agent 21. Scope receipt pruning by queue and avoid hydrating inference outcomes for UTF-8 byte accounting while retaining UTF-16 semantics. Storage design: #153533. Release notes: faster task lookup, session recovery, and maintenance as retained history grows; no payload or retention changes.
bf82b91 to
a33c16a
Compare
|
Merged via squash.
|
…aw#153548) * perf(sqlite): avoid retained-history scans and payload reads Add compatible nonunique lookup indexes through canonical schema repair and preserve state 17 / agent 21. Scope receipt pruning by queue and avoid hydrating inference outcomes for UTF-8 byte accounting while retaining UTF-16 semantics. Storage design: openclaw#153533. Release notes: faster task lookup, session recovery, and maintenance as retained history grows; no payload or retention changes. * refactor(sqlite): project retained turn fields explicitly * test(sqlite): keep legacy fixtures free of later indexes * test: keep historical SQLite fixtures version accurate * perf(sqlite): reuse normalized task identifier indexes
What Problem This Solves
Task ownership checks, session recovery, and maintenance perform unnecessary database work as retained history grows. Scoped delivery cleanup scans unrelated queues, and inference retention loads cached payloads merely to count their bytes.
User Impact
Reduces database work while preserving matching, ordering, ownership checks, retention, and stored payloads. State schema 17 and agent schema 21 stay unchanged. The first writable open installs three nonunique indexes through canonical repair; later writes maintain them. Older same-version readers can ignore them.
Why This Change Was Made
The indexes cover requester ownership, placement environment, and exceptional session-validity predicates. Queue-scoped receipt pruning exposes its existing queue index to the planner. Inference pruning reads identity, time, and byte counts instead of payloads on UTF-8 stores; UTF-16 stores retain the existing UTF-8 accounting behavior.
Main's #153467 normalized run and child-session identifiers and made their existing indexes usable. This PR uses that implementation and adds no expression indexes for those identifiers. The accepted remaining storage decision is #153533. Compression and canonical payload redesign are separate follow-up work.
Evidence
a33c16a8efbe3cd9938fa2d73efbb6358ba2735f.Synthetic in-memory SQLite 3.53.4 / Node 26.8.2 measurements against current main, 25 warm samples after five warmups:
The two shared-state indexes added about 2.50 MB of SQLite page allocation and built in about 43 ms. Inserting 1,000 synthetic tasks in a rolled-back transaction increased from 7.18 ms to 7.81 ms. The normalized scoped task lookup was already indexed on main and stayed approximately unchanged. These are local microbenchmarks under variable host load, not end-to-end or live-Gateway latency forecasts. Query plans establish the removal of unrelated scans independently of timings.