App-server brokers started for another workspace are never shut down

Author: WotuuCreated Sep 28, 2026Updated Sep 30, 2026

: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.mjs spawnBrokerProcess: detached: true + unref(); the broker never checks whether the session that started it is alive.
  • scripts/app-server-broker.mjs: exits only on broker/shutdown, SIGTERM or SIGINT; no idle timeout.
  • scripts/lib/state.mjs resolveStateDir: keyed by a hash of the workspace root, so every git worktree gets its own broker.json.
  • scripts/session-lifecycle-hook.mjs handleSessionEnd: 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.

  1. Start Claude Code in ~/repo and create a worktree ~/repo-wt (git worktree add ../repo-wt).
  2. From that session, run a Codex review or task whose cwd is ~/repo-wt.
  3. Exit the session normally.
  4. ps -eo pid,etime,args | grep '[a]pp-server-broker.mjs serve' still shows the broker with --cwd ~/repo-wt, and its codex app-server child.

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.