Skip to content

Shared Codex session writes a full provider-session.updated row to every attached thread on each startup-phase change #44029

Done

Description

@kdy1

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.

  1. One row per attached thread for each session update. ProviderSessionManager.persistProviderSessionUpdate (apps/server/src/orchestration-v2/ProviderSessionManager.ts:2802) calls writeProviderSessionEvents (:794) with threadIds: current.attachedThreadIds. This writes one provider-session.updated event per attached thread, each with the full OrchestrationV2ProviderSession payload. About 85% of each row (2,302 of 2,713 bytes on average) is the static capabilities object, which is the same in every row.

  2. Transient startup phase is persisted as a durable event. CodexAdapterV2.reportStartupPhase (Adapters/CodexAdapterV2.ts:2575) emits provider_session.updated with a new startupPhase/startupPhaseThreadId when a thread resume starts or ends (reportingResume, :2590), and on mcpServer/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.

  3. On a shared session, a thread stays attached until it settles (or the session is released). attachedThreadIds loses a thread only in detach (: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 with supportsMultipleProviderThreadsPerSession, with the comment "Shared processes unload their threads themselves".
    • The shared process's own unload, unloadIdleThread (ProviderSessionManager.ts:2196), clears idleThreadUnloads and loadedProviderThreadKeyByThread, but not attachedThreadIds.
    • 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 startupPhase changes as per-thread durable events. Publish them as ephemeral state, or write only to startupPhaseThreadId.
  • Write a session update once per session, not once per attached thread. Alternatively, leave the static capabilities out of provider-session.updated when 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:

  1. Use one Codex provider instance (shared app-server session).
  2. Create a thread on it and let it finish. Keep it unsettled (for example, disable auto-settle for it or pin it).
  3. Repeat step 2 for K threads while at least one other Codex thread stays busy, so that the session is never idle-released.
  4. Start one more Codex thread on the same instance.
  5. Count provider-session.updated rows 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_task use

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

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

  1. added
    via-triage
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    via-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions