Repository navigation
Description
What happened
On a long dispatcher thread (13,369 runs), each step still parses the whole thread on the server. Accepting a delegated child's completion spends about 9 s in reads before the parent wakes, and every turn start spends about 3.3 s. The server's event loop also stalls for 2–16 s about ten times an hour, with no output, MCP replies or provider events for any thread during a stall.
Diagnosis
Both paths read the thread's full record sets on main 5385 (v0.1.14-nightly.20261128.5385):
dispatchNotificationAccepted(Orchestrator.ts) callsgetProjectionWithPendingEvents, the command projection: every user message, every node that is not a settled leaf and the user and error turn items of the thread.acceptDelegatedCompletionDeliveryuses one message, its parent run and the tasks that run can claim or deliver.getTurnStartContext(ProjectionStore.ts) reads every run, every run attempt and every provider turn of the thread (WHERE thread_id = ? ORDER BY …).
The rows are read on a reader worker, but the event loop decodes them. The largest thread's payloads total 15.8 MB of runs, 9.4 MB of run attempts, 17.5 MB of provider turns, 56.5 MB of messages and 89.7 MB of nodes. In 109 of the 201 stalls the traces cover, a server.heap.spike (128 MB or more) landed in the same 30-second sample. Its suspects include orchestrationV2.providerTurnStart.start and ProjectionStore.readCanonicalProjection. This connection is circumstantial: no CPU profile was taken.
For acceptance, a read by key gives the same result: the message by ID (user role), the parent run by ID, then the subagents of that run plus the delivery's task IDs, with the same omitSettledSubagents filter. One case keeps the full read: a parent run awaiting its turn-end capture, which holdRunAwaitingCapture may report as waiting. We run that change locally. Its 15 cases (pending siblings, a delivery naming an older run's task, generation and message mismatches, live and archived parents, a pending capture) match the full read's events.
Steps to reproduce
- Use a thread with about 10,000 runs whose agent delegates tasks.
- Let a child finish, so the parent accepts the completion notice.
- Time
orchestrationV2.notificationAcceptedandorchestrationV2.providerTurnStart.start, or watch theevent loop stalled for N mswarnings.
Version
Production runs a local build of 0.1.12-nightly.20261123.5165. It reads several other commands by key. These two paths use upstream's code, unchanged on 5385.
Environment
Linux (Proxmox LXC, 16 CPUs, ZFS), t3 serve as a systemd service, statev2.sqlite 49 GB. Two dispatcher threads have 11,000–13,000 runs each.
Evidence
Statement log, 24 h, statements over 250 ms:
| Path | Statement | Calls | Mean | Rows |
|---|---|---|---|---|
| notification accept | messages, user role | 149 | 3.77 s | 14,643 |
| notification accept | turn items | 149 | 2.45 s | 6,141 |
| notification accept | nodes | 149 | 2.44 s | 12,752 |
| turn start | runs | 509 | 1.12 s | 12,249 |
| turn start | run attempts | 584 | 1.10 s | 11,005 |
| turn start | provider turns | 598 | 1.11 s | 10,500 |
event-loop-stalls.ndjson, same 24 h: 221 stalls, median 3.2 s, 90th percentile 8.1 s, longest 15.9 s.
Related issues
#35597 (turn start) and #36127 (send and queued start) were closed as partly fixed by #39103, #36289 and #37915; turn start still reads the three record sets above. #42557 reports a server wedged by background sync on a large history, a different path.
Fix applied or workaround
A local patch reads notification acceptance by key. Turn start is unchanged.
Filed by
Measured and written by Claude (Opus 5.5) in T3 Code; posted with the owner's approval.
Activity