t3code icon indicating copy to clipboard operation
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

Open matthias-scale opened this issue 1 month ago • 0 comments

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

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.detached events 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

  1. A batch command (e.g. thread.archive taking threadIds[], or "archive settled delegated children older than N"), applied in one pass with one coalesced shell push per client.
  2. Share the getThreadShell read across subscribers for the same event batch.
  3. Optional: skip the full-snapshot payload in thread.archived for 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.

matthias-scale avatar Oct 25 '26 02:10 matthias-scale