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.

feat(codex): arm the identity-auth secret on Server Edition boot (S6 Decision 1)

Claude Code8597972c5a87
diff --git a/src/server/codex-identity-boot.test.ts b/src/server/codex-identity-boot.test.ts
new file mode 100644
index 000000000..526f56f9f
--- /dev/null
+++ b/src/server/codex-identity-boot.test.ts
@@ -0,0 +1,73 @@
+/**
+ * Server Edition arms the Codex identity-auth secret on boot (S6 Decision 1; carried PR-2
+ * obligation). Before PR 5 the headless shell armed ONLY `hookServer.setNodeAuthSecret(...)` and
+ * never `setCodexThreadIdentityAuthSecret(...)`, so a MANAGED Codex account's thread→node→account
+ * ownership record threw "NodeTerm Codex identity authentication is unavailable" the moment it
+ * tried to sign — the record layer was dead on every headless host.
+ *
+ * The invariant pinned here: run the EXACT boot sequence src/server/index.ts runs after
+ * `hookServer.start()`, and a managed-account resolve signs + round-trips instead of throwing.
+ * MUTATION (recorded in the PR body): delete the `setCodexThreadIdentityAuthSecret(secret)` line in
+ * src/server/index.ts (equivalently, drop it from the boot sequence below) → this suite goes red
+ * because `writeCodexThreadIdentity` for a managed account throws "unavailable".
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest'
+import fs from 'fs'
+import os from 'os'
+import path from 'path'
+import { initPlatform, resetPlatformForTests } from '../core/platform'
+import { fakePlatform } from '../core/platform-fake'
+import { loadOrCreateNodeAuthSecret, resetNodeAuthSecretForTests } from '../core/agents/node-auth-secret'
+import {
+ setCodexThreadIdentityAuthSecret,
+ resetCodexThreadIdentityAuthSecret,
+ codexThreadIdentityAvailable,
+ writeCodexThreadIdentity,
+ resolveCodexThreadNodeIdentity,
+ codexThreadIdentityRoot
+} from '../core/codex-identity-proxy'
+
+let dir = ''
+
+beforeEach(() => {
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nodeterm-server-codex-ident-'))
+ resetPlatformForTests()
+ resetNodeAuthSecretForTests()
+ resetCodexThreadIdentityAuthSecret()
+ // Server-Edition shape: no seal hooks, so the secret is stored raw (node-auth-key.bin).
+ initPlatform(fakePlatform({ userDataDir: dir }))
+})
+
+afterEach(() => {
+ resetPlatformForTests()
+ resetNodeAuthSecretForTests()
+ resetCodexThreadIdentityAuthSecret()
+ fs.rmSync(dir, { recursive: true, force: true })
+})
+
+describe('Server Edition arms the Codex identity secret on boot', () => {
+ it('a managed-account record signs + resolves after the boot sequence, instead of throwing unavailable', async () => {
+ // Before arming: the record layer is dead.
+ expect(codexThreadIdentityAvailable()).toBe(false)
+ expect(() =>
+ writeCodexThreadIdentity('thread-a', 'node-1', '/hook', undefined, 'managed-account')
+ ).toThrow(/identity authentication is unavailable/)
+
+ // The EXACT boot sequence src/server/index.ts runs after hookServer.start().
+ const secret = await loadOrCreateNodeAuthSecret()
+ setCodexThreadIdentityAuthSecret(secret)
+
+ expect(codexThreadIdentityAvailable()).toBe(true)
+
+ // A MANAGED account (non-empty accountId) — the case that threw on a headless host — now signs
+ // and round-trips against the real on-disk record under the fake platform's data dir.
+ const root = codexThreadIdentityRoot()
+ expect(() =>
+ writeCodexThreadIdentity('thread-a', 'node-1', '/hook', root, 'managed-account')
+ ).not.toThrow()
+ expect(resolveCodexThreadNodeIdentity('thread-a', root, 'managed-account')).toBe('node-1')
+ // And the SYSTEM account (no id) keeps resolving too — legacy-root records must not regress.
+ writeCodexThreadIdentity('thread-b', 'node-2', '/hook', root)
+ expect(resolveCodexThreadNodeIdentity('thread-b', root)).toBe('node-2')
+ })
+})
diff --git a/src/server/handlers/index.ts b/src/server/handlers/index.ts
index 625670022..90b1dadc2 100644
--- a/src/server/handlers/index.ts
+++ b/src/server/handlers/index.ts
@@ -77,12 +77,15 @@ export function registerCoreHandlers(
// The secret question that used to block this is ANSWERED: src/server/index.ts arms
// `hookServer.setNodeAuthSecret(await loadOrCreateNodeAuthSecret())` at boot, which on a headless
// host is raw 0600 bytes in the data dir — a decision taken explicitly, not quietly (see
- // src/core/agents/node-auth-secret.ts). What is still missing is only the codex-specific
- // plumbing: `setCodexThreadIdentityAuthSecret(secret)`, `refreshCodexIdentityCaps()`, and the two
- // `setCodexThread*Handler` registrations src/main/index.ts makes. Everything they call already
- // lives in src/core and boots from CorePlatform, so this stays a scope line, not a blocker —
- // until it is drawn differently, saying "no" here keeps the browser's Codex nodes identical to
- // what they are today rather than half-armed.
+ // src/core/agents/node-auth-secret.ts). As of S6 PR 5 the same boot path also calls
+ // `setCodexThreadIdentityAuthSecret(secret)`, so a MANAGED Codex account's thread→node→account
+ // ownership records sign and verify on this headless host instead of throwing "identity
+ // authentication is unavailable" (the carried PR-2 obligation). What stays deliberately absent
+ // here is the shared-app-server plumbing (`refreshCodexIdentityCaps()` + the two
+ // `setCodexThread*Handler` registrations src/main/index.ts makes): the Server Edition answers "no
+ // shared identity" so its Codex nodes launch the bare `codex` — a working node with its own
+ // app-server, just without the shared one. Arming the record secret is orthogonal to that
+ // degrade: it never launches an app-server, it only lets the record layer sign.
registerCodexIdentityIpc(() => UNKNOWN_CODEX_IDENTITY_CAPS)
// Claude subscription usage. Previously desktop-only — the browser bridge answered `null`, so
diff --git a/src/server/index.ts b/src/server/index.ts
index 71c6f1f6b..6eebc1997 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -38,6 +38,7 @@ import os from 'os'
import { hookServer } from '../core/agents/hook-server'
import { serverEditionControlHandler } from './control-unsupported'
import { loadOrCreateNodeAuthSecret } from '../core/agents/node-auth-secret'
+import { setCodexThreadIdentityAuthSecret } from '../core/codex-identity-proxy'
import { initNodeTokens, refreshNodeTokens } from '../core/agents/node-token-service'
import {
writePendingAnswerLocal,
@@ -476,7 +477,17 @@ export async function startServer(
// arming the secret, and a headless host in legacy mode is where it is most likely to be needed.
hookServer.setIdentityStrictOverride(() => settingsStore.get().hookIdentityStrict)
try {
- hookServer.setNodeAuthSecret(await loadOrCreateNodeAuthSecret())
+ const nodeAuthSecret = await loadOrCreateNodeAuthSecret()
+ hookServer.setNodeAuthSecret(nodeAuthSecret)
+ // S6 (Decision 1, carried from PR 2 review): arm the SAME secret for the Codex thread→node→
+ // account identity records so a MANAGED Codex account on a headless host can sign/verify its
+ // ownership records instead of throwing "identity authentication is unavailable". This is the
+ // both-shells half of the secret: desktop arms it in src/main/index.ts, and the Server Edition
+ // — which runs the managed-account + relay + switch protocol just as the desktop does — must
+ // arm it here too, or every managed-account resolve throws. The shared-app-server DEGRADE
+ // (Codex nodes launch bare, no launcher on PATH) is a SEPARATE, deliberate scope decision and
+ // is unaffected: this only makes the record layer able to sign.
+ setCodexThreadIdentityAuthSecret(nodeAuthSecret)
// Materialise a token file for every persisted node so an already-running session becomes
// verified at its next hook event with no restart. No-ops into legacy mode without a secret.
initNodeTokens({ canvases: () => workspaceStore.persistedCanvases() })