codex resume can OOM on very large local session JSONL
Codex CLI Issue: resume of very large local session needs excessive RAM/swap
Status: reported upstream after this run.
Summary
codex resume <session_id> can require an extremely large transient amount of
RAM/swap when the local session JSONL is very large. In this workstation, a
long-running production migration session caused the CLI process to be killed
by the OS unless roughly 80 GiB of swap was temporarily available. After the
session loads, memory usage stabilizes, which suggests the peak occurs during
resume/parsing/indexing rather than during normal interaction.
Environment
- Codex CLI:
codex-cli 0.139.0 - OS: Linux workstation
- Local Codex data size:
86Gunder~/.codex - Largest local session files observed:
37,776,204,485bytes17,861,589,428bytes17,657,202,793bytes17,657,089,210bytes
Actual Behavior
Resuming the long session creates a large transient memory spike. If the
machine does not have enough RAM/swap, the OS kills the Codex CLI process. The
user then needs to add a very large swap file only to resume the session.
Expected Behavior
- Resume should stream or lazily index large session files instead of loading
enough data to create a large memory spike.
- If the session is too large to resume safely, the CLI should fail early with
an actionable message.
- The CLI should offer a supported way to compact, prune, archive, split, or
export a handoff from a large session before it becomes unresumable.
Reproduction Shape
- Work in a single Codex session for multiple days.
- Let the session JSONL grow to tens of GiB.
- Run
codex resume <session_id>on a workstation without very large swap. - Observe process termination by the OS during resume.
Current Workaround
For this repository, operational continuity is now moved into versioned runbooks
and control files so a new session can start from files instead of depending on
resuming a huge transcript. This avoids project risk, but it does not solve the
CLI resume behavior.
Requested Improvement
Add one or more of:
- lazy/streaming resume for large local JSONL sessions;
- a persistent session compaction or split command;
- a size warning before resume;
- a supported handoff export that lets users start a clean session without
losing the important operational context.
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I reviewed the duplicate candidates from the bot:
This report is specifically about the local CLI
codex resume <session_id>path on Linux exhausting memory while hydrating a very large preserved session. The observed workaround is adding a very large swap file just for the initial resume spike; after hydration, memory stabilizes. That points to an unbounded eager load/materialization issue in the resume path, even without using the Desktop surface.I am keeping this open unless maintainers prefer consolidating CLI resume memory behavior under one of the Desktop/session JSONL issues.
A useful closeout test would separate "resume enough to continue" from "hydrate the whole JSONL into memory."
For very large rollouts, the resume path can build a lightweight index first: session_meta, compaction boundaries, latest user/assistant turns, tool-call ids, byte offsets, and token/count metadata. Large bodies such as base64 images, huge tool outputs, and old function outputs can stay as offset-addressed records until the UI/model actually needs them.
I would expect three behaviors:
That would also make this distinct from the Desktop image-heavy issues: the CLI resume invariant is "stream/index first, materialize bodies lazily."
---
_Generated with ax._
Hi @jselvareef, that rollout size is valuable stress evidence. Codex Rescue Alpha5 scans large local session histories with bounded memory and produces aggregate size, media, and compaction diagnostics without loading the whole file into RAM or dumping full payloads.
If you still have an affected closed rollout, you can test it locally:
No raw session upload is needed; sanitized aggregate output is sufficient.