Skip to content
Source
Sign inSign up
pingdotgg/t3code

orchestration_events grows without bound: streaming updates are stored as permanent events and never compacted #21154

Closediokoioko(GitHub profile, opens in a new tab) opened this issue 3 comments

Version

  • Server: 0.0.46-nightly.20261014.3105 (headless t3 serve, Linux x64)
  • Providers in use: Codex, Claude, and opencode. The growth is dominated by opencode threads.

Observed

On one long-running server used by a few dozen agents a day:

  • statev2.sqlite is about 17 GiB.

  • orchestration_events holds about 2.55 M rows, about 11 GB of table data plus about 2 GB of indexes.

  • Growth: about 1.2 GB on 16 Oct 2026 and about 1.8 GB on 17 Oct 2026.

  • By event type, over the last two days:

    event_typerowsbytes
    node.updated1.21 M1.94 GB
    turn-item.updated162 k746 MB
    message.updated31 k202 MB
  • The twelve largest streams in the last 24 hours were all threads run through the opencode provider: 53 to 154 MB and 29 k to 91 k event rows each, all single code-review threads. No thread on the Codex or Claude providers appeared in the top twelve.

Our reading is that the opencode adapter emits a node.updated event for each streamed chunk of text and the server persists each one as a durable event. We have not traced this in the adapter; the per-thread row counts are what suggest it.

Existing compaction is never invoked

Build 3105 already contains ProjectionMaintenanceV2.compactEventStore (src/orchestration-v2/ProjectionMaintenance.ts, byte offset 164579697 in the server binary). It scans newest first and deletes every node.updated / message.updated event except the newest per entity:

} else if (row.event_type === "message.updated" || row.event_type === "node.updated") {
  const key = encodeEntityKey([row.event_type, row.stream_id, row.entity_id]);
  if (retainedEntityKeys.has(key)) obsolete.push(row.sequence);
  else retainedEntityKeys.add(key);
}
...
yield* sql`DELETE FROM orchestration_events WHERE sequence IN ${sql.in(obsolete)}`;

The service is provided in the production layer (layerProjectionMaintenanceProvided is merged into the server layer, offset 164738048), but we found no code that calls it: the identifiers ProjectionMaintenanceV2 and compactEventStore occur only inside that module. So, as far as we can see, it never runs. Two more limits:

  • Its comment says turn-item.updated stays intact because replay assigns positions on first write, so about a quarter of the recent growth is out of its scope by design.
  • It returns reclaimableBytes from PRAGMA freelist_count, but deleting rows does not shrink the file without a VACUUM (or incremental vacuum).

Why it matters

  • Disk. At this rate the database grows by about 10 GB a week on a small host, with no ceiling. A full disk takes the server and every agent on it down.
  • Backups. The state file is the thing you most want to back up, and it is now tens of GB, almost all of it superseded intermediate states.
  • Startup and projection time. Startup, recovery and any projection rebuild page through this table; rebuild and replay cost grows with history, not with live state. Larger indexes also slow every write under load, and we see database is locked and event loop stalls on the same host when it is busy.

Suggested fixes

  1. Coalesce streaming updates. Keep the per-chunk updates in memory for live clients and write one node.updated per node when the node completes (plus at most a periodic checkpoint for crash recovery), instead of one durable event per chunk.
  2. Or keep streaming deltas out of the durable log. The raw provider-event path already drops message.part.delta and running text/reasoning message.part.updated events (offset 159920717); the same rule could apply before events reach orchestration_events.
  3. Run the existing compaction. Call compactEventStore on a schedule (or at startup before recovery) for threads whose runs are terminal, extend it to turn-item.updated where replay allows, and follow it with an incremental vacuum so the file actually shrinks. A retention setting for very old, settled threads would also help.

Workaround

None we consider safe. Deleting rows from orchestration_events or running VACUUM on a live database risks breaking projections and holds long write locks, and the compaction service has no entry point we can call while the server runs. The only option we see is an offline operation with the server stopped, which interrupts every running agent. For now we reduce our own load by routing most review work away from the opencode provider.

  1. Note

    Grok responding on behalf of Julius.

    Your build predates the fix for compaction never running (#18559). Since #19435, the server compacts history one minute after start and every six hours, keeping only the first and newest node.updated and message.updated per entity, and new databases use incremental auto vacuum. On an existing database, t3 doctor reclaims the space; it stops the server while it runs. turn-item.updated staying outside compaction is tracked in #19780, and per-chunk OpenCode events were discussed in #20443.

    Please update to the latest nightly, run t3 doctor once, and after a day of normal load share the database size and the row counts per event type for the last 24 hours. That shows whether OpenCode streaming still causes real growth after compaction.

  2. juliusmarminge added labelsneeds more info

  3. juliusmarminge added labelsvia-triage

  4. Note

    🤖 Claude Opus 5.5 responding on behalf of Theo

    Thanks for the report. One part of this is fixed on main in #19435. Please test on the nightly built from main on 2026-10-21, or on the next stable release. One part is still open: turn-item.updated growth and OpenCode per-chunk event volume. If that part still matters to you, please open a new issue for that part only.

  5. Current main already backfills eligible turn-item and node snapshots. A remaining omitted type is provider-turn.updated: a read-only audit found 1,271,390 updates for 32,821 provider turns, with 1,173,829 obsolete rows containing 1.28 GB of payload under the first/latest/usage retention rules. A rebased port of Theo's #22548 is ready at #28109, with real-subset replay and rebuild parity. This fixes that event type only; retained conversation history and other storage work remain separate.

Sign in to join this conversation.