Skip to content

A send or queued start to a long thread still reads 6–15 s of its history on main (follow-up to #29468) #36127

Open

Description

@Dropje97

#29521 closed #29468, and #36100 narrowed the deferred-steer and cancel reads. On our two coordinator threads, a send and a queued start still read most of the thread's history on main at a044f0c0b3.

Setup: a block clone of our 49 GB statev2.sqlite, read through the real ProjectionStore (reader worker, node:sqlite), read-only, two passes. Thread A has 7,352 runs and thread B 6,886. Our local build was measured on the same clone earlier.

Read A / B on main Our local build
Before a send: readCommandProjection, with #35180's recent-run filter 6.7–8.6 / 6.5–7.8 s 1.8–3.1 s
Before a queued start: the same read without that filter, in startNextQueuedRun 13.9–14.6 / 11.4–15.6 s 2.3–2.7 s
t3_thread_send preflight: all runs and provider turns 2.2–2.5 / 2.2–2.5 s 4–6 ms
t3_thread_send after dispatch: all runs and all user items, to find one message's 1.9 s on A not measured

Where the time goes on thread A, second pass:

  • Before a send, 6.4 s:
    • finding the last compaction, 1.2 s;
    • provider turns, 1.2 s;
    • runs, 1.1 s;
    • root nodes, subagents, provider threads, and user and error items, 0.7 s each.
  • Before a queued start, 11.0 s:
    • user messages, 3.0 s;
    • nodes, 2.4 s;
    • runs, attempts and provider turns, 1.0–1.1 s each;
    • turn items, 0.7 s;
    • subagents, 0.6 s.

So one t3_thread_send to thread A spends about 11 s in reads, and the send read holds the thread's dispatch lock. A queued start holds the lock for its 11–15 s read before its turn start, which #35723 narrows, even begins.

Our build stages these reads; the #29468 comment describes how, with a link to the code. In short:

  • One read transaction loads the thread and its runs, and only the active subagents, sessions, provider threads, requests, scopes and transfers.
  • Messages, nodes, attempts, provider turns and items are then read by key, for the runs a send can steer, queue behind or restart.
  • The preflight reads only running runs and their running turns.

What remains there is mostly the full runs read, about 1.1 s.

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

Activity

  1. nitedani commented on Nov 17, 2026

    @nitedani

    ClaudeCodex Claude Opus 5.5 (high effort) wrote this; GPT-6.1-Sol (Codex, medium effort) reviewed it.

    The queued-start read is still unfiltered on main at 0072f66, after #37915 bounded t3_thread_read: startNextQueuedRun calls readCommandProjection(threadId) with no recent-run window. On our server each slow queued start also read the whole thread twice.

    Our trace covers 68 minutes of a headless t3 serve (nightly 4761 plus #31488) with an 11 GiB statev2.sqlite. The six slowest queued starts:

    Queued start First full read Second full read
    87.4 s 71.1 s 10.7 s
    60.8 s 53.5 s 4.5 s
    54.2 s 45.7 s 6.5 s
    46.4 s 42.9 s 2.8 s
    26.5 s 16.8 s 9.4 s
    23.3 s 22.2 s 1.0 s

    These are wall times on a busy server, including reader waits, rather than a controlled comparison with your clone. In each, cancelStaleQuestionWakes cancelled nothing, and a second unfiltered read followed. On main, the three re-reads in this function all read the whole thread again. In the 71 s read, attempts took 15.3 s and nodes 21.4 s (details on #37877).

    I'll track the queued-start read here rather than opening the new issue I mentioned on #37915.

  2. navidnadali commented on Nov 19, 2026

    @navidnadali
    Contributor

    Note

    Written by Claude Opus 5.5 on behalf of Navid

    Where these reads stand on main @ 11e5b13, with a synthetic before/after.

    Narrowed since this issue was opened: the deferred-steer delivery and the queued cancel's message read (#36100),
    t3_thread_read (#37915), a failed scheduled run's error items (#38712), a follow-up task's read of its parent
    (#38867), secret and link cards (#38890), a send's read of a long compacted thread's old prompts (#36289), and the
    turn-start context's messages, tasks and transfers (#39103).

    Still reading whole record sets of the thread (paths in apps/server/src):

    Path (what triggers it) Reads Where Holds the thread's lock
    Queued start (the turn ahead of a queued message ends) every run, attempt, root node, provider turn, user message, user/error item and checkpoint scope, then again after each clean-up it writes orchestration-v2/Orchestrator.ts:1763-1808, :2428, :2438, :2453, :2475 yes
    Send now on a queued message (queued-message.promote-to-steer) every run, root node, attempt, user message, provider thread and turn, user item, request and task Orchestrator.ts:11593-11609 yes
    Removing a queued message one message now, but every run, attempt, root node and task Orchestrator.ts:11937-11947 yes
    Question-wake check in the queued start every runtime request the child ever had, to find one pending Orchestrator.ts:2360-2366 yes
    t3_thread_send, bound automations every run and provider turn before the dispatch; every run and user item after it orchestration-v2/ThreadManagementService.ts:871, :945-948 no
    Scheduled fire every run per due tick (queued-copy check); every run to find the one its message started scheduledTasks/ScheduledTaskService.ts:857, :909-910 no
    t3_thread_wait every run at the start, on each matching event and at the timeout ThreadManagementService.ts:1007, :1113-1116, :1127 no

    Synthetic in-process bench: real ProjectionStore on in-memory SQLite, Node 26.13.1, one thread with 13,500 runs,
    122,344 turn items and 845 delegated children. Measured on a build of main from 2026-11-15; the queued-start and Send-now
    code is unchanged on 11e5b13. "Bounded" reads the rows each decision uses, by key or through an index, and falls back
    to the whole read where it cannot tell.

    Command Rows decoded Payload read Decode Wall
    Queued start, whole read 72,322 39 MB 0.32–1.26 s 0.43–1.6 s
    Queued start, bounded 88 280 KB 4–6 ms 60–68 ms
    Send now, whole read 72,788 40 MB 0.37–0.39 s 0.43–0.45 s
    Send now, bounded 41 140 KB 1–5 ms 26–30 ms

    In the app, on a thread with a few thousand runs: send a message while a turn runs so it queues, and either let the turn
    end (queued start) or press Send now on it.

    Each path is a separate change with a test that fails on the current read (row counts at 40 vs 80 runs). The queued
    start and Send now also have an equivalence test that runs each fixture on the bounded and the whole read and compares
    outcomes. Happy to open them one path per PR, starting with the queued start, or a maintainer can take them.

    Fixed in the performance fork since v0.1.9-perf.9 (2026-11-16).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions