Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
simplify: trim duplicated spawn-reason rationale, fold twin spawn-rejected tests into it.each
[._.]/ Adam Eivyde4dbc3aefd8
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.jsindex 4f14258d81..a553f2888a 100644--- a/server/services/agentTuiSpawning.js+++ b/server/services/agentTuiSpawning.js@@ -930,19 +930,13 @@ export async function spawnTuiAgent({// spawn error into the record. Runs outside the Express request lifecycle, so// there is no middleware to bubble to.//- // The REASON depends on which half failed. On the durable-runner path every- // throw is a runner-hop failure — a `fetch failed` while the runner restarts,- // or the runner answering with a refusal — and no agent process ever existed,- // so it finalizes as `spawn-rejected`: non-actionable, the task retries, and a- // persistent misconfiguration still blocks on MAX_TASK_RETRIES with the- // runner's own message attached. The direct-CLI runner path made this exact- // split already (agentLifecycle.js, `spawn-rejected is its own reason,- // deliberately NOT the TUI's spawn-error`); before mirroring it here, a- // momentarily-unreachable runner blocked the task for a human with "confirm- // the CLI is installed" advice and filed an investigation — five times in one- // week, for a condition a plain retry fixes. A LOCAL PTY that won't open keeps- // `spawn-error` (actionable): that is a real host/config problem a retry- // cannot repair.+ // The REASON splits on which half failed. A durable-runner throw is a+ // runner-hop failure (a `fetch failed` mid-restart, or a runner refusal) —+ // no process ever existed, so it is `spawn-rejected` (non-actionable →+ // retry), mirroring the direct-CLI runner path's deliberate split in+ // agentLifecycle.js and the registration in COMPLETION_REASON_ANALYSES. A+ // LOCAL PTY that won't open keeps the actionable `spawn-error`: that is a+ // real host/config problem a retry cannot repair.let session;try {session = await createAgentTuiSession({diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex 482febec58..f33b358dc5 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -2362,62 +2362,35 @@ describe('spawnTuiAgent runtime', () => {// `initializing` until the zombie reaper finalized it a minute later with a// generic message, so the real cause never reached the user.//- // A runner-hop failure finalizes as `spawn-rejected` (non-actionable → the- // task retries), mirroring the direct-CLI runner path in agentLifecycle.js.- // Only a LOCAL PTY failure keeps the actionable `spawn-error` (test 5 above):- // before the split, a runner mid-restart blocked the task for a human with- // "confirm the CLI is installed" advice and filed an investigation task.+ // The reason splits on the runner hop — see spawnTuiAgent's catch. Note a+ // refused/mid-restart runner surfaces from undici as a bare+ // TypeError('fetch failed').describe('spawn failure', () => {- it('finalizes a runner refusal as spawn-rejected instead of throwing', async () => {- vi.mocked(spawnTuiSessionViaRunner).mockRejectedValueOnce(- new Error('Command not allowed: grok. Permitted commands: claude, codex')- );+ it.each([+ ['a runner refusal', new Error('Command not allowed: grok. Permitted commands: claude, codex'), 'Command not allowed: grok'],+ ['an unreachable runner', new TypeError('fetch failed'), 'fetch failed'],+ ])('finalizes %s as spawn-rejected instead of throwing', async (_label, rejection, expectedFragment) => {+ vi.mocked(spawnTuiSessionViaRunner).mockRejectedValueOnce(rejection);// Resolves, does not reject.await expect(runSpawn({ useDurableRunner: true })).resolves.toBeNull();- await flushMicrotasks();expect(agentLifecycle.finalizeAgent).toHaveBeenCalledWith(expect.objectContaining({agentId: 'agent-1',success: false,completionReason: 'spawn-rejected',- error: expect.stringContaining('Command not allowed: grok'),+ error: expect.stringContaining(expectedFragment),}));});- it('finalizes an unreachable runner (fetch failed) as spawn-rejected, not the actionable spawn-error', async () => {- // Node's undici surfaces a refused/mid-restart runner as a bare- // TypeError('fetch failed') — the week-one top failure class this split- // exists for.- vi.mocked(spawnTuiSessionViaRunner).mockRejectedValueOnce(- new TypeError('fetch failed')- );-- await expect(runSpawn({ useDurableRunner: true })).resolves.toBeNull();- await flushMicrotasks();-- expect(agentLifecycle.finalizeAgent).toHaveBeenCalledWith(- expect.objectContaining({- agentId: 'agent-1',- success: false,- completionReason: 'spawn-rejected',- error: 'Failed to start TUI session: fetch failed',- })- );- });-- // The other half of the split: a LOCAL PTY that won't open is a real- // host/config problem a retry cannot repair, so it keeps the actionable- // reason that blocks the task for a human.it('keeps the actionable spawn-error when the local PTY path throws', async () => {vi.mocked(shellService.createShellSession).mockImplementationOnce(() => {throw new Error('posix_spawnp failed');});await expect(runSpawn({ useDurableRunner: false })).resolves.toBeNull();- await flushMicrotasks();expect(agentLifecycle.finalizeAgent).toHaveBeenCalledWith(expect.objectContaining({