Skip to content

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

fix: retry a TUI spawn the runner hop dropped instead of blocking for a human

[._.]/ Adam Eivyda2552f83c5c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index afa95804d9..357713bd8f 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -58,3 +58,5 @@
- **A managed app pinned to a self-hosted GitHub/GitLab is now reconciled the same way its Issues tab lists it.** When an app's work tracker is explicitly set to GitHub or GitLab, that pin lets PortOS query a forge whose hostname spells out neither `github.` nor `gitlab.` — a self-hosted Enterprise/GitLab instance can live on any domain the operator picked. The app's Issues tab honored the pin, but the background zombie/park reconciler that feeds scheduled CoS tasks still classified the origin from its hostname alone, so it silently treated the very same repo as "not a forge" and skipped every scan. Both paths now go through one composed resolver that carries the pin, so the tab and the scan can't drift again: threading it by hand is invisible on an ordinary github.com/gitlab.com origin and only fails on exactly the hosts that need it.
- **Stopping an autonomous run no longer reports it as a crash and files a bug for it.** Cancelling a Series Autopilot run — or stopping the LLM call it is sitting on from the Runs page, or restarting PortOS mid-run — kills the provider process, which the run then met as `TUI canceled (signal 15)` on its way out. The two lower layers already knew that signal was a deliberate stop rather than a provider fault (they neither bench the provider nor scan the story text for a bogus quota marker), but the autopilot itself only recognized a cancellation that arrived between steps. One that interrupted a step landed in the run's failure handler instead: the series was left in `error` rather than the resumable `paused`, a self-improvement post-mortem spent a long call diagnosing an automation defect that did not exist, and a CoS task was filed reading "The autonomous run failed and stopped" — a bug report about you pressing Stop. An interrupted step now ends the run the same way the between-steps cancel does, with the reason recorded on the series so Resume picks it back up. The foundation gate's two repair paths get the same treatment: they used to pause on "switch the repair provider/model first" for a repair the user themselves stopped, and the optional teaser step used to file a "retry this deliverable" task. Genuine step failures are unchanged — still `error`, still diagnosed, still filed. While fixing this, the pause and error terminals also moved their task filing to before the terminal status frame: the filing emits its own progress frame, and a client that opened the series after the run ended replayed that one and never learned the run had stopped.
+
+- **A CoS runner that is briefly unreachable no longer blocks the task for a human.** When an agent's TUI session spawns through the durable cos-runner and the spawn HTTP call fails — a bare `fetch failed` while PM2 restarts the runner, or the runner answering with a refusal — the failure finalized as the actionable `spawn-error`: the task was blocked immediately awaiting human approval, an "[Auto] Investigate agent failure" task was filed, and the escalation advice said to confirm the provider CLI is installed — none of which is true of a runner that was down for a moment. It was the most frequent failure class in the week's digest, five times over, each one parking work a plain retry fixes. The direct-CLI runner path drew this exact distinction long ago (`spawn-rejected` — non-actionable, retry, block only after the retry budget with the runner's own message attached); the TUI runner path now mirrors it. A local PTY that genuinely cannot open keeps the actionable `spawn-error`, because that is a real host problem a retry cannot repair.
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index 461cf01e5b..4f14258d81 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -929,6 +929,20 @@ export async function spawnTuiAgent({
// process terminated unexpectedly". Finalize it here instead, carrying the
// 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.
let session;
try {
session = await createAgentTuiSession({
@@ -952,7 +966,7 @@ export async function spawnTuiAgent({
success: false,
exitCode: 1,
error: `Failed to start TUI session: ${message}`,
- reason: 'spawn-error',
+ reason: useDurableRunner ? 'spawn-rejected' : 'spawn-error',
});
return null;
}
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index c15ede79e9..482febec58 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -2361,8 +2361,14 @@ describe('spawnTuiAgent runtime', () => {
// spawnTuiAgent to a caller that only logs — leaving the agent record stuck in
// `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.
describe('spawn failure', () => {
- it('finalizes with the spawn error instead of throwing', async () => {
+ 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')
);
@@ -2375,11 +2381,53 @@ describe('spawnTuiAgent runtime', () => {
expect.objectContaining({
agentId: 'agent-1',
success: false,
- completionReason: 'spawn-error',
+ completionReason: 'spawn-rejected',
error: expect.stringContaining('Command not allowed: grok'),
})
);
});
+
+ 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({
+ agentId: 'agent-1',
+ success: false,
+ completionReason: 'spawn-error',
+ error: 'Failed to start TUI session: posix_spawnp failed',
+ })
+ );
+ });
});
});