Skip to content

Memory leak when running multiple agents #23749

Open

Description

@aniket-yamle

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

Codex

What subscription do you have?

Pro

What platform is your computer?

Darwin 25.5.0 arm64 arm

What issue are you seeing?

My codex crashed after running the application to 128GB memory usage on Macbook pro. Can you verify if it's memory leak or somethin when you run parallel agents.

What steps can reproduce the bug?

Feedback ID: 019e4666-b55f-7482-ba26-9db616a3c078

What is the expected behavior?

No response

Additional information

Feedback 019e4666-b55f-7482-ba26-9db616a3c078

Activity

  1. added
    app
    on May 20, 2026
  2. added
    bug
    subagent
    on May 20, 2026
  3. github-actions commented on May 20, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. sigyulee commented on May 21, 2026

    @sigyulee

    Hello from #23260

    My understanding is that memory usage spikes because each subagent receives the full transcript from the parent, and MCPs are started for each subagent. Keeping the context and MCP catalog clean may help.

  5. Taridoku commented on Jun 15, 2026

    @Taridoku

    Corroborating evidence: native app-server heap, attributed to streamed-response buffers across concurrent subagent sessions

    Reproduced on the VS Code extension and captured the memory composition while it ballooned.

    Environment: VS Code Codex extension openai.chatgpt 26.609.30741, macOS 26.3.1, Apple Silicon, 17 GB RAM, gpt-5.5, model_reasoning_effort = "xhigh", [features] multi_agent = true.

    Repro: asked Codex to perform a large code-audit task. Native multi-agent fanned out to 5 new concurrent session_loop sessions spawned within 18 seconds (from the app-server's own logs):

    11:21:00  new session_loop 019ecacc-806a...  op: UserInput
    11:21:06  new session_loop 019ecacc-9734...  op: UserInput
    11:21:06  new session_loop 019ecacc-9792...  op: UserInput
    11:21:12  new session_loop 019ecacc-af54...  op: UserInput
    11:21:18  new session_loop 019ecacc-c66e...  op: UserInput
    

    Memory went from 1.7 GB to 14 GB in ~2 minutes; only an explicit op: Interrupt released it. Left unattended it freezes the machine (hard restart required).

    Memory attribution (vmmap on the live native codex app-server process):

    Physical footprint:        14.2G
    Physical footprint (peak): 17.0G   (= total RAM)
    Writable regions: swapped_out 11.1G (68%)
    MALLOC_LARGE     9.4G  (81 regions)
    MALLOC_REALLOC   4.3G  (37 regions)   <- continually re-grown buffers
    

    The footprint is almost entirely heap. The MALLOC_REALLOC mass (buffers repeatedly doubled) points to unbounded accumulation, and the busiest log targets during the spike were codex_api::endpoint::responses_websocket and codex_api::sse::responses, i.e. streamed response bodies retained per concurrent session and not released until every session completes. sample showed hot frames in codex_core::tools::parallel::ToolCallRuntime and codex_app_server_transport::transport::serialize_outgoing_message.

    Net: N concurrent subagent sessions each retain their full streamed-response context in the parent app-server heap with no cap. On a 17 GB host, roughly 5 to 6 wide is enough to exhaust RAM and freeze the OS. A per-session buffer cap, or releasing completed-stream buffers before all siblings finish, would bound it.

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

    appbugperformancesubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions