Skip to content

TUI freeze during agent fan-out #16688

Closed

Description

@Auties00

What version of Codex CLI is running?

codex-cli 0.118.0

What subscription do you have?

Codex Pro

Which model were you using?

gpt-5.4

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

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

Windows Terminal (Command Prompt)

What issue are you seeing?

When spawning a large number of sub-agents (e.g. 100), the TUI becomes completely unresponsive.

What steps can reproduce the bug?

  1. Start the Codex TUI.
  2. Have the model (or a skill) issue many spawn_agent tool calls in a single turn (e.g. 100 noop agents).
  3. The TUI freezes

What is the expected behavior?

The TUI should remain responsive and codex should not freeze indefinitely.

Additional information

I've already fixed this issue locally, but like for the other issue I opened I noticed that PRs require approval before being opened.
I wanted to attach videos directly, but for whatever reason GitHub is not allowing me: https://streamable.com/63gerb

Activity

  1. added
    CLIIssues related to the Codex CLI
    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal display
    tool-callsIssues related to tool calling
    on Apr 3, 2026
  2. github-actions commented on Apr 3, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  3. added
    agentIssues related to the core agent loop
    and removed
    CLIIssues related to the Codex CLI
    tool-callsIssues related to tool calling
    on Apr 3, 2026
  4. etraut-openai commented on Apr 3, 2026

    @etraut-openai
    Contributor

    Do you have reason to believe this is a recent regression? If you downgrade to 0.116.0, for example, are you able to repro the problem still? I ask because this affects prioritization.

  5. Auties00 commented on Apr 4, 2026

    @Auties00
    Author

    Do you have reason to believe this is a recent regression? If you downgrade to 0.116.0, for example, are you able to repro the problem still? I ask because this affects prioritization.

    Happens in that version as well, not sure if it ever worked corretly. If it never did, Let me know if I can open a PR with the fix that works for me locally so maybe we can discuss there what's the best solution.

  6. etraut-openai commented on Apr 4, 2026

    @etraut-openai
    Contributor

    You mentioned that you've "already fixed the issue locally". I presume that you've analyzed the problem and understand the root cause. Can you explain what you've found?

    Starting 100 subagents is outside the bounds of the current design. By default, we limit the max number to 6. You've presumably overridden that default value of agents.max_threads in your config file. If you start significantly more than 6 subagents, you'll likely hit 429's on the responses API because you'll trigger DDoS detection, so even if the client didn't hang here, you probably wouldn't be able to get this to work. If there's a straightforward fix to prevent hangs, we will entertain it, but I think we'd consider this a low priority.

  7. removed
    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal display
    on Apr 4, 2026
  8. Auties00 commented on Apr 8, 2026

    @Auties00
    Author

    You mentioned that you've "already fixed the issue locally". I presume that you've analyzed the problem and understand the root cause. Can you explain what you've found?

    Starting 100 subagents is outside the bounds of the current design. By default, we limit the max number to 6. You've presumably overridden that default value of agents.max_threads in your config file. If you start significantly more than 6 subagents, you'll likely hit 429's on the responses API because you'll trigger DDoS detection, so even if the client didn't hang here, you probably wouldn't be able to get this to work. If there's a straightforward fix to prevent hangs, we will entertain it, but I think we'd consider this a low priority.

    Actually the API doesn't throw a 429, it could be because my test agents don't do that much work.
    Also keep in mind i could reproduce the issue even with 10 agents (I'm running an i7 9700K and 16GBs of DDR4 3200 RAM which seems reasonable for such a workload).
    As for the issues I found:

    • Blocking thread_read RPC in the TUI event loop
      hydrate_collab_agent_metadata_for_notification was making a synchronous thread_read RPC to the embedded app-server for every agent notification. When the app-server was busy handling 100 concurrent spawn requests, that RPC queued behind all the spawn work and blocked the TUI event loop. While this was happening, crossterm kept queueing tick events, so after the block finally resolved, each queued tick triggered an expensive render (4+ seconds each), compounding the freeze.

    • SQLite connection pool contention
      Each agent was calling StateRuntime::init(), which opens 2 new SQLite connection pools (state + logs, max_connections(5) each), all pointing at the same DB files, runs migrations (write lock) and attempts VACUUM (exclusive lock).
      With 100 agents: 200 pools, up to 1,000 connection attempts, all fighting for SQLite's file-level locks. Process inspection showed 483 threads, mostly blocked on SQLite.

    • node --version subprocess per agent
      Not that important, but i still fixed it: Codex::spawn_internal calls resolve_compatible_node() up to twice per agent (once for JsRepl, once for CodeMode) and each call spawns node.exe as a subprocess to run node --version.

    • spawn_agent serialized through a write lock
      spawn_agent had supports_parallel_tool_calls = false, which in ToolCallRuntime::parallel forced every spawn call to acquire an exclusive RwLock write guard. With 100 spawn tool calls from a single turn, they executed one at a time, each waiting for the previous to complete session init. This doesn't seem to cause any regressions from the automated tests or my own testing, but maybe there was a reason why supports_parallel_tool_calls was set to false.

  9. added
    subagentIssues involving subagents or multi-agent features
    and removed
    agentIssues related to the core agent loop
    on Apr 11, 2026
  10. 4 remaining items

  11. 92645417d9e5c763259dbebc306e3e commented on Apr 18, 2026

    @92645417d9e5c763259dbebc306e3e

    I can reproduce this on 0.121 on Linux.
    In a clean session, I opened sub-agents one by one without forking the main-session context, closed each immediately, and paused 5 seconds between iterations. Around 20 agents, /agent + Tab already took ~5s to show the menu; around 50 agents, ~10s.
    In a real session, once it goes past ~20, even waiting 10 minutes does not recover it.

  12. panoanx commented on Apr 19, 2026

    @panoanx

    I can reproduce this in my local machine. Codex stuck forever when spawning even like 4+ agents and i have to manually kill the whole window (Ctrl+C, Ctrl+Z do not work either). Btw I'm on a NFS machine (high latency on read/writes) . I'm not sure if it's related.

    --
    update: after mentioning these, i tried moving the whole ~/.codex to a local ssd mount point. it works way much better. Spawning is fast but navigating through /agent still sometimes stucks.

  13. djdomi commented on May 5, 2026

    @djdomi

    I can reproduce this in my local machine. Codex stuck forever when spawning even like 4+ agents and i have to manually kill the whole window (Ctrl+C, Ctrl+Z do not work either). Btw I'm on a NFS machine (high latency on read/writes) . I'm not sure if it's related.

    -- update: after mentioning these, i tried moving the whole ~/.codex to a local ssd mount point. it works way much better. Spawning is fast but navigating through /agent still sometimes stucks.

    Hi,

    since i bought exact for one month Pro, i got this updates for you:

    For the 128 update:

    • Spawning more agents as 9 gets instant TUI crash, wait for 15-30 mins. The reason is, its only the TUI the work will be done.
    • Using NFS: I did not have any issues regarding this, due i use SSD as a backend, so only the Gbit is the "slowness" for startup.
    • Setting logs_2.sqlite to read only, fixed a lot of problems with TUI crashes, i dont know what exactly it prevents, but it stops growing infinite and the tui lasted for me longer (as said, i do not recommended it, but i also using the "YOLO" mode on Codex....)
    -r--r--r--  1 codex codex        0 30. Apr 23:22 logs_2.sqlite
    

    So it seems still, there is a problem, the only thing i did not tried to say codex, to wait x seconds after each spawn, if it will help or crash directly

    For the dev:
    Uploaded thread: 019d4a69-9705-76f3-9d72-0d417bb7f17d

  14. Auties00 commented on May 5, 2026

    @Auties00
    Author

    I'm not able to repro the problem as stated. I've set max_threads to 100, then asked the main agent to spawn 100 subagents, and then used /agents to view the list and switch to various subagents. It takes about a second to display the full list, but at no point does the TUI appears to be "unresponsive".

    When you say that you type /agents and then press Tab, are you pressing Return before Tab (to display the agent list)? Or are you pressing tab immediately after /agents? In neither case do I see any freeze.

    If you think that you have a "fix" for this issue, please describe the root cause. I'm not looking for a list of speculations but the verified root cause.

    are you running on windows or linux? It could be a windows only issue.

    also I don't think I ever said I was sending a /agents command, all I did was run a skill that spawned the agents and the TUI would freeze.

    i've listed the issues i've found in my second message, if you are asking which one I think is reponsible for the TUI freeze than it's the first one I've listed, the others are performance issues, but they are not strictly required to fix the TUI freezing.

    Here is my fork, in which the TUI doesn't freeze: https://github.com/Auties00/codex

  15. djdomi commented on May 5, 2026

    @djdomi

    hey I told my codex to take a sleep 0.5 between the spawns and to let me work with 12 agents,maybe a try worth

  16. Auties00 commented on May 5, 2026

    @Auties00
    Author

    hey I told my codex to take a sleep 0.5 between the spawns and to let me work with 12 agents,maybe a try worth

    Do you mind compiling my branch and trying it out? Just to see if it fixes your issue as well (if you ask codex it should be able to compile it for you quiite easily)

  17. added a commit that references this issue on May 9, 2026
    90c0bec
  18. 92645417d9e5c763259dbebc306e3e commented on May 11, 2026

    @92645417d9e5c763259dbebc306e3e

    I found the regression. PR #21870 stopped doing synchronous thread/read metadata hydration on the TUI render path, which was the right performance direction because large fan-outs could block the UI. The side effect is that collab rows can now render before the TUI has
    learned each child agent’s nickname/role, so wait/follow-up rows fall back to raw thread UUIDs even though /agent later has the proper names.

  19. added a commit that references this issue on May 15, 2026
    e3c5bcb
  20. added a commit that references this issue on Jun 27, 2026
    57e7f6e
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

    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displaybugSomething isn't workingperformancesubagentIssues involving subagents or multi-agent features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions