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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(accounts): never bind a Claude account id to a Codex node
review7bbe76086bd2
diff --git a/src/renderer/state/workspace.account-color.test.ts b/src/renderer/state/workspace.account-color.test.tsindex a53c99f8f..895034f29 100644--- a/src/renderer/state/workspace.account-color.test.ts+++ b/src/renderer/state/workspace.account-color.test.ts@@ -162,3 +162,26 @@ describe('createAgentNode — account default color', () => {expect(createAgentNode('claude', 0).data.color).toBe(AGENT_COLOR('claude'))})})++// Issue #1423. The canvas-control open paths, the board's `+ New` and the cross-project open all+// resolve ONE account against the Claude list and hand it to this factory whatever the agent is.+describe('createAgentNode — an inherited account must belong to the agent’s provider', () => {+ it('does not stamp a Claude account id on a Codex node', () => {+ withAccounts([account('claude-acct', '#0a84ff')])+ const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, 'claude-acct')+ expect(node.data.accountId).toBeUndefined()+ expect(node.data.color).toBe(AGENT_COLOR('codex'))+ })++ it('keeps a Codex account on a Codex node', () => {+ withAccounts([account('claude-acct')], [codexAccount('cx1')])+ const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, 'cx1')+ expect(node.data.accountId).toBe('cx1')+ })++ it('keeps a Claude account on a Claude node', () => {+ withAccounts([account('claude-acct')])+ const node = createAgentNode('claude', 0, undefined, undefined, undefined, undefined, 'claude-acct')+ expect(node.data.accountId).toBe('claude-acct')+ })+})diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.tsindex 88ef0065a..3b8599f68 100644--- a/src/renderer/state/workspace.test.ts+++ b/src/renderer/state/workspace.test.ts@@ -24,6 +24,7 @@ import {selectedRootIds,ungroupNodes} from './workspace'+import { useSettings } from './settings'import type { CanvasNode } from './workspace'import type { Project } from '@shared/types'@@ -840,9 +841,21 @@ describe('accountId on Claude node factories', () => {const node = createAgentNode('claude', 0, undefined, undefined, undefined, undefined, 'a1')expect(node.data.accountId).toBe('a1')})- it('stamps accountId onto a Codex agent node (S6 per-node account picker)', () => {+ it('stamps a CODEX accountId onto a Codex agent node (S6 per-node account picker)', () => {+ // The id must be one the Codex list owns: the two account lists share an id alphabet, and a+ // Claude account id on a Codex node is refused at spawn (issue #1423).+ const before = useSettings.getState().settings+ useSettings.setState({ settings: { ...before, codexAccounts: [{ id: 'a1', label: 'a1' }] } })+ try {+ const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, 'a1')+ expect(node.data.accountId).toBe('a1')+ } finally {+ useSettings.setState({ settings: before })+ }+ })+ it('does not stamp an id the Codex list does not own onto a Codex agent node (#1423)', () => {const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, 'a1')- expect(node.data.accountId).toBe('a1')+ expect(node.data.accountId).toBeUndefined()})it('does not stamp accountId onto a non-account agent node', () => {// Accounts bind to the Claude/Codex builtins only — another agent never carries one.diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex 8c417a27e..522d8de0f 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -21,7 +21,7 @@ import {import { assembleLaunchCommand, assembleResumeCommand } from '@shared/agents/launch'import { heldLaunchIntentFor } from '@shared/agents/launch-intent'import { agentAccountColor } from '@shared/agents/account-color'-import { boundAccountId } from '@shared/agents/account-binding'+import { ownedAccountId } from '@shared/agents/account-binding'import { agentEnvSnapshot } from '../lib/agentEnv'import { uuid } from '@renderer/lib/uuid'import { COLLAPSED_HEIGHT, expandRectToGrid, NODE_MIN_SIZES, snapNodeToGrid, type Rect } from '../lib/nodeSizing'@@ -833,11 +833,16 @@ export function createAgentNode(resumeSessionId?: string): CanvasNode {const { label, color: agentColor } = resolveAgent(agentId)+ const settings = useSettings.getState().settings// ONE binding decision, shared with the phone-registration path (core/project-node-append) so// "which agents bind a managed account" has a single definition instead of a ternary the canvas// enforces and the registrar does not. It feeds both `data.accountId` below and the color here,- // which is what keeps the two from drifting apart.- const bound = boundAccountId(accountId, agentId)+ // which is what keeps the two from drifting apart. `ownedAccountId` adds the provider check on+ // top: a Claude account id inherited from the opener or the project default must never bind a+ // Codex node — the Codex scope gate refuses it at spawn and the node sits QUEUED (issue #1423).+ const bound = ownedAccountId(accountId, agentId, (id) =>+ (settings.codexAccounts ?? []).some((a) => a.id === id)+ )// A managed account's default node color (Settings → Accounts) replaces the agent's brand color,// so a second login of either builtin is recognizable on the canvas at a glance.// `agentAccountColor` asks the list that OWNS this agent's accounts — the two are keyed@@ -845,7 +850,6 @@ export function createAgentNode(// `?? []` on both lists, matching the phone path in `src/main`: `mergeSettings` merges without// checking, so a hand-edited `"claudeAccounts": null` survives load and would throw on `.find`// one level ABOVE the `typeof color` guard — i.e. the very failure that guard exists to prevent.- const settings = useSettings.getState().settingsconst color =agentAccountColor(agentId, bound, {claude: settings.claudeAccounts ?? [],diff --git a/src/server/headless-node-factory.test.ts b/src/server/headless-node-factory.test.tsindex 13578f5b1..594942c2e 100644--- a/src/server/headless-node-factory.test.ts+++ b/src/server/headless-node-factory.test.ts@@ -1699,6 +1699,35 @@ describe('HeadlessNodeFactory', () => {expect(pty.sends).toEqual([{ nodeId: id, text: "claude 'brief'" }])})+ // Issue #1423: the node carries ONE `accountId` for either builtin, so a Claude opener's account+ // id used to be copied onto a Codex node, which the Codex scope gate refuses at spawn.+ describe('open-agent inherits the opener’s account only into the same provider', () => {+ const openedBy = async (accountId: string, agent: string): Promise<CanvasNodeState> => {+ const ws = await store.load({ sideline: false })+ ws.projects[0].nodes = ws.projects[0].nodes.map((n) =>+ n.id === 'term-source' ? { ...n, accountId } : n+ )+ await store.save(ws)+ const reply = await factory.openAgent('term-source', { agent, prompt: 'brief' }, true)+ expect(reply.ok).toBe(true)+ const id = (reply.result as { id: string }).id+ return (await store.load({ sideline: false })).projects[0].nodes.find((n) => n.id === id)!+ }++ it('does not hand a Claude account id to a Codex node', async () => {+ expect((await openedBy('claude-acct', 'codex')).accountId).toBeUndefined()+ })++ it('still hands a Claude account to a Claude node', async () => {+ expect((await openedBy('claude-acct', 'claude')).accountId).toBe('claude-acct')+ })++ it('hands a Codex account to a Codex node', async () => {+ settingsOverride = { codexAccounts: [{ id: 'cx1', label: 'cx1' }] }+ expect((await openedBy('cx1', 'codex')).accountId).toBe('cx1')+ })+ })+it('refuses --run-now with --after on open-terminal before anything is created, saved or sent (#925)', async () => {states['term-upstream'] = 'working'const save = vi.spyOn(store, 'save')diff --git a/src/server/headless-node-factory.ts b/src/server/headless-node-factory.tsindex 643f9bc18..57adffe19 100644--- a/src/server/headless-node-factory.ts+++ b/src/server/headless-node-factory.ts@@ -36,6 +36,7 @@ import {type BuiltinAgentId} from '../shared/agents/config'import { assembleLaunchCommand } from '../shared/agents/launch'+import { ownedAccountId } from '../shared/agents/account-binding'import type { AgentState, NormalizedAgentEvent } from '../shared/agents/normalize'import { oneLine } from '../shared/one-line'import { rootPositionWith } from '../shared/root-position'@@ -1608,6 +1609,15 @@ export class HeadlessNodeFactory {...(successHold ? { afterSuccess: successHold } : {})}: undefined+ // The opener's account, when the new agent's PROVIDER owns it. The node carries one+ // `accountId` for either builtin, so a Claude opener used to hand its Claude account id to+ // a Codex node, which the Codex scope gate then refused at spawn (issue #1423).+ const inheritedAccountId =+ verb === 'open-agent'+ ? ownedAccountId(source.node.accountId, agentId, (accountId) =>+ (settings.codexAccounts ?? []).some((a) => a.id === accountId)+ )+ : undefinedconst node: CanvasNodeState = {id,kind: 'terminal',@@ -1623,10 +1633,7 @@ export class HeadlessNodeFactory {...(args.model && verb === 'open-agent' ? { agentModel: args.model } : {}),...(issueRef && verb === 'open-agent' ? { issueRef } : {}),...(mintedSessionId ? { agentSessionId: mintedSessionId } : {}),- ...(source.node.accountId && verb === 'open-agent' &&- (agentId === 'claude' || agentId === 'codex')- ? { accountId: source.node.accountId }- : {}),+ ...(inheritedAccountId ? { accountId: inheritedAccountId } : {}),...(pendingLaunch ? { pendingLaunch } : {})}created.push(node)diff --git a/src/shared/agents/account-binding.test.ts b/src/shared/agents/account-binding.test.tsindex 3cf7d168e..cf3b9868e 100644--- a/src/shared/agents/account-binding.test.ts+++ b/src/shared/agents/account-binding.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest'-import { boundAccountId } from './account-binding'+import { boundAccountId, ownedAccountId } from './account-binding'describe('boundAccountId', () => {it('binds a managed account to a Claude node', () => {@@ -37,3 +37,31 @@ describe('boundAccountId', () => {expect(boundAccountId('', 'claude')).toBeUndefined()})})++// Issue #1423: `open-agent --agent codex` from a session on a managed CLAUDE account stamped that+// Claude account id on the Codex node, which the Codex scope gate then refused at spawn.+describe('ownedAccountId', () => {+ const isCodexAccount = (id: string): boolean => id === 'cx1'++ it('drops a Claude account id from a Codex node — it becomes the system login', () => {+ expect(ownedAccountId('claude-acct', 'codex', isCodexAccount)).toBeUndefined()+ })++ it('keeps a Codex account on a Codex node', () => {+ expect(ownedAccountId('cx1', 'codex', isCodexAccount)).toBe('cx1')+ })++ it('leaves a Claude node exactly as boundAccountId does', () => {+ expect(ownedAccountId('claude-acct', 'claude', isCodexAccount)).toBe('claude-acct')+ expect(ownedAccountId(undefined, 'claude', isCodexAccount)).toBeUndefined()+ })++ it('still binds nothing to an agent that owns no accounts', () => {+ expect(ownedAccountId('cx1', 'gemini', isCodexAccount)).toBeUndefined()+ expect(ownedAccountId('cx1', 'custom:abc', isCodexAccount)).toBeUndefined()+ })++ it('keeps the unstated-agent binding — the phone may send an account without an agent', () => {+ expect(ownedAccountId('claude-acct', undefined, isCodexAccount)).toBe('claude-acct')+ })+})diff --git a/src/shared/agents/account-binding.ts b/src/shared/agents/account-binding.tsindex bc24ff81e..71b459595 100644--- a/src/shared/agents/account-binding.ts+++ b/src/shared/agents/account-binding.ts@@ -41,3 +41,37 @@ export function boundAccountId(if (agentId !== undefined && !ACCOUNT_CAPABLE_AGENT_IDS.includes(agentId)) return undefinedreturn accountId}++/**+ * `boundAccountId`, plus the question it cannot answer on its own: does this id belong to the+ * provider this agent logs in with?+ *+ * Managed Claude and Codex accounts are two lists sharing one id alphabet, and both builtins are+ * account-capable, so `boundAccountId` happily binds a CLAUDE account id to a CODEX node. Every+ * path that inherits an account instead of having the user pick one does exactly that: canvas+ * control (`open-agent --agent codex` from a session on a managed Claude account stamps the+ * source's id; a project whose default account is a Claude account stamps that) and the board's+ * `+ New`. The node is then refused at spawn — the Codex scope gate (`needsCodexAccountScope` in+ * core) fails closed on an id that is not a Codex account — so it sat QUEUED forever with nothing+ * naming the account as the cause (issue #1423).+ *+ * So a Codex node keeps an id only when the Codex list owns it; anything else is the SYSTEM login+ * (`undefined`), which is what the same call produced when no Claude account was involved. That is+ * not the fail-open Property 4 forbids: nobody picked this account for this node — an EXPLICIT+ * Codex pick still goes through `resolveNewCodexNodeAccount`, which refuses rather than downgrades.+ *+ * `isCodexAccount` is required for the reason `needsCodexAccountScope` gives: the id alone cannot+ * say, and neither default is safe. Claude is not checked the other way round here — every caller+ * that hands a Claude node an id already resolved it against the Claude list+ * (`resolveNewNodeAccount`).+ */+export function ownedAccountId(+ accountId: string | undefined,+ agentId: string | undefined,+ isCodexAccount: (id: string) => boolean+): string | undefined {+ const bound = boundAccountId(accountId, agentId)+ if (bound === undefined) return undefined+ if (agentId === 'codex' && !isCodexAccount(bound)) return undefined+ return bound+}