Memory not reclaimed after codex-cli exits in non-interactive mode
What version of Codex CLI is running?
0.106.0
What subscription do you have?
Azure OpenAI
Which model were you using?
gpt-5.1-codex
What platform is your computer?
Linux 5.14.0-503.22.1.el9_5.x86_64 x86_64 x86_64
What terminal emulator and version are you using (if applicable)?
_No response_
What issue are you seeing?
When running the codex-cli in non-interactive mode, memory used by the process is not reclaimed after shutdown.
In our case it's running inside a Debian-based Docker container (hosted on a RHEL VM) and repeating the process eventually exhausts memory and causes the sandbox container to be killed by OOM.
This appears to be a memory leak.
What steps can reproduce the bug?
Run codex-cli in non-interactive mode multiple times (example command):codex exec --json --dangerously-bypass-approvals-and-sandbox {prompt}
What is the expected behavior?
After each codex-cli invocation exits, memory usage should return to the baseline (previous) free memory level.
Repeated runs should not accumulate unreleased memory.
Additional information
_No response_
7 Comments
The OS kernel is responsible for freeing all memory associated with a process with it terminates. Are you saying that the codex process isn't terminating? Or are there other processes that are started and not getting terminated?
@etraut-openai
The codex process terminates, and I don't see any other related processes, yet overall memory usage increases after each run.
I'm not a low-level programmer, so this might not be a traditional memory leak — however, I read similar symptoms can be caused by leftover shared memory or tmpfs objects that persist between runs.
If helpful, I can collect more info or run checks to confirm whether a shared memory segment or tmpfs object is being left behind.
I'm somewhat skeptical that this is a Codex issue based on what you're saying, so I think we'll need more proof before we spend time investigating this.
@etraut-openai
OK, I’ll gather some more information and get back to you. Thanks.
Hey, I'd like to help investigate this further.
The symptoms — memory growing across repeated runs even though the process exits cleanly — are consistent with leftover POSIX shared memory objects or tmpfs allocations that aren't cleaned up on exit.
@thingersoft, if you're able to run the following before and after each
codex execinvocation, it would help narrow this down:If any entries appear after the run that weren't there before — and persist after the process exits — that would be concrete evidence of leaked resources and a clear starting point for a fix.
I can help interpret the output or dig into the Codex source to trace where shared memory or tmpfs might be allocated without a corresponding cleanup. Happy to assist if that's useful.
After further inspection I couldn't find any remaining artifacts.
The memory usage growth is still present, but it appears to be caused by processes unrelated to Codex execution.
I also found that some process exits with code 137 were due to the container lifecycle configuration rather than an OOM.
Because there's no evidence that Codex contributed to this issue, I'm closing it.
Thanks for your cooperation.
Forensic Update (artifact-backed, sanitized)
I re-analyzed the sysdiagnose archive (
codex-watchdog.tar.gz) and corrected my earlier attribution.Artifact 1: Panic excerpt (
panic-full-2026-03-04-171042.0002.panic)Interpretation: watchdog panic occurred under severe VM pressure; Codex was present at panic time, but this snippet alone does not prove primary causality.
Artifact 2: Pre-panic Jetsam timeline (
JetsamEvent-2026-03-04-*.ips)Artifact 3: Quantitative memory attribution from Jetsam snapshots
| Timestamp (+1100) | Codex total GiB | gmail-rag total GiB | largestProcess |
|---|---:|---:|---|
| 2026-03-04 16:36:33 | 1.07 | 49.06 | gmail-rag |
| 2026-03-04 16:42:26 | 1.09 | 67.55 | gmail-rag |
| 2026-03-04 17:01:57 | 1.09 | 72.85 | gmail-rag |
| 2026-03-04 17:03:17 | 1.09 | 43.67 | gmail-rag |
Correction
This dataset supports severe system memory pressure + watchdog failure, but it does not prove Codex was the primary memory driver in this incident.
What the artifacts support:
gmail-rag.I still think process-lifecycle hardening (child cleanup / process-group teardown / leak-resistant shutdown) is worth pursuing, but this specific crash should be described with the attribution above.