Repository navigation
Description
What happened
statev2.sqlite grew to 113 GiB on a machine that runs about 10 long sessions. Each session drives 400–500 PRs through review iterations, so thousands of delegated Codex threads are created and finished on the one shared Codex session (provider-session:provider-instance:codex:shared).
The largest single source we found was provider-session.updated events in orchestration_events. In the retained window, the shared Codex session wrote 5,654,888 of these rows (15.3 GB) across 5,199 threads. No other provider session wrote more than 618 rows.
PR #43558 (in 0.1.13) removed the main trigger. On 0.1.13 and later the fan-out per write fell from up to 1,794 rows to 9–37 rows. But the write pattern that caused the growth is still in the current nightly: one full session snapshot per attached thread, on every startup-phase change. Any thread that stays attached multiplies every update. This issue is about that remaining pattern.
I am filing this because a maintainer said on X that part of this looks like a bug: https://x.com/jullerino/status/2126207815052325020
Diagnosis
Three parts combine. Source references are at v0.1.14-nightly.20261127.5319. The same code is in v0.1.12.
-
One row per attached thread for each session update.
ProviderSessionManager.persistProviderSessionUpdate(apps/server/src/orchestration-v2/ProviderSessionManager.ts:2802) callswriteProviderSessionEvents(:794) withthreadIds: current.attachedThreadIds. This writes oneprovider-session.updatedevent per attached thread, each with the fullOrchestrationV2ProviderSessionpayload. About 85% of each row (2,302 of 2,713 bytes on average) is the staticcapabilitiesobject, which is the same in every row. -
Transient startup phase is persisted as a durable event.
CodexAdapterV2.reportStartupPhase(Adapters/CodexAdapterV2.ts:2575) emitsprovider_session.updatedwith a newstartupPhase/startupPhaseThreadIdwhen a thread resume starts or ends (reportingResume,:2590), and onmcpServer/startupStatus/updated(:5473). Each thread start on the shared app-server therefore causes about 2–4 session updates. Each update fans out to all attached threads. With N attached threads and M thread starts, rows grow as N × M. -
On a shared session, a thread stays attached until it settles (or the session is released).
attachedThreadIdsloses a thread only indetach(:3537) and in attach rollback. Paths that end a thread's work do not detach it:Orchestrator.releaseFinishedDelegateSessions(Orchestrator.ts:15326) skips the detach for sessions withsupportsMultipleProviderThreadsPerSession, with the comment "Shared processes unload their threads themselves".- The shared process's own unload,
unloadIdleThread(ProviderSessionManager.ts:2196), clearsidleThreadUnloadsandloadedProviderThreadKeyByThread, but notattachedThreadIds. - Session-level idle release (
releaseIfStillIdle,:1643) clears everything, but only when no turn on the shared process is busy. With about 10 sessions running all the time, that does not happen.
The remaining detach paths are settle, archive, delete, force stop, and provider or model switches. On 0.1.12, delegated children settled only together with their parent, and the parents were long-lived. So every finished child stayed attached for the life of the process. fix(server): finished subagent threads settle without waiting for their parent #43558 now settles finished children on their own, which is why the fan-out is small on 0.1.13+. But a thread that finishes and does not settle still receives a full snapshot on every later startup-phase change of any other thread. Examples: auto-settle is off, the thread is pinned, or an automatic settlement fails (the service log shows
Thread … changed before automatic settlement.errors).
Suggested directions (any one helps):
- Do not persist
startupPhasechanges as per-thread durable events. Publish them as ephemeral state, or write only tostartupPhaseThreadId. - Write a session update once per session, not once per attached thread. Alternatively, leave the static
capabilitiesout ofprovider-session.updatedwhen it has not changed. - Detach a thread from a shared session when its native thread is unloaded, or when a finished delegate is released, independent of settlement.
Steps to reproduce
Not reproduced in isolation. These steps follow from the code above:
- Use one Codex provider instance (shared app-server session).
- Create a thread on it and let it finish. Keep it unsettled (for example, disable auto-settle for it or pin it).
- Repeat step 2 for K threads while at least one other Codex thread stays busy, so that the session is never idle-released.
- Start one more Codex thread on the same instance.
- Count
provider-session.updatedrows with that occurred_at for the shared session: there are about K+1 rows per update, and 2–4 updates per thread start.
On 0.1.12 the same happens without step 2's manual hold, because delegated children did not settle until their parent settled.
Version
The burst happened on 0.1.12 (service install, auto-updated). Per the service log, 0.1.12 ran from 2026-11-26T00:48Z to 23:59Z, then 0.1.13 until 2026-11-27T04:01Z. Since then the server runs 0.1.14-nightly.20261127.5319, and this code is unchanged there. (The triage CLI is 0.1.14-nightly.20261127.5319.)
Environment
- Linux x64 (kernel 7.0.0), Node v26.13.1
- T3 Code server installed as a background service (
boot-service), auto-update enabled - Provider: Codex (one shared instance), about 10 parallel long sessions with heavy
delegate_taskuse
Evidence
Max fan-out per write (rows with the same occurred_at for the shared Codex session), by version window:
| Version | Writes | Rows | Max rows/write | Avg rows/write |
|---|---|---|---|---|
| 0.1.12 | 12,590 | 5,624,852 | 1,794 | 446.8 |
| 0.1.13 | 1,732 | 22,226 | 530 * | 12.8 |
| 0.1.14-nightly.20261127.5319 | 693 | 6,040 | 24 | 8.7 |
* The 530-row write was the last update of the 0.1.12 process, at 23:59Z. After that, the 0.1.13 maximum was 37.
On 0.1.12, the max rows per write grew steadily through the day, for one session (the same createdAt, 2026-11-26T00:49Z):
hour(UTC) rows max/write distinct threads
01Z 25,020 148 149
04Z 96,229 500 562
08Z 119,446 560 560
12Z 220,162 860 860
16Z 331,535 1,353 1,417
20Z 371,902 1,458 1,458
22Z 580,275 1,742 1,742
The largest write (2026-11-26T23:20:43Z, 1,794 rows, 5.0 MB) went to 1,787 delegated-task threads under 42 parents, plus 7 other threads. None of them was settled at that time. At 23:20Z, 1,232 threads settled and 1,143 provider-session.detached events for the shared session followed. The max fan-out then fell from 1,794 to 695. So the settle → detach path works, and settlement is the only thing that bounded the set.
On the current nightly, the largest write in the last hour (07:05:44Z) had 21 recipients. 18 of them had not finished their run yet, and the 20 delegated ones settled within 13 minutes of the write.
Sample row (masked; capabilities omitted):
{"stream_version":49897,"occurred_at":"2026-11-26T23:20:43.311Z","actor_kind":"server",
"metadata_json":"{\"driver\":\"codex\",\"providerInstanceId\":\"codex\"}","payloadBytes":2799,
"payload":{"id":"provider-session:provider-instance:codex:shared","driver":"codex","status":"ready",
"cwd":"~/.t3/worktrees/<masked>","model":"gpt-6.2-sol","capabilities":"<2302 bytes>",
"startupPhase":"mcp","startupPhaseThreadId":"thread:<masked>",
"createdAt":"2026-11-26T00:49:11.478Z","updatedAt":"2026-11-26T23:20:41.000Z","lastError":null}}Event-store pruning works (1-day retention in ProjectionMaintenance.pruneEventStore). But at the 0.1.12 peak of 580k rows/hour (1.5 GB/hour), one day of retained rows was about 15 GB.
Related issues
- Settle delegated and subagent child threads when their own run ends, not only when the parent settles #43545 / PR fix(server): finished subagent threads settle without waiting for their parent #43558: finished delegated children now settle without their parent. This removed the main trigger here (it shipped in 0.1.13; the burst was on 0.1.12). It does not change the per-thread fan-out or the "attached until settled" lifetime on shared sessions, so this is not a duplicate.
- orchestration_events grows without bound: streaming updates are stored as permanent events and never compacted #21154, Retain orchestration events and receipts for a bounded window #13166, [Bug]: V2 event-store compaction is implemented but never runs, so statev2.sqlite keeps every superseded and imported-legacy event #18559: earlier event-store growth issues (streaming updates, retention, compaction). These are different event types and mechanisms.
- Retention for settled and archived threads: archiving frees nothing, and a 3-week-old database already stalls the server #42372, [Feature]: Retention/pruning for settled subagent thread projections (statev2.sqlite grows to 38.9 GB, 82% subagent turn_items) #43500, [Bug]: Claude
Readimages stay inline as base64 in both event and projection rows (1.4 GB, 46% of statev2.sqlite, in one week) #26591: database growth from projections or inline images. These are not aboutorchestration_eventssession rows.
Fix applied or workaround
None. The investigation was read-only: no database writes, no restart. The update to 0.1.13 (with #43558) already brought the rate down from about 245k to about 2.5–11k rows/hour. A server restart, or an idle release of the shared Codex session, also empties attachedThreadIds.
Filed by
Claude Code (claude-opus-5-5), via t3 triage.
Activity