[Bug]: V2 event-store compaction is implemented but never runs, so statev2.sqlite keeps every superseded and imported-legacy event #18559
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Run Orchestrator V2 (nightly) for a few weeks on an install that imported V1 history.
- Open
~/.t3/userdata/statev2.sqliteread-only and count the events thatProjectionMaintenanceV2.compactEventStorewould delete:
-- V1 events of threads whose transcript import finished
SELECT count(*), sum(length(payload_json))
FROM orchestration_events e
WHERE application_event_version = 1 AND aggregate_kind = 'thread'
AND EXISTS (SELECT 1 FROM orchestration_v2_legacy_imports li
WHERE li.thread_id = e.stream_id AND li.transcript_imported_at IS NOT NULL);
-- V2 node.updated / message.updated rows superseded by a newer row of the same entity
SELECT event_type,
count(*) - count(DISTINCT stream_id || '/' || json_extract(payload_json, '$.id'))
FROM orchestration_events
WHERE application_event_version = 2 AND event_type IN ('node.updated', 'message.updated')
GROUP BY 1;
- Search the server for a caller of
compactEventStore.
Expected behavior#
The server runs compactEventStore (on startup and/or periodically), so superseded events and imported V1 events are deleted and the file stops growing with them.
Actual behavior#
On main (5fe7568e) compactEventStore is defined in apps/server/src/orchestration-v2/ProjectionMaintenance.ts and its layer is provided in runtimeLayer.ts, but the only callers are FoundationPersistence.test.ts. Nothing in production resolves ProjectionMaintenanceV2 and calls it, so the rows it targets accumulate.
My install (macOS, 0.0.46-nightly.20261006.2735, V1 history imported on 2026-10-03):
| events | payload | |
|---|---|---|
orchestration_events total | 2,917,313 | — (table 9.3 GB + 1.7 GB indexes) |
| V1 events of 786 fully imported threads | 1,248,694 | 1.41 GB |
superseded V2 node.updated | 490,050 | of 0.86 GB for the type |
superseded V2 message.updated | 5,072 | of 0.13 GB for the type |
So about 1.74 M of 2.92 M events (60%) are already eligible for the existing compaction. The file is 15.9 GB and grows by roughly 170–800 MB per day of event payload.
Separately, projection_thread_activities (617,868 rows, 1.25 GB) has had no new rows since the V2 migration on 2026-10-03, and no non-migration server code references it. It may be a dead V1 projection that is never dropped.
Impact#
Major degradation or frequent failure
Disk use grows without bound, and large databases slow every full scan (see #17955, #14701). Related, not duplicates: #17845 (deleted threads keep events), #18204 and #16558 (write amplification of individual event types), #13166 (closed, filed against a fork).
Version or commit#
0.0.46-nightly.20261006.2735; code read on main 5fe7568e.
Environment#
macOS (Apple Silicon), T3 Code Nightly desktop.
Logs or stack traces#
No errors: the compaction simply never executes.
Workaround#
None supported. Running compactEventStore manually is not exposed.
Two things I listed as "not measured" in my comment above, now measured on the same fork server (Windows, read-only queries,
dbstatfor the table sizes).Growth over 19 hours of normal use (12 Oct 07:27 UTC to 13 Oct 02:26 UTC; eleven recurring tasks plus interactive threads):
12 Oct 07:27 13 Oct 02:26 change statev2.sqlite1.77 GB 2.45 GB +0.69 GB orchestration_eventsrows265,983 370,675 +104,692 event payload 667 MB 945 MB +278 MB superseded node.updated45,972 of 90,161 59,448 of 118,594 still half What the file is made of now (largest first):
orchestration_events1,342 MB orchestration_v2_projection_turn_items500 MB orchestration_v2_projection_nodes122 MB sqlite_autoindex_orchestration_events_194 MB orchestration_v2_projection_messages70 MB three more indexes on the events table about 30 MB each Which event types the new payload came from (events since 12 Oct 07:30 UTC):
event type events payload turn-item.updated32,625 100 MB thread.pull-request-synced1,990 55 MB node.updated28,377 29 MB context-handoff.updated213 27 MB provider-turn.updated14,351 15 MB message.updated5,851 14 MB So on this install the events table is a bit more than half of the file and grows by roughly a third of a gigabyte of payload per day;
turn-item.updatedis the largest contributor, and two types stand out per event rather than by count (thread.pull-request-syncedat about 28 KB each,context-handoff.updatedat about 127 KB each).Caveats: this is a fork, so the mix of event types may differ from
main(I checked only that these type names exist upstream). The file grew by more than the payload did; I did not separate index growth from free pages. The set of counting queries from this issue now takes about 12 seconds in total on this database (3 seconds a day earlier).Posted by Claude (Opus 5.5, Claude Code via T3 Code) on behalf of @AdEx-Partners-DE.
I checked
mainat9c9ae43d80: outside tests,compactEventStoreappears only in its interface, implementation and service export in ProjectionMaintenance.ts. The runtime layer provides the service, but nothing calls it, so the existing compaction never runs in a normal server.#15759 was closed because hourly deletion and a new offline verify/rebuild command needed scope approval first. Would you want a narrower PR that only calls the existing compaction once in the background after server startup, with its existing deletion rules? No recurring schedule, no CLI and no retention changes.
The PR would show that startup runs compaction once, that the existing retention and replay tests still pass, and that a compaction failure is logged without blocking startup. It would report how long the first pass takes on a large database. It wouldn't shrink the file on disk by itself: the existing method reports reclaimable pages and doesn't
VACUUM.Drafted with Claude Code and Codex (GPT-6.1 Sol).
Another data point, Linux (Fedora 44, btrfs),
0.0.46-nightly.20261012.3021, heavy Claude subagent fan-out. This one shows a user-visible cost, not only disk.statev2.sqlite4.6 GB, 1.01M orchestration_eventsGrowth 215k events from 08-24 to 10-11, then about 800k from 10-12 to 10-14 node.updated/message.updated629k rows; 67.5k are the latest per entity; 510k are byte-identical copies of an earlier row (same stream, type and payload), and the top repeated payload had a single command_idauto_vacuum0, freelist 0, so deleting rows would not shrink the file Impact on worktree creation. At that size,
sql.transactionspans went over 500 ms 122 times in 14 minutes, the longest 5.8 s. TwoGitManager.createWorktreecalls took 3.5 s and 9.2 s, and single git calls inside them (config,rev-parse) took 0.3 to 2.6 s each. The same commands run in a shell took 0.00 s. Database stalls overlapped 2.1 s of the 3.5 s call but only 0.6 s of the 9.2 s one, so they don't explain all of the slowdown.After
0.0.46-nightly.20261014.3105(40 minutes of light use): 154 of 154 newnode.updatedrows are distinct, 0 transactions over 500 ms, git p50 dropped from 159 ms to 25 ms. The duplicate writes look fixed, likely by #18375, but the existing 4.6 GB stays until compaction (#19435) and a vacuum run.Filed by: claude (opus-5.5), investigating the machine directly
Consolidated confirmation from two additional installations on
0.0.46-nightly.20261014.3132. Recheckede536bfd33bc3c351997141d93790df75eeded7b9:rg -n 'compactEventStore' apps/server/src --glob '*.ts'still finds only its interface/definition/export and test invocations, with no production caller.Read-only copied-data analysis using the current compactor's own eligibility policy, with payload measured as UTF-8 bytes:
Linux server Mac desktop All events 163,911 98,055 Eligible events 50,518 75,074 Eligible payload bytes 77,424,570 226,986,346 Share of all event payload 11.82% 85.68% Imported legacy component, rows / bytes 23,997 / 29,464,130 71,054 / 222,807,924 The remaining eligible bytes are superseded thread states, nodes and messages. The Mac's 176 legacy thread imports were complete. Other audit captures used slightly later cutoffs and text-character counts; the table above uses one consistent pair of snapshots and BLOB byte lengths rather than mixing those totals.
These figures exclude row/index overhead. They overlap retained deleted-thread history (#17845), so they must not be added to that finding. They also do not claim that every eligible payload byte immediately shrinks the filesystem file: both databases used
auto_vacuum=0, and deletion and physical reclamation are separate steps. Turn-item/subagent retention is intentionally outside this calculation. No cleanup ran on either live installation.The current background-compaction and offline-reclamation proposals #19435/#19436 remain open; this is evidence for this issue, not another implementation proposal.
juliusmarminge closed this
Sign in to join this conversation.
I ran your two queries read-only on two Windows databases, a desktop Nightly and a fork's server on the same machine, as a second data point with a different shape: smaller, and with very little V1 history left.
statev2.sqliteorchestration_eventsnode.updated: superseded / totalmessage.updated: superseded / totalprojection_thread_activitiesWhat that adds to your numbers:
node.updatedrows. More than half of everynode.updatedever written here is already dead weight.node.updatedpayload together is 92 MB and 52 MB, so compaction would free less than that here. I did not sum the payload of only the superseded rows.projection_thread_activitiesis empty on both, even though both imported V1 threads, so I cannot add anything to that part.I also checked the caller: in the tag
v0.0.46-nightly.20261011.2994,compactEventStoreappears only inProjectionMaintenance.tsandFoundationPersistence.test.tsunderapps/server/src, the same as you found on main.Not measured: what the rest of the file is (payload is 667 MB of 1.77 GB; I did not break down indexes and projection tables), and how fast either database grows per day.
Posted by Claude (Opus 5.5, Claude Code via T3 Code) on behalf of @AdEx-Partners-DE.