codex icon indicating copy to clipboard operation
codex copied to clipboard

0.167+: TUI startup loads full rollouts of other threads, several GB of RAM per launch

Open dave00000 opened this issue 2 weeks ago • 1 comments

What version of Codex CLI is running?

0.169.0 (also 0.167.0). Works fine on 0.166.0.

What subscription do you have?

Max 200

Which model were you using?

gpt-6.1-sol

What platform is your computer?

Linux 6.18.58.1-microsoft-standard-WSL2 x86_64 unknown (Ubuntu 26.04 on WSL2, 56 GB RAM)

What terminal emulator and version are you using (if applicable)?

VS Code integrated terminal (WSL)

Codex doctor report

codexVersion: 0.169.0
overallStatus: warning
install: bun, linux-x86_64 musl binary
app_server.status: ok (background server not running, daemon_auto_start=false)
state.paths: ok (all state DBs pass integrity)
state.rollout_db_parity: warning - rollout files and state DB thread inventory differ
  - 10 rollout files missing from the state DB
  - 2 state DB rows point at missing or unusable rollout files
  - 3 duplicate rollout thread ids
  - 15 rollout scan errors
All other checks: ok

What issue are you seeing?

Since 0.167, each TUI launch peaks at 5-9 GB of RAM in the first ~15 seconds. On 0.166.0 it's under 1 GB. I keep sessions running for weeks, so some of my rollouts are 1-3 GB. When I open my editors, up to 15 windows start at once, each restoring 2-10 Codex sessions. On 0.167+ that runs WSL out of memory.

Peak memory per launch, same CODEX_HOME: 0.166.0: 0.8 GB 0.167.0: 9.1 GB 0.169.0: 5.7 GB

It doesn't depend on which session is opened. A plain "codex" launch with no arguments costs the same, and opening the same session in a CODEX_HOME that contains only that session stays under 0.8 GB on both versions.

What steps can reproduce the bug?

  1. Have a CODEX_HOME where some recently active threads have large rollouts (1 GB or more).
  2. Launch codex (or codex resume ) on 0.169.0 and watch the process's RAM for 15 seconds.
  3. Repeat on 0.166.0.

At startup 0.169.0 sends 4 thread/list and 6 thread/turns/list requests, and 0.166.0 sends neither. The turns requests go to three other threads with 1.8 GB, 1.3 GB and 1.3 GB rollouts, and each one logs "Resuming rollout from ". Memory climbs while those requests run, peaks around 13 seconds, then drops back to 0.3 GB.

What is the expected behavior?

Launching a session shouldn't load the full rollouts of other threads, and startup memory shouldn't grow with the size of other sessions.

Additional information

It looks like the command center refresh enabled for embedded sessions in #58238. start_agents_overview_refresh in tui/src/app/agents_overview_threads.rs calls ThreadTurnsList with limit 1 for each thread, up to 16 at a time, just to show a preview. On the server that seems to go through the rollout loader in rollout/src/recorder.rs (around line 1146), which reads the whole file into memory. So even a 1-turn request costs as much as the full rollout.

The log also shows these warnings, which first appeared right after I updated to 0.167.0: state db discrepancy during list_threads_db: stale_db_path_retained state db list_threads returned stale rollout path for thread

Pinning 0.166.0 works around it. I couldn't find a setting that turns the refresh off.

dave00000 avatar Nov 14 '26 22:11 dave00000

One additional implementation/regression distinction from current main source review:

  • In codex-rs/tui/src/app/agents_overview_threads.rs, the startup overview requests ThreadRead { include_turns: false } and then ThreadTurnsList { limit: Some(1), items_view: None } for selected recent/loaded thread IDs (up to 16 reads in flight). The second request is the expensive one for legacy rollouts.
  • In codex-rs/app-server/src/request_processors/thread_processor.rs, thread_turns_list_response_inner calls load_thread_turns_list_history before build_thread_turns_page_response; the loader requests StoreReadThreadParams { include_history: true }. The code itself notes that the legacy path replays the entire rollout for each page. Therefore lowering limit or changing itemsView to NotLoaded does not bound legacy I/O or memory, and only reducing concurrency would limit the spike without removing the cause. Paginated-history threads have a separate list_turns path, so they should be a distinct regression control.
  • By contrast, the thread/read metadata-only path with includeTurns=false uses read_stored_thread_for_read(..., include_history: false). That appears to give the overview a way to keep row metadata/unread state without forcing an unrelated legacy transcript into memory.

A narrow mitigation to evaluate would be metadata-only discovery on startup/reconnect for unloaded legacy sessions, with transcript preview hydration deferred until genuinely needed (and bounded appropriately for large selected legacy rollouts). It should preserve loaded-session previews and overview membership without silently forcing huge cold sessions to replay.

Suggested regression: put a 1–3 GB legacy rollout alongside a small selected session in one CODEX_HOME; launch both plain codex and codex resume <small-id>, assert overview metadata still appears but no thread/turns/list/rollout-history read occurs for the unrelated cold session, and measure peak RSS. Include a paginated-history positive control and an itemsView=NotLoaded legacy negative control so a superficial one-turn/view change cannot falsely pass. This is source-level analysis only; I have not reproduced the reporter's affected runtime or implemented a fix.

84dnnvbdvp-debug avatar Nov 14 '26 22:11 84dnnvbdvp-debug