App-server brokers started for another workspace are never shut down
:robot: Summary. A broker (node scripts/app-server-broker.mjs serve) plus its codex app-server child is started per workspace root and runs detached with no idle timeout. The only thing that stops it is the SessionEnd hook, which looks up broker.json for input.cwd only. A broker started for any other workspace root in the same Claude Code session — for example a review run against a git worktree of the repository — is never found and lives forever.
Impact. Over about 18 days of normal use on one machine: ~80 leaked brokers, each with a codex app-server, and each app-server with its configured stdio MCP servers. The MCP servers alone were ~150 processes polling constantly (~2 CPU cores in total), and a shared MCP daemon they connect to stopped accepting new clients ("could not accept this client within 30000 ms"). Killing the stale brokers fixed it immediately.
Where (1.0.6).
scripts/lib/broker-lifecycle.mjsspawnBrokerProcess:detached: true+unref(); the broker never checks whether the session that started it is alive.scripts/app-server-broker.mjs: exits only onbroker/shutdown, SIGTERM or SIGINT; no idle timeout.scripts/lib/state.mjsresolveStateDir: keyed by a hash of the workspace root, so every git worktree gets its ownbroker.json.scripts/session-lifecycle-hook.mjshandleSessionEnd:loadBrokerSession(input.cwd)finds only the broker for the session's own directory.
The same leak happens without worktrees whenever SessionEnd does not run to completion (terminal closed, process killed, the hook's 5 s timeout exceeded).
Reproduction.
- Start Claude Code in
~/repoand create a worktree~/repo-wt(git worktree add ../repo-wt). - From that session, run a Codex review or task whose cwd is
~/repo-wt. - Exit the session normally.
ps -eo pid,etime,args | grep '[a]pp-server-broker.mjs serve'still shows the broker with--cwd ~/repo-wt, and itscodex app-serverchild.
Suggested fixes (any one helps; the first two together close it).
- Idle timeout in the broker: exit after N minutes with no connected sockets and no active request or stream.
- Record every broker a session starts (keyed by session id, not only by workspace) and shut all of them down in
SessionEnd. - Have the broker watch the Claude Code process that started it (pass its pid, poll
process.kill(pid, 0)), and shut down when it disappears.
Environment: plugin codex@openai-codex 1.0.6 (db52e28), Claude Code on Linux (Ubuntu 24.04 base), @openai/codex via npm on Node 24.
Source: openai/codex-plugin-cc