[Bug]: Intermediate turn-item snapshots remain outside event compaction (78.5 MB on one install) #19780
Before submitting#
- Searched #18559, #16647/#16652, #12758, #19461 and closed PR #19451.
- Included a read-only query excluding both first and latest snapshots.
Area#
apps/server
Steps to reproduce#
- Use V2 with tool-heavy agent threads over time.
- On a copy of
statev2.sqlite, run:
WITH ranked AS (
SELECT length(CAST(payload_json AS BLOB)) AS bytes,
row_number() OVER (
PARTITION BY stream_id, json_extract(payload_json, '$.id')
ORDER BY sequence
) AS first_rank,
row_number() OVER (
PARTITION BY stream_id, json_extract(payload_json, '$.id')
ORDER BY sequence DESC
) AS latest_rank
FROM orchestration_events
WHERE application_event_version = 2 AND event_type = 'turn-item.updated'
)
SELECT count(*) AS intermediate_snapshots, sum(bytes) AS payload_bytes
FROM ranked WHERE first_rank > 1 AND latest_rank > 1;
Actual behavior and evidence#
An October 14/15 Linux database copy, approximately 1.46 GB overall, has:
All turn-item.updated snapshots: 52,295 / 434,343,273 payload bytes
Intermediate snapshots excluding first+latest: 10,366 / 78,496,430 payload bytes
The aggregate was rechecked while consolidating the audits. Payload bytes are UTF-8 JSON bytes, excluding row/index overhead. They are not a promise of immediately reclaimable filesystem space.
compactEventStore explicitly leaves turn-item.updated intact. Its deletion cases cover complete thread states, node.updated, message.updated, and eligible legacy events. Thus merely adding its missing production caller (#18559) does not address this category. The proposed #19435 also excludes turn items.
Expected behavior / repair constraints#
Redundant intermediate full-state tool snapshots should not accumulate indefinitely. A repair must preserve original insertion position, latest state, prompt references, and replay/reconnect behavior. The source explicitly cites first-write ordering as a reason for retaining these records; deleting everything except the latest is unsafe. The query excludes both endpoints to establish the remaining storage cost, not to assert that blind deletion of its result is safe.
Closed PR #19451 attempted first/latest retention and a backfill. Its maintainer closure asked for the storage-growth evidence in an issue and agreement on a smaller repair. This issue records independent evidence; it does not request approval of that PR's implementation or backfill.
Impact / version / environment#
Storage growth on an Ubuntu Linux server using Claude. Nightly 0.0.46-nightly.20261014.3132; retention logic unchanged at main e536bfd33bc3c351997141d93790df75eeded7b9. No CPU slowdown or heap crash was demonstrated from these particular rows. No live database was compacted.
This count excludes the first/latest snapshots and projection copies. Normal event/projection duplication and required served-image storage are not counted as a separate defect here; #16647's already-fixed unserved-image case is also different.
Same query from the report, run read-only on a much larger install (a 19.8 GB
statev2.sqlite), on 2026-10-16:All turn-item.updated snapshots: 892,418 / 3,430,716,566 payload bytes Intermediate snapshots excluding first+latest: 137,091 / 600,533,278 payload bytesSo on this install the intermediate snapshots are about 0.6 GB, or 17% of the bytes in
turn-item.updatedevents, which is the largest event type (the whole table holds about 4.95 GB of event payload).By item type, the intermediate part is:
item type snapshots payload MB reasoning 33,633 238 command_execution 36,771 170 assistant_message 30,001 79 subagent 21,044 78 dynamic_tool 7,024 19 Counting every non-latest snapshot (the first one included) gives 425,630 of 891,622 rows and about 1.04 GB, because the first snapshot of an item is also kept for replay ordering.
One thing that may help when sizing the repair: file size is a poor proxy here. The same file has 1,138,303 free pages (4.66 GB) and
auto_vacuum = 0, and the data in use (15.2 GB) is 1.1 GB smaller than aVACUUM INTOcopy of the same database taken three days earlier, because compaction and the legacy cleanup shrank the event table in between. Onlyt3 doctorreturns those free pages to the filesystem.Payload bytes exclude row and index overhead, as in the report. Counts and sizes only; no thread content was read beyond
$.idand$.type.Another data point, from a newer build (
0.1.2-nightly.20261022.3512, macOS, Claude and Codex providers, a few hundred agent threads a day). It still reproduces after the #21154 fix.Measured read-only on a copy of
statev2.sqliteon 22 Oct 2026:statev2.sqlite: 11.56 GB, no free pages,auto_vacuumoff.orchestration_events: 6.49 GB table data, 1,309,069 rows. That's 7.68 GB with indexes, 66% of the file.turn-item.updatedalone: 2.76 GB.- Superseded snapshots of
turn-item.updated,subagent.updatedandprovider-turn.updated(every version but the latest per item): about 1.9 GB.
orchestration_v2_projection_turn_items: 2.32 GB, 278,730 rows.orchestration_v2_projection_nodes: 0.60 GB, 202,831 rows.- Growth: about 0.6–0.75 GB a day.
- The periodic compaction ran (every 6 h, last at 09:02 local), and
VACUUM INTOon the copy only took it from 11.56 to 11.26 GB. Sot3 doctor --fixcan't recover the space: the bytes are in live rows, the superseded snapshots compaction keeps.
Same ask as this issue: let compaction drop intermediate
*.updatedsnapshots once a turn item is final, keeping the first and latest. A retention setting next tostorageCleanupwould also work.Another data point for this issue, from a larger install and with a measured reclamation result.
Install#
T3 Code 0.1.1 desktop (macOS, Apple Silicon), 2026-10-22.
statev2.sqlitewas 26.99 GB (26,985,054,208 bytes) at the time of the measurement, with no free pages. 3,112 threads, of which 1,255 are archived.Where the bytes are (read-only, on a consistent copy)#
table bytes share of file orchestration_events15.42 GB 57.1% orchestration_v2_projection_turn_items4.85 GB 18.0% orchestration_v2_projection_nodes1.76 GB 6.5% orchestration_v2_projection_messages0.34 GB 1.2% all other tables 1.64 GB 6.1% all indexes (11) 2.97 GB 11.0% Inside the event log: 11.03 GB of payload over 3,948,291 rows, and one event type dominates it.
event_type payload share of event payload turn-item.updated7.48 GB 67.8% node.updated1.63 GB 14.8% provider-turn.updated0.51 GB 4.7% provider-session.updated0.32 GB 2.9% message.updated0.26 GB 2.4% context-handoff.updated0.20 GB 1.8% the other 37 event types 0.62 GB 5.6% The payload of
turn-item.updatedis mostly reasoning (2.87 GB) and command output (2.85 GB), because every change to a turn item stores the whole item again.The same query as this issue, on this install#
WITH ranked AS ( SELECT length(CAST(payload_json AS BLOB)) AS bytes, row_number() OVER (PARTITION BY stream_id, json_extract(payload_json, '$.id') ORDER BY sequence) AS first_rank, row_number() OVER (PARTITION BY stream_id, json_extract(payload_json, '$.id') ORDER BY sequence DESC) AS latest_rank FROM orchestration_events WHERE application_event_version = 2 AND event_type = 'turn-item.updated' ) SELECT count(*), sum(bytes) FROM ranked WHERE first_rank > 1 AND latest_rank > 1;All turn-item.updated snapshots: 1,567,471 / 7,131,369,660 payload bytes Intermediate snapshots excluding first+latest: 322,165 / 2,890,508,022 payload bytes Kept if pruned to first+latest: 1,245,306 / 4,240,861,638 payload bytesSo the intermediate snapshots are 2.89 GB, 40.5% of the
turn-item.updatedpayload on this install. That share is higher than the 18% and 17.5% in the two data points above, and it grows with the install: the more history a database keeps, the more of it is intermediate.No single thread dominates. Of the 3,125 threads that carry events, the largest holds 4.5% of the event payload, the top 12 hold 24.9%, the top 100 hold 63.0%, and the remaining 2,125 threads hold 8.6% (951 MB) between them. 48.2% of the payload is in threads that are already settled.
Growth#
26.0 GB at 2026-10-21T23:01Z, 26.99 GB at 2026-10-22T14:22Z: about 0.9 GB a day on this install, with streaming in its reduced mode.
A measured reclamation result#
On a copy of the database (nothing live was touched), I deleted the superseded
turn-item.updatedrows, keeping the first and the newest row per item, plus every row that a prompt sequence or a command receipt points at and the newest event of every stream, and then ranVACUUM:before 24.23 GiB after 20.33 GiB (-16%) PRAGMA integrity_check okThe projection was unchanged: for all 746,171 turn items, the projection row equals the newest surviving event, with 0 mismatches, before and after. A server opened the pruned copy and listed the same threads (3,063 threads, 16 archived, 13 deleted).
t3 doctor --fixon the result reports nothing to repair.So the reclaimable space is real and measurable, and it comes back to the filesystem only if the file is vacuumed;
auto_vacuum=INCREMENTALafterwards is what keeps returning it online.Suggestion#
Compacting superseded
turn-item.updatedrows the waymessage.updatedandnode.updatedalready are - keeping the first and the newest row per item, preserving insertion position, prompt references and replay behaviour - would reclaim a large part of the event log on every long-lived install. The measurement above suggests the reclamation is worth having on its own, and not only for the event log: on this install the projections and the indexes add another 9.9 GB of the file.Another data point, on the newest build so far:
0.1.3-nightly.20261023(server.3566when measured, doctor run from.3579). macOS desktop app, Apple Silicon, Codex and Claude providers. The workload is heavy ondelegate_taskfan-out, with 6,172 threads and none archived.All of this was measured read-only on the live
statev2.sqliteon 23 Oct 2026.statev2.sqlite: 19.14 GiB.freelist_count = 0,auto_vacuum = NONE.t3 doctorreports "19.14 GiB, 0 KiB reclaimable" and offers no repair. The 6-hourly compaction last ran a few hours earlier.
Where the bytes are (
dbstat):object MB orchestration_events10,738 its 4 largest indexes ~2,055 orchestration_v2_projection_turn_items3,760 orchestration_v2_projection_nodes1,105 orchestration_eventsby type (payload MB):turn-item.updated1,081,208 rows / 4,977;node.updated682,382 / 809;subagent.updated81,580 / 355;provider-turn.updated308,505 / 324;message.updated80,551 / 156.The query from this issue:
All turn-item.updated snapshots: 1,083,458 / 5,238,163,750 payload bytes Intermediate snapshots excluding first+latest: 330,962 / 1,492,184,255 payload bytesSo 28% of the
turn-item.updatedbytes are intermediate snapshots, a higher share than the 17% on the 19.8 GB install above.Growth per day (
orchestration_eventspayload):day rows MB Oct 15 148,584 367 Oct 16 130,264 316 Oct 17 183,312 420 Oct 18 195,456 347 Oct 19 105,438 210 Oct 20 145,724 296 Oct 21 2,878 5 Oct 23 23,480 54 Usage on Oct 21 to 23 was lower, so I can't tell how much of the drop comes from the #21154 / #19435 fix.
95% of the event rows are from October; the database was mostly built up in the last three weeks.
Measured and drafted by Claude Code (claude-opus-5-5) via
t3 triage, on behalf of @kosovojs.Another data point for this issue, from a long-running headless server:
t3 v0.1.2-nightly.20261022.3541, macOS 27,t3 serverun by a launchd service, Claude and Codex providers, remote desktop and mobile clients, several thousand threads.Size and growth.
~/.t3/userdata/statev2.sqlitereached about 34.9 GB (32.5 GiB) in 17 days. That is about 1.9 GiB and about 286,000 events a day on average, and it is still growing at about 1.8 GiB a day.turn-item.updatedis the largest event type. Newest 20,000 events (a 73-minute busy window), payload bytes only (sum(length(payload_json)), without row or index overhead):event_type rows payload bytes share turn-item.updated8,807 23.9 MB 64% node.updated5,393 6.0 MB 16% provider-turn.updated3,814 4.4 MB 12% thread.visited104 1.3 MB 4% message.updated568 0.7 MB 2% all others 1,314 1.0 MB 3% An earlier 5,000-event sample gave the same order. Highest rowids, as a size hint:
orchestration_v2_projection_turn_items1,058,421;..._nodes844,414;..._messages128,802;..._provider_turns17,337;..._runs15,341;..._threadsabout 4,000.Compaction and
t3 doctorreturned little. Automatic compaction ran ("Compacted orchestration history" is logged three times; the last run matchesuserdata/compacted-at), and the file did not shrink.t3 doctor --fixtook the file from 32.41 GiB to 31.48 GiB (about 800 events, 0.93 GiB, 2.9%), with the server stopped for 51 minutes.auto_vacuumwas 0 before the doctor ran (it set it to 2), so until then deleted rows could not return space to disk.Impact. Long reads and checkpoints slow down as the file grows (see #21840 and #23482), and the host's free disk fell to its alarm floor. The doctor's two APFS-clone backups also took about 32 GiB together once the live file diverged from them.
Not measured: bytes per table or index. A
dbstatscan of a live 32 GiB file would hold a long reader snapshot, so these readings use onlymax(rowid),PRAGMAlookups and rowid-bounded reads.Questions:
- Is compaction of
turn-item.updated(andnode.updated) snapshots planned, and in which release? - Is there a supported retention setting, or an online way to shrink the database, for a server that runs for weeks? #21371 asked for one and was closed as a duplicate. Which issue tracks it?
- Could
t3 doctorprint a dry-run estimate (rows and bytes it would remove) and its progress? A 51-minute exclusive lock is hard to plan around without one. - Is there a safe, read-only way to report per-table and per-index bytes on a live database?
- Is compaction of
Note
Posted by Claude Code (Opus 5.5) on behalf of @omar7550.
Another data point, from a delegate-heavy install where the intermediate snapshots are only a small part of the growth.
Install: T3 Code Nightly
0.1.3-nightly.20261024.3630, macOS desktop, Codex and Claude, heavydelegate_taskfan-out. 7,366 threads (2,867 deleted).statev2.sqliteis 23.3 GB,freelist_count = 0. Background compaction runs (compacted-atfrom earlier the same day; only 480 intermediatemessage.updated/node.updatedrows left, all written after that pass).orchestration_eventsby type (payload bytes; 2,908,049 rows, 6.92 GB):event_type rows payload share turn-item.updated1,279,100 4,895 MB 70.7% message.updated710,031 863 MB 12.5% node.updated483,528 579 MB 8.4% provider-turn.updated198,503 208 MB 3.0% subagent.updated60,954 159 MB 2.3% the other types 175,933 216 MB 3.1% The query from this issue:
Intermediate snapshots excluding first+latest: 85,330 / 269 MB (5.5% of turn-item payload) of which item type "subagent": 47,243 / 131 MB All but the latest per item: 291,001 / 692 MB Distinct turn items: 988,106So on this install, first-and-latest compaction would remove about 0.27 GB of 4.9 GB. #20990 keeps every subagent snapshot and command-associated ones, so it would remove at most about half of that (≤0.14 GB). Most items have one row; the bytes are the latest state of about a million items (
command_execution1.75 GB,dynamic_tool1.62 GB,assistant_message0.66 GB,user_message0.43 GB), stored again in the projections.Event payload grows 0.15–0.65 GB a day (Oct 10–24), about 70% of it
turn-item.updated. Compaction (ProjectionMaintenance.ts#L233-L243) only removes superseded rows, and nothing removes old or deleted threads; deleted threads alone account for 1.68 GB of event payload here (see #17845). On this install, startup after a 1.3 GB WAL took ~4.5 min, past the desktop's 60 s readiness timeout (details in #22983).#20990 is still worth having, but on installs like this one what bounds the file is retention (#15122, #22630) or deletes that purge rows (#17845).
Measured read-only on the live file in short chunked reads (to avoid a long reader snapshot, #23482); totals may be a few minutes' writes off.
I'm seeing a severe instance of this on Windows with 0.1.3-nightly.20261026.3740. My statev2.sqlite is 117.9 GiB, with 15,893,258 rows in orchestration_events. Three delegated Codex threads account for 15,489,331 rows (97.5%).
Read-only samples from early, middle, and late in those threads are dominated by turn-item.updated events for command execution and dynamic tool items. In one sample, a single tool item had 64 snapshots with only two distinct payloads. Its completed snapshot contained the same 287 KB tool result repeatedly.
t3 doctor --dry-run reports 0 KiB reclaimable, so reclaiming free pages alone does not appear to address this case. With this data directory, the desktop backend repeatedly times out waiting for readiness and no window opens. The same installed build opens a window promptly with a fresh data directory.
I have not deleted or modified events. This looks like a case where repeated full turn-item snapshots have accumulated enough to affect startup, beyond the disk growth described in this issue.
Closing: current main already covers this as of 481b9b7192. If you still see it on a build that includes that commit, reply and we'll reopen.
juliusmarminge closed this
Sign in to join this conversation.
Another data point that is larger and has a different shape: macOS desktop,
0.0.46-nightly.20261015.3145,statev2.sqlitecreated 2026-10-05, now 22.7 GB after 10 days (freelist_count = 0). Measured read-only withdbstatand aGROUP BY event_typeoverorchestration_events:turn-item.updatedsubagent.updatednode.updatedOne thread accounts for 15.7 GB. It ran a Workflow whose script (~207 KB) is passed inline as the subagent
prompt. Averaged over the latest 200 events of each type in that thread,promptis 206,885 bytes in bothsubagent.updatedandturn-item.updated. The next largest fields arediffStr(~42 KB) andworkflow(~13 KB). 213 distinct subagents produced 40,304subagent.updatedevents, so the same prompt is rewritten roughly 190 times per subagent.So beyond the intermediate snapshots described here, the size driver on this install is an unchanged large field being copied into every snapshot. Compacting intermediate snapshots would help. Storing large immutable fields such as
promptonce per entity, or emitting only changed fields, would address the growth rate itself. #19435 states that turn items are never compacted; I have not verified whethersubagent.updatedfalls under its node rules.