t3code
t3code copied to clipboard
[Feature]: Batch archive: archiving thousands of finished subagent threads takes one heavy command per thread and pushes an update per thread to every client
Summary
Agent-heavy installs collect thousands of finished delegated-task threads. The only way to archive them is one thread.archive command per thread. Each one loads the thread's projection, emits a full-snapshot thread.archived event, detaches provider sessions, and pushes a shell update to every subscribed client. Doing this fast enough to matter makes the server unresponsive for everyone, so it has to be paced. We archived 7,609 threads over two hosts; it took ~80 minutes per host.
Version / setup
0.1.3-nightly.20261023.3566, Linux t3 serve with remote clients over T3 Connect. Same contract on main at edb2b2f365 (no multi-thread archive).
Where in the code
- Contract takes one thread: orchestrationV2.ts:2604-2608.
- Per command: provider context is loaded (Orchestrator.ts:2922), then the projection with runs, attempts, nodes, subagents and user messages (:3571-3576), then provider sessions are detached (:3674-3760).
- Per event, per subscribed client: one
getThreadShellread, not shared across subscribers (ws.ts:1055-1067), plus the archived-shell stream (ws.ts:1819-1840) and a relay publish (AgentAwarenessRelay.ts:88-92). - Commands are decided one at a time, so parallel callers only lengthen the queue.
Numbers
- Unpaced attempt (host A, 25 GB DB): 1,615 archives in 13 min (~2/s) at 3–4 parallel callers. 149 of 1,742 calls timed out on the client after 30–45 s but were applied anyway; other clients' commands waited in the same queue, and remote clients saw the server as unresponsive for ~13 min. 1,377
provider-session.detachedevents came with it. ~10 % of calls returned an error yet applied. - Paced run (both hosts): serial, 750 ms gap, 20 s pause per 100, back off on slow replies. Host A 4,039 threads in 84 min, host B 3,570 in 80 min. Median archive RPC 35–42 ms (per-chunk medians, n=80 and 71 chunks); max 8.0 s.
- Payoff: shell read median host A 1,358 → 311 ms, host B 1,410 → 293 ms (n=5 each). Active threads 4,802 → 775 and 4,305 → 739.
Ask
- A batch command (e.g.
thread.archivetakingthreadIds[], or "archive settled delegated children older than N"), applied in one pass with one coalesced shell push per client. - Share the
getThreadShellread across subscribers for the same event batch. - Optional: skip the full-snapshot payload in
thread.archivedfor batch archives (avg 1.8 KB, max 5.9 KB per event here).
Related
- #22372: thread opens slow with ~5,000 unarchived threads; its workaround is bulk
thread.archive. - #13657 (closed): auto-archive settled threads.