Skip to content
Source
Sign inSign up
pingdotgg/t3code

Deferred-steer check and queued-message cancel read a long thread's whole history under its dispatch lock #36095

ClosedDropje97(GitHub profile, opens in a new tab) opened this issue 0 comments

Two paths still read a long thread's whole history while they hold the thread's dispatch lock, so sends and other commands to that thread wait. #29521 narrowed the steer and Stop reads from #29468, but not these two.

Measured in production over 8.6 hours on 0.1.10-nightly.20261112.4606; our local patches leave both paths unchanged, and the code is the same on main at 5f69cac5c9. Both threads are coordinators:

  • thread A: 7,511 runs, 4,577 subagents, about 45,000 nodes;
  • thread B: 6,939 runs, 2,535 subagents, about 40,000 nodes.

1. Deferred steers: a full runs read on every running provider-turn update

deliverDeferredSteers handles every provider-turn.updated event with status running. Inside threadDispatch.withLock, it reads all runs of the thread to find queued runs whose steerWhenReadyRunId is the running run. The Claude adapter emits such an event with each token-usage update, so this happens several times per turn, and it almost never finds a steer to deliver.

Thread AThread B
Provider turns started15250
Runs reads by deliverDeferredSteers1,400481
Per read, median1.10 s1.08 s
Lock time, total26 min8.8 min

That is about 10 s of lock time per turn on thread A, and each read decodes about 8.7 MB of run JSON.

A possible fix: runStatuses: ["queued", "running"] on that read, which seeks orchestration_v2_projection_runs_thread_status_idx. On a copy of the database, with the sqlite3 CLI, that query returns 2 rows in under 50 ms; the full read returns 7,352 rows in 2.2 s.

2. Cancelling a queued message reads the whole thread

dispatchQueuedRunCancel loads all runs, user messages, nodes, attempts and subagents to remove one queued run; rahulshinde11 noted this in #29468. #29521 gave the steer and Stop reads omitSettledLeafNodes, but not this one. In the same 8.6 hours, five cancels on the two threads each read for about 15 s:

ReadRowsMedian
Nodes40,000–44,0008.0 s
User messages (two reads)7,100–7,8002.8 + 1.3 s
Attempts6,900–7,4001.1 s
Runs6,900–7,4001.0 s
Subagents2,500–4,5000.9 s

An agent that clears handled messages from its own queue with t3_queue cancel pays this for each message.

Times are statement execution times from a local statement log that records every read over 250 ms, so the counts are complete for these threads.

Measured and written by Claude (Opus 5.5) in T3 Code; posted with the owner's approval.

  1. tanstack-source added labelsbug

  2. juliusmarminge closed this

Sign in to join this conversation.