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
feat(codex): reconcile pending accounts without reviving removed ones
Claude Codeeab1fce5c34a
diff --git a/src/renderer/state/codexAccountReconcile.test.ts b/src/renderer/state/codexAccountReconcile.test.tsnew file mode 100644index 000000000..3b3e33478--- /dev/null+++ b/src/renderer/state/codexAccountReconcile.test.ts@@ -0,0 +1,65 @@+import { describe, expect, it, vi } from 'vitest'+import type { CodexAccount } from '@shared/codex-account'+import {+ applyResolvedCodexAccounts,+ discoverResolvedCodexAccounts,+ type ResolvedCodexAccount+} from './codexAccountReconcile'++const pending = (id: string, over: Partial<CodexAccount> = {}): CodexAccount => ({+ id,+ label: 'New Codex account',+ pending: true,+ ...over+})++describe('discoverResolvedCodexAccounts', () => {+ it('discovers only authenticated pending accounts', async () => {+ const accounts: CodexAccount[] = [+ pending('a'), // authenticated+ pending('b'), // still logging in (identity null)+ { id: 'c', label: 'Settled', email: 'c@x', pending: false } // not pending → never probed+ ]+ const identity = vi.fn(async (id: string) =>+ id === 'a' ? { email: 'a@x' } : null+ )+ const resolved = await discoverResolvedCodexAccounts(accounts, identity)+ expect(resolved).toEqual<ResolvedCodexAccount[]>([{ id: 'a', email: 'a@x' }])+ // The settled account 'c' is never read — probing a non-pending account is the mutation.+ expect(identity).not.toHaveBeenCalledWith('c')+ })++ it('drops an account whose identity read throws (fail-closed, no fabrication)', async () => {+ const identity = vi.fn(async () => {+ throw new Error('unreachable host')+ })+ expect(await discoverResolvedCodexAccounts([pending('a')], identity)).toEqual([])+ })+})++describe('applyResolvedCodexAccounts', () => {+ it('promotes a generated label to the email and clears pending', () => {+ const out = applyResolvedCodexAccounts([pending('a')], [{ id: 'a', email: 'a@x' }])+ expect(out).toEqual([{ id: 'a', label: 'a@x', email: 'a@x', pending: false }])+ })++ it('keeps a user-chosen label but still captures the email', () => {+ const out = applyResolvedCodexAccounts(+ [pending('a', { label: 'Work' })],+ [{ id: 'a', email: 'a@x' }]+ )+ expect(out[0]).toMatchObject({ label: 'Work', email: 'a@x', pending: false })+ })++ it('merges against fresh state without reviving removed or already-changed accounts', () => {+ // Fresh list: 'a' was already settled by a concurrent edit; 'removed' is gone entirely.+ const fresh: CodexAccount[] = [{ id: 'a', label: 'Renamed', email: 'a@x', pending: false }]+ const resolved: ResolvedCodexAccount[] = [+ { id: 'a', email: 'stale@x' }, // must NOT clobber the already-changed row+ { id: 'removed', email: 'ghost@x' } // must NOT be revived into the list+ ]+ const out = applyResolvedCodexAccounts(fresh, resolved)+ expect(out).toEqual(fresh) // untouched+ expect(out.some((account) => account.id === 'removed')).toBe(false)+ })+})diff --git a/src/renderer/state/codexAccountReconcile.ts b/src/renderer/state/codexAccountReconcile.tsnew file mode 100644index 000000000..70cc98eeb--- /dev/null+++ b/src/renderer/state/codexAccountReconcile.ts@@ -0,0 +1,65 @@+// S6 PR 8 — reconcile pending Codex accounts against the app-servers' live identity, without+// trusting attacker-controlled settings fields. Based on @Corvin's #112+// (`src/renderer/state/codexAccountReconcile.ts`).+//+// `discover` reads only the identity the account home actually holds (an authenticated `auth.json`+// yielded an email); `apply` merges that against a FRESH accounts list so a login that resolves+// late can never revive an account the user removed, nor clobber one that already changed. Nothing+// here fabricates an account: an unauthenticated / unreadable home drops out of the resolved set.++import type { CodexAccount } from '@shared/codex-account'++export interface ResolvedCodexAccount {+ id: string+ email: string | null+}++/**+ * Read the live identity of every PENDING account (only pending ones are still waiting on a+ * login). A home that has not authenticated — `identity` resolves null or throws — is omitted, so+ * the resolved set is exactly the accounts that genuinely logged in. `identity` is the caller's+ * bound reader (local `codexAccounts.identity`, or the host reader behind a live connection).+ */+export async function discoverResolvedCodexAccounts(+ accounts: readonly CodexAccount[],+ identity: (id: string) => Promise<{ email: string | null } | null>+): Promise<ResolvedCodexAccount[]> {+ const resolved = await Promise.all(+ accounts+ .filter((account) => account.pending)+ .map(async (account) => ({+ id: account.id,+ identity: await identity(account.id).catch(() => null)+ }))+ )+ return resolved.flatMap(({ id, identity: value }) =>+ value ? [{ id, email: value.email }] : []+ )+}++/**+ * Merge resolved identities onto the CURRENT accounts list. Fail-closed against staleness:+ * - only an account still present in `accounts` is touched (a removed id is never re-added — the+ * result is `accounts.map(...)`, which can only transform existing rows, never append);+ * - only an account still `pending` is promoted (`!account.pending` short-circuits, so a row that+ * already changed under a concurrent edit is left exactly as the user left it);+ * - a generated "New Codex account" label is promoted to the captured email; a user-chosen label+ * is preserved.+ */+export function applyResolvedCodexAccounts(+ accounts: readonly CodexAccount[],+ resolved: readonly ResolvedCodexAccount[]+): CodexAccount[] {+ const byId = new Map(resolved.map((account) => [account.id, account]))+ return accounts.map((account) => {+ const identity = byId.get(account.id)+ if (!identity || !account.pending) return account+ return {+ ...account,+ label:+ account.label === 'New Codex account' && identity.email ? identity.email : account.label,+ email: identity.email ?? undefined,+ pending: false+ }+ })+}