Repository navigation
perf(sessions): keep agent-database transactions off the Gateway main thread - #163053
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 changes before merge. Reviewed October 2, 2026, 2:36 AM ET / 06:36 UTC (Revision 3). ClawSweeper reviewWhat this changesMoves full-history recovery, usage, and MCP App reconstruction into existing database workers, enables prepared custom-message appends, and adds transaction diagnostics and a benchmark. Merge readiness⛔ Needs changes before merge - 1 item remains This PR still addresses blocking transcript scans present on current main. No actionable introduced correctness or security defect was found, and the previous test-type concern is cleared by successful current-head checks. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores session transcripts in per-agent SQLite databases. Gateway and agent callers read recovery, usage, and app-reconstruction facts from those transcripts; database workers perform the scans and return the selected results. flowchart TD
A[Gateway and agent requests] --> B[Transcript read owner]
B --> C{Process-held incognito database?}
C -->|Yes| D[Native snapshot reader]
C -->|No| E[Admitted history worker]
D --> F[Transcript selectors]
E --> F
F --> G[Recovery usage and app facts]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +162, Tests +196, Docs +27, Config +1, Other +196. Total +582 across 46 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep transcript selection and asynchronous appends with their existing admitted workers, preserving native incognito ownership and synchronous SDK contracts. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main's full recovery and usage selectors traverse native SQLite snapshots, and the supplied large-history benchmark provides a concrete trigger. This review did not execute it. Is this the best way to solve the issue? Yes. Reusing the admitted history worker and shared snapshot selectors avoids a competing database owner or summary cache while preserving existing contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 25fbb38f16bd. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
… thread Full-history recovery checkpoints, usage aggregation, MCP App reconstruction, restart-tombstone recovery and runtime custom-message writes still reached the agent database through native callback paths on the main thread, holding transactions for seconds on large stores. Route them through the existing database workers, keep tombstone recovery atomic through the canonical agent writer, and add prepared session identifiers and event counts to the slow-hold diagnostics.
4058c9e to
133554c
Compare
…ent-database holds bench
…penclaw#163053) * perf(sessions): keep agent-database transactions off the Gateway main thread Full-history recovery checkpoints, usage aggregation, MCP App reconstruction, restart-tombstone recovery and runtime custom-message writes still reached the agent database through native callback paths on the main thread, holding transactions for seconds on large stores. Route them through the existing database workers, keep tombstone recovery atomic through the canonical agent writer, and add prepared session identifiers and event counts to the slow-hold diagnostics. * fix(scripts): forward overloaded sqlite statement arguments in the agent-database holds bench
What Problem This Solves
Full-history recovery checkpoints, usage aggregation, and MCP App reconstruction can hold SQLite read transactions on the Gateway main thread and delay unrelated requests. This change sends those selectors through the existing admitted history worker and returns compact facts from one snapshot, including both MCP reconstruction passes. It adds prepared diagnostic context without extra queries or transcript payloads.
Schemas, stored bytes, retention, configuration, permissions, and update behavior are unchanged. Process-held incognito reads and shipped synchronous SDK contracts retain their existing owners. No summary cache or busy-worker synchronous fallback is introduced.
Why This Change Was Made
The branch was rebased onto main
b21e522e2ad1, retaining only this lane's remaining changes. Main already provides the canonical restart-tombstone recovery worker and asynchronous custom-entry/message writes. Their overlapping branch implementations were removed during conflict resolution, preserving main's authority checks, FIFO admission, atomic recovery, and uncertain-outcome handling.The failed
mainRestartRecoveryreference was privateInternalSessionEntry.mainRestartRecovery, not a field to add to publicSessionEntry. The redundant recovery kernel and registration are gone; the existing recovery worker owns that state. The benchmark preserves and restores typed native method descriptors and explicitly cancels its sampler. Its package command makes the executable discoverable to dependency analysis.The original CI logs also identified a missing worker error-encoder import, a type import cycle through the sessions barrel, and tests using a worker thread where the host database broker requires the existing process-based test owner. These are repaired without changing performance semantics. The oversized spawn fixture's cache-TTL mock reader is moved into its existing mock helper.
Measurements
Historical performance evidence from this lane used Blacksmith Testbox, Node 24.19.0, baseline main
7cbaa6b36f15, 10,000 messages with 4 KiB payloads, and 2,000 other sessions. These are earlier before/after measurements, not a fresh comparison against the newer rebase base.The original benchmark's wall time was 17.49 → 18.15 s and peak RSS 1,701,484 → 2,023,324 KiB. Moving blocking work does not promise lower write latency; the original tombstone wall time increased about 20%, and first append included cold worker startup. Reproduce via
pnpm bench:agent-database-holds 10000 2000.The earlier negative controls failed on native host-thread SQL for history, tombstone recovery, and custom messages. The history regression uses 1,204 messages and verifies checkpoint, usage, and MCP facts with no host transcript SQL. Existing runtime tests cover message publication, ancestry, rollback, and current authority. No live Gateway was changed.
Evidence
Blacksmith Testbox provider
blacksmith-testbox, profileopenclaw-check, leasetbx_01m3xhc9sejka6715p4rp4ht9n, workflow run https://github.com/openclaw/openclaw/actions/runs/36969110674.The first lease installed dependencies and exposed two diagnostic-option type errors in the rebased candidate; those are repaired. A subsequent native full sync timed out before executing its payload, and that lease was stopped. Replacement lease
tbx_01m3xhym6f83tkz5616ak0dd33stayed queued from 05:38:48Z through the final 06:08:50Z status check on 2026-10-02. The first run hit the native 15-minute admission limit; after backoff, the retry remained queued through the 30-minute window. It never received a runner or workflow URL, and neither attempt executed its payload. Both task leases are stopped. No final passing remote result is claimed.Independent Codex review passed with
scoped-cleanand no actionable P0/P1 findings for the staged candidate, including the unchanged recovery-owner contracts. The reviewer explicitly treated queued validation as unverified. The earlier CI run36936592386on4058c9ec9c06failed; its results are not current-head evidence. This prepared body is not a claim of publication.Remaining work
The branch was rebased onto current main (merge base
9646ebea2497) and published as the exact head CI tests; the lane's final Testbox proof run was blocked by Testbox admission, so the hosted CI run on this head is the completion gate for the full changed-file checks. The Blacksmith Testbox measurements above are historical (taken on the pre-rebase head against the same owners) and are labeled as such. Thecheck-test-typesfailure on the previous head (bench script forwarding into the overloaded nativeStatementSyncmethods) is fixed on this head.