Skip to content

Fix 4 problems from the log (db, runner, perf) - #262

Merged
danielehrhardt merged 1 commit into
mainfrom
godmode/69-fix-4-problems-from-the-log-db-runner-pe
Oct 29, 2026
Merged

danielehrhardt merged 1 commit into
mainfrom
godmode/69-fix-4-problems-from-the-log-db-runner-pe

Conversation

@danielehrhardt

Copy link
Copy Markdown
Contributor

I fixed the two slow database queries behind the "slow database query" warnings, which were also the main recorded cause of the "event loop blocked" warnings. The other three problems were the network and the Mac sleeping, not the code. Core tests, typecheck and the merge of origin/main are clean.

Changes

Chat list query (packages/core/src/services/conversations.ts)

  • Cause: listConversations computed the preview for every chat before it sorted and cut the 100-chat page. That is 824 chats today (924 in the archive), and the list grows. This query was 11 of the slow-query warnings and 14 of the recorded blockers of the event loop (5.7 s in total, up to 1.5 s at once).
  • Fix: the query now picks the page first (WHERE c.id IN (SELECT ... ORDER BY ... LIMIT ?)) and builds the preview and the other derived columns only for the chats on that page.
  • Effect: run read-only on the real database, it returns the same rows, active and archived. It is about 5x faster with a warm cache: 4.2 ms down to 0.8 ms (archived: 5.8 ms down to 1.3 ms).

Unfinished runs query (packages/core/src/runner/runner.ts)

  • Cause: listRuns with status=queued,running,paused, which the desktop app and the computer-to-computer mirror ask for, went through every run by date instead of using the status index. That was the 146 ms warning.
  • Fix: when only unfinished statuses are asked for, it sorts by +created_at, so SQLite finds those few runs through idx_runs_status and sorts them. Other filters work as before.
  • Effect: read-only on the real database, 1.9 ms down to 0.01 ms with a warm cache.

Tests

  • conversations.test.ts: a limited page keeps pinned-first order and the right previews.
  • runner.test.ts: a new listRuns test covers unfinished and finished status filters, newest first, with ties broken by insert order and with a limit.

Not code bugs, left unchanged

  • 4 × run failed ... ENOTFOUND (19:48–20:03Z): the internet was down. The link to the other computer came back at 20:03:49 and Godmode restarted the 4 broken-off runs by itself at 20:04:10.
  • 4 × browser CDP connection closed: each one happened about 18 s before the Mac went to sleep (08:54:52, slept 08:55:14; 10:06:47, slept 10:07:04). Two browsers closed at the same moment at 08:54:52. The browser starts again the next time it is used.
  • 4 × event loop blocked (16:02–17:01Z, 408 ms to 1.1 s): 4 long runs were working at the same time. The worst at 17:00:45 had only 66 ms of measured work behind it, so the rest has no recorded cause. The chat-list fix removes the main blocker seen across the whole log.

Checks

  • pnpm -r typecheck passes.
  • These test files pass: conversations.test.ts, runner.test.ts, remote-mirror.test.ts and tasks.test.ts (153 tests, 0 failing).
  • I merged the latest origin/main. It had no new commits, so there were no conflicts.
  • Everything is in one commit, 29c1dff9.

Nothing for Daniel to do.


Task #69 · done by Self-Healer with Godmode Bot

…ns by status

The chat list computed the preview, pause and handover columns for every chat before sorting and cutting the page,
so its cost grew with all chats instead of the 100 shown. The runs list with only unfinished statuses walked every
run by date because the planner preferred the created_at index for the ORDER BY.
@danielehrhardt
danielehrhardt merged commit e9627e9 into main Oct 29, 2026
1 check passed
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