Repository navigation
Description
In OpenClaw 2026.6.5-beta.2 (and observed on 2026.6.1, repro on clean install with no hotfixes), the gateway main thread is pinned at ~95–100% CPU on most operations, including trivial CLI commands (e.g. openclaw cron list would time out at 30s) and the gateway's own /health endpoint (10s timeout).
perf record profiles show the hot native frame is node::sqlite::StatementSync::All in a tight JS loop. A V8 sampling profile (CDP capture, 25.36s, 22,940 samples) shows the JS caller is loadSubagentRegistryFromSqliteOnly at dist/subagent-registry-state-DxLh3f1M.js:872, called ~22×/sec from getSubagentRunsSnapshotForRead (line 929) which does loadSubagentRegistryFromSqlite() on every invocation — no cache, no interval, no rate limit. The query it issues is SELECT * FROM subagent_runs ORDER BY created_at ASC, run_id ASC (full table scan, no WHERE/LIMIT). Many read-side consumers (delivery, completion, route, registry-read) hit getSubagentRunsSnapshotForRead ~22 times per second, pinning a core.
Top 10 self-time frames = 96.99% of CPU, all in this read path:
all(V8 native sqlite binding) — 30.60% / 7,761ms / 6,960 hitsparseJson(subagent-registry-state:705) — 20.73% / 5,257ms / 4,898 hitsexecuteCompiledSqliteQuerySync(openclaw-state-db:135) — 18.40% / 4,666ms / 4,283 hitsrowToSubagentRunRecord(subagent-registry-state:743) — 11.69% / 2,964ms / 2,757 hitsmergeDeliveryState(subagent-registry-state:444) — 4.53%loadSubagentRegistryFromSqliteOnly(the hot leaf) — 2.34% / 553 hits- (garbage collector) — 2.29%
normalizeSubagentRunState— 2.65%createDeliveryFromTypedColumns— 2.13%normalizeDeliveryContext(delivery-context.shared:25) — 1.62%
Pruning the table from 984 → 498 rows (49% reduction) only reduced the read-path CPU from 97% → 77% — the call rate is the real cost driver, not table size.
Suggested fix: memoize the snapshot returned by getSubagentRunsSnapshotForRead. The snapshot only changes on subagent run start/end (which go through saveSubagentRegistryToSqlite, in the same module). Either:
- a 500ms–1s TTL cache (simple, ≤1s staleness for non-write consumers), OR
- event-driven invalidation: invalidate the cache inside
saveSubagentRegistryToSqliteafter each write (keeps read-after-own-write exact).
We applied a 500ms TTL + write-invalidation in our local build and saw CPU drop from 102% to 4% (a 25× reduction); trivial CLI commands went from 30s timeout to 1.5s, and /health went from 10s timeout to 0.7ms. The patch is reversible + dist-ephemeral; we'll carry it until upstream lands.
Sibling of CLOSED #75707 (its fix didn't cover this read path).
V8 profile: /tmp/openclaw-cpuprofile-kiz-1165-2026-06-08T16-46-35-513Z.cpuprofile (22,940 samples, 134 nodes).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 8, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 8, 2026, 6:31 PM ET / 22:31 UTC.
Summary
Keep open: current main and the latest release still read the full persisted subagent run table from the production snapshot path, so the reported CPU hotspot remains actionable and source-supported.
Reproducibility: yes. from source inspection: current main calls loadSubagentRegistryFromSqlite() on each production getSubagentRunsSnapshotForRead call, and that loader synchronously reads all subagent_runs. I did not run a live perf reproduction in this read-only review.
Next step
This is a narrow, source-backed performance repair with clear files and validation; no product or config decision is required.
Review details
Best possible solution:
Add a bounded process-local cache for persisted subagent registry snapshots with local write invalidation, short cross-process staleness bounds, and focused tests for read reuse and freshness.
Do we have a high-confidence way to reproduce the issue?
Yes from source inspection: current main calls loadSubagentRegistryFromSqlite() on each production getSubagentRunsSnapshotForRead call, and that loader synchronously reads all subagent_runs. I did not run a live perf reproduction in this read-only review.
Is this the best way to solve the issue?
Yes: a small process-local snapshot cache with local write invalidation and a short staleness bound is the narrowest maintainable fix for the repeated-read driver. A pure event-invalidation cache would be too narrow because other processes can write the SQLite rows.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against c967172f694e.
Label changes
Label changes:
P1: The report describes a current gateway availability problem where high CPU causes health checks and ordinary CLI operations to time out.impact:crash-loop: The issue affects process availability by pinning gateway CPU and causing health checks and CLI commands to hang or time out.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:queueable-fix: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state selects this label.Label justifications:
P1: The report describes a current gateway availability problem where high CPU causes health checks and ordinary CLI operations to time out.impact:crash-loop: The issue affects process availability by pinning gateway CPU and causing health checks and CLI commands to hang or time out.Evidence reviewed
Acceptance criteria:
What I checked:
src/agents/subagent-registry-state.ts:46, c967172f694e)src/agents/subagent-registry.store.sqlite.ts:254, c967172f694e)src/infra/kysely-sync.ts:27, c967172f694e)src/agents/subagent-registry-read.ts:25, c967172f694e)src/agents/subagent-registry-state.ts:42, 2e08f0f4221f)src/agents/subagent-registry.persistence.test.ts:416, c967172f694e)Likely related people:
src/agents/subagent-registry.ts)src/agents/subagent-registry.ts)src/agents/subagent-registry.store.sqlite.ts,src/state/openclaw-state-schema.sql)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.vincentkoc commentedon Jun 9, 2026
Fixed on main in c4a0ca0.
Behavior changed:
getSubagentRunsSnapshotForReadnow reuses the persisted subagent registry snapshot for a short bounded window, refreshes the local cache after successful writes, and still overlays in-memory runs on every read. Cross-process updates are bounded by the TTL instead of forcing every hot read through a full synchronous SQLite table scan.Proof run:
node scripts/run-vitest.mjs src/agents/subagent-registry-state.test.ts src/agents/subagent-registry.persistence.test.ts src/agents/subagent-registry.announce-loop-guard.test.ts src/agents/subagent-registry.store.sqlite.test.ts src/agents/subagent-registry.test.ts— 1 shard, 5 files, 88 tests passed..agents/skills/autoreview/scripts/autoreview --mode local --base origin/main— clean; no accepted/actionable findings.blacksmith-testbox, idtbx_01ktmz2dftmr76xn9cajamvjvh, Actions run27177469692, commandcorepack pnpm check:changed, exit 0.Closing as fixed.