Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(codex): a shared-identity node keeps a per-project unique node id

Claude Code50f149a03671
diff --git a/src/core/codex-identity-proxy.ts b/src/core/codex-identity-proxy.ts
index 1e4918a9a..9670adc9f 100644
--- a/src/core/codex-identity-proxy.ts
+++ b/src/core/codex-identity-proxy.ts
@@ -602,7 +602,20 @@ nt_preflight() {
# <CODEX_HOME>/packages/standalone/current/codex". Caps normally keeps that second case away from
# here entirely, but the pane resolves CODEX_HOME from its OWN environment (§8.5) and an install
# can be removed after boot, so the launcher still has to be able to say which it hit.
- if ${appServerStartCommand}; then
+ #
+ # The app-server is a PERSISTENT DAEMON: the FIRST codex node to reach here starts it and every
+ # later node reuses it. Start it in a SUBSHELL with THIS node's per-pane NODETERM_* scrubbed, or
+ # the daemon — and every tool shell it later spawns for EVERY node — would inherit this one node's
+ # NODETERM_NODE_ID. The thread → node resolver (codex-thread-identity-sh.ts) only recovers the
+ # right node when a tool shell has NO NODETERM_NODE_ID; a leaked value makes its guard no-op and
+ # silently collapses every codex node's identity onto whichever node started the daemon, so
+ # Project B's codex lists Project A's links and routes to A (#350). NODETERM_CODEX_ACCOUNT_ID is
+ # the ONE var deliberately KEPT: one daemon serves one account, and the resolver reads it from the
+ # daemon's env to pick the record scope. The unset runs BEFORE the (test-injected) start command.
+ if ( unset NODETERM_NODE_ID NODETERM_HOOK_ENDPOINT NODETERM_HOOK_PORT NODETERM_HOOK_TOKEN \\
+ NODETERM_HOOK_SOCK NODETERM_AGENT_ID NODETERM_CANVAS_CONTROL NODETERM_NODE_TOKEN_DIR \\
+ NODETERM_PERM_WAIT_SECS
+ ${appServerStartCommand} ); then
return 0
fi
if [ -x "\${CODEX_HOME:-$HOME/.codex}/packages/standalone/current/codex" ]; then
diff --git a/src/core/codex-launcher-sh.test.ts b/src/core/codex-launcher-sh.test.ts
index 11a17c3da..48271316c 100644
--- a/src/core/codex-launcher-sh.test.ts
+++ b/src/core/codex-launcher-sh.test.ts
@@ -185,6 +185,40 @@ describe('generated Codex launcher', () => {
expect(fallbacks).toEqual([])
})
+ // #350 (the confused deputy): the shared app-server is a PERSISTENT DAEMON started by the FIRST
+ // codex node to launch, and reused by every later node. If the launcher starts it while THIS
+ // node's per-pane NODETERM_NODE_ID is in the environment, the daemon — and every tool shell it
+ // later spawns for EVERY node — inherits that one node's id. The thread→node resolver only
+ // recovers the right node when the tool shell has NO NODETERM_NODE_ID (its guard is
+ // `[ -z "$NODETERM_NODE_ID" ]`), so a leaked value silently collapses every codex node's identity
+ // onto the daemon-starting node: Project B's codex then lists Project A's links and routes to A.
+ // The daemon MUST therefore be started with the per-pane vars scrubbed. NODETERM_CODEX_ACCOUNT_ID
+ // is the ONE exception — one daemon serves one account, and the resolver reads it to pick scope.
+ it('starts the shared app-server daemon WITHOUT this node\'s per-pane NODETERM_NODE_ID (#350)', async () => {
+ const envDump = path.join(dir, 'daemon-env.txt')
+ const dumpScript = path.join(dir, 'dump-daemon-env.sh')
+ fs.writeFileSync(
+ dumpScript,
+ `#!/bin/sh\n` +
+ `printf 'NID=[%s]\\nACC=[%s]\\nHOOK=[%s]\\n' ` +
+ `"\${NODETERM_NODE_ID-}" "\${NODETERM_CODEX_ACCOUNT_ID-}" "\${NODETERM_HOOK_ENDPOINT-}" ` +
+ `> ${JSON.stringify(envDump)}\n`,
+ { mode: 0o755 }
+ )
+ const script2 = path.join(dir, 'nodeterm-codex-envdump')
+ fs.writeFileSync(script2, buildCodexLauncherScript(JSON.stringify(dumpScript)), { mode: 0o755 })
+
+ await callLauncher([], { NODETERM_CODEX_ACCOUNT_ID: 'acct-A' }, script2)
+
+ const dumped = fs.readFileSync(envDump, 'utf8')
+ // The per-pane node id is scrubbed for the daemon (else its tool shells all report node-1).
+ expect(dumped).toContain('NID=[]')
+ // …and the per-pane hook endpoint too — a tool shell recovers it per-thread from the record.
+ expect(dumped).toContain('HOOK=[]')
+ // The account scope is deliberately preserved: the resolver needs it to pick the record scope.
+ expect(dumped).toContain('ACC=[acct-A]')
+ })
+
it('keeps the caller arguments after the thread it resolved', async () => {
await callLauncher(['--ask-for-approval', 'never', 'fix the bug'])
expect(codexArgv()).toEqual([
diff --git a/src/core/codex-thread-identity-sh.test.ts b/src/core/codex-thread-identity-sh.test.ts
index b3465bbb5..101322d54 100644
--- a/src/core/codex-thread-identity-sh.test.ts
+++ b/src/core/codex-thread-identity-sh.test.ts
@@ -74,6 +74,23 @@ describe('codex thread identity prelude', () => {
)
})
+ // #350, at the resolver: two projects, a codex node in each with its OWN thread. A daemon-spawned
+ // tool shell for Project B's thread — with the daemon env CLEAN (no leaked NODETERM_NODE_ID, which
+ // is what the launcher fix guarantees) — must recover B's node and NEVER A's. This is the
+ // cross-project isolation the confused-deputy broke: when the daemon leaked node-A's id the guard
+ // above no-opped and B's tool shell stayed node-A, so B listed A's links and routed to A.
+ it('cross-project isolation: a clean tool shell for project B resolves B, never A (#350)', async () => {
+ record('thread-A', `nodeId=node-A\nendpoint=${dir}/hook-endpoint.env\nsignature=x\n`)
+ record('thread-B', `nodeId=node-B\nendpoint=${dir}/hook-endpoint.env\nsignature=x\n`)
+ const resolvedB = await resolve({ CODEX_THREAD_ID: 'thread-B' })
+ expect(resolvedB).toBe(`node-B|${dir}/hook-endpoint.env|1`)
+ expect(resolvedB).not.toContain('node-A')
+ // And symmetrically, A's thread never resolves to B.
+ expect(await resolve({ CODEX_THREAD_ID: 'thread-A' })).toBe(
+ `node-A|${dir}/hook-endpoint.env|1`
+ )
+ })
+
it('is inert for every other agent (no CODEX_THREAD_ID, no record)', async () => {
expect(await resolve({})).toBe('||')
expect(await resolve({ CODEX_THREAD_ID: 'unknown-thread' })).toBe('||')