codex - 💡(How to fix) Fix Extreme Python Memory Usage in Codex (135GB RAM / 25GB swap after long session) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19600Fetched 2026-04-26 05:14:07
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×4unlabeled ×2commented ×1
RAW_BUFFERClick to expand / collapse

What version of the Codex App are you using (From “About Codex” dialog)?

Version 26.422.30944 (2080)

What subscription do you have?

Pro

What platform is your computer?

Darwin 25.4.0 arm64 arm

What issue are you seeing?

Possibly related to the high resource usage being reported:

During extended use (~4 hours, ~7 sessions without restarting Codex), a Python process spawned by Codex grew to extremely high memory usage (~135 GB in Activity Monitor), causing heavy swap usage (~25 GB) and system degradation (UI lag, audio crackling).

Restarting Codex immediately resolved the issue, suggesting the process was not being cleaned up or was accumulating state over time.

It's unclear whether this is:

  • a memory leak in a long-running Python process
  • multiple Python runtimes not being terminated between sessions
  • or unbounded in-memory data accumulation during agent execution

Environment:

  • macOS 26.4.1
  • Codex: GPT-Codex 5.3 (Medium)
  • Project located in OneDrive (high file churn, though .git has been externalised)
  • Continuous usage without restart

Additional notes:

  • I attempted to reproduce by re-running Python3 tasks in a fresh session, but memory usage remained stable.
  • This suggests the issue may be tied to long-lived processes or cumulative session state rather than a single execution.

Happy to provide logs if someone can point me to the relevant locations (Python subprocess logs, Codex agent logs, etc).

<img width="1916" height="1024" alt="Image" src="https://github.com/user-attachments/assets/99f0266c-39d4-4897-9ee8-d33e35ecb3a6" />

Steps to reproduce

Session ID: 019dbfe9-110f-78a0-8ba7-c23328b7063e
Context: ~149K / 258K token window
Duration: ~4 hours, ~7 sessions without restarting Codex

Prompt issued: "Can you go through the CORE code as all CORE pages are broken and no longer show the models, data etc; this happened after the ML learn profiles were made."

Notes:

  • "CORE" refers to a relatively small internal module responsible for aggregating and displaying data from other modules / SQLite DBs.
  • It is not a large codebase or memory-intensive component.

Codex executed: $ python3 -m py_compile engine/core/elora_core/service.py engine/admin/elora_core/pages.py engine/api/admin_routes/elora_core.py engine/api/routes_admin.py 2>&1 | sed -n '1,200p

Observed behaviour:

  • After this command (and subsequent Python3 calls), memory usage from a Python process increased continuously.
  • Memory eventually reached ~135GB, with ~25GB swap usage.
  • System became unstable (UI lag, audio crackling).
  • No additional tasks were running at the time.

Additional context:

  • System had already been under load from earlier Codex activity (high CPU usage and slowdown observed prior).
  • Activity Monitor became difficult to use during the spike, suggesting cumulative resource exhaustion over the session.
  • Re-running similar Python commands after restarting Codex did NOT reproduce the issue, suggesting it is tied to long-lived session state rather than the command itself.

Expected behaviour

  • Python subprocesses should use minimal and bounded memory for compilation commands like py_compile.
  • Memory usage should be released after execution.
  • No unbounded growth should occur from repeated or sequential Python calls.

Additional information

  • This behaviour does not occur on the same codebase when run outside Codex (e.g. on a live server).
  • No Python errors were thrown during execution.
  • Suggests possible memory leak, uncollected subprocess state, or accumulation across Codex sessions.

Happy to provide logs or process samples if directed to the correct locations. - Edited to add more information.

extent analysis

TL;DR

The issue can be mitigated by restarting Codex regularly to prevent memory accumulation from long-lived Python processes.

Guidance

  • Investigate the Python subprocess logs and Codex agent logs to determine if there's a memory leak or uncollected subprocess state.
  • Verify if the issue is specific to the Codex environment by comparing memory usage patterns when running the same Python commands outside of Codex.
  • Consider implementing a periodic restart of Codex or a mechanism to clean up subprocesses to prevent cumulative resource exhaustion.
  • Review the py_compile command and its usage within Codex to ensure it's not contributing to the memory accumulation.

Example

No code snippet is provided as the issue is more related to the environment and subprocess management rather than a specific code error.

Notes

The issue seems to be related to the Codex environment and how it manages subprocesses, rather than a problem with the Python code itself. The fact that restarting Codex resolves the issue suggests a resource accumulation problem.

Recommendation

Apply a workaround by implementing a regular restart of Codex or a mechanism to clean up subprocesses to prevent cumulative resource exhaustion, as the root cause of the issue is not immediately clear and may require further investigation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Extreme Python Memory Usage in Codex (135GB RAM / 25GB swap after long session) [1 comments, 2 participants]