Skip to content

Index events to stop 300-900% CPU - #100

Open
SuperLogicAI wants to merge 3 commits into
mainfrom
fix/events-type-ts-index
Open

SuperLogicAI wants to merge 3 commits into
mainfrom
fix/events-type-ts-index

Conversation

@SuperLogicAI

@SuperLogicAI SuperLogicAI commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Two reads kept SQLite busy enough to show as 300-900% CPU in the Rust process.

  • listAttentionEvidence runs after every hook. With no index on events.type, each run scanned the whole table: 12-33 s on an 18 GB database. Runs in flight aren't cancelled, so they stacked until all 10 pool workers were busy.
  • eventsSince runs on every side-panel refresh and filters on ts alone. ts is stored after payload_json, so each run walked every row's overflow pages to reach it.

Migration 15 adds events(type, ts) and migration 16 adds events(ts). Nothing is deleted, and no query changes.

Query Before After
listAttentionEvidence 12.7 s 112 ms
listToolEvents 1.4 s 4 ms
lastLeft 235 ms under 1 ms
eventsSince, 1 hour 919 ms 8 ms
eventsSince, 7 days 1,560 ms 670 ms

Measured on APFS clones of the real database, warm cache, through node:sqlite. Output hashes matched, and the indexes built in 1.6 s and 1.0 s.

Verification

  • Live: sample during spikes pointed at each query in turn. Migration 15 alone took the installed app from 500-900% to 1-3% at idle and 30-300% with two agents, and applied in 1.29 s on the real database.
  • npm run check, npx tsc --noEmit, git diff --check
  • cargo test --lib (194 passed, 1 ignored), cargo clippy --all-targets -- -D warnings
  • New test hot_event_reads_use_their_indexes runs the real SQL from repo.ts. It failed with either index removed and passes with both.

Not verified

  • Migration 16 in the running app. That needs npm run reinstall; steps are in docs/TESTING.md.
  • Windows CI on the latest commit. The earlier failure was this PR's test matching a newline against a CRLF checkout, now fixed.

.logic-loop/board.md and the Phase 68 work stay out of this PR.

🤖 Generated with Claude Code

SuperLogicAI and others added 3 commits November 6, 2026 07:11
listAttentionEvidence runs after every hook, and with no index on
events.type each run scanned the whole table: 12-33 s on an 18 GB database.
Runs already in flight are not cancelled, so they stacked until all 10 pool
workers were busy, showing as 300-900% CPU in the Rust process.

Migration 15 adds events(type, ts). On a clone of that database the query
drops from 12.7 s to 112 ms with identical output, and listToolEvents from
1.4 s to 4 ms. Nothing is deleted. A new test pins that the query uses the
index and was confirmed to fail without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows checks repo.ts out with CRLF, so matching a literal newline failed
the new test there. The migration itself was unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With two agents running, CPU still reached 30-300% after migration 15. Spike
samples showed pread under getOverflowPage with JSON parsing near zero:
eventsSince filters on ts alone on every side-panel refresh, and ts is stored
after payload_json, so each run walked every row's overflow pages.

Migration 16 adds events(ts). On a clone, a 1-hour window drops from 919 ms
to 8 ms with identical output. The index test now covers both reads and was
confirmed to fail with the new index removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SuperLogicAI SuperLogicAI changed the title Index events by type to stop 300-900% CPU Index events to stop 300-900% CPU Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant