From 4551933e32b915d56a910bfa811c2fba50dc01fb Mon Sep 17 00:00:00 2001 From: g-but <41178744+g-but@users.noreply.github.com> Date: Wed, 20 May 2026 05:33:12 +0200 Subject: [PATCH] fix(home): cancel failures emit worker.crashed so they surface in the UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Symmetric with executeDispatch — when injectIntoTab throws, the worker emits worker.crashed and the brain's lastError surfaces the reason in red on /control. Cancellation didn't have that path: sendRawKey could throw (zellij tab gone, daemon unreachable), the worker logged to stderr, and that was it. state.applyEvent had already cleared currentRun optimistically on the bridge.cancel itself, so the UI would show the project as idle while the agent kept running. Silent failure. executeCancel now emits worker.crashed on sendRawKey failure with the underlying message ("cancel failed: "). state.applyEvent sets lastError and adds an "error" outcome to recentOutcomes — the cancel attempt is its own event, separate from the run's eventual outcome (if a stop hook fires later, the cancelled runId is still in state.cancelledRunIds and that future worker.finished still gets relabelled to user_abort). home/worker self-tests still 12/12 (executeCancel is I/O so it's not covered by the pure-function suite; state.ts already handles the new event flow via the existing worker.crashed projection). tsc clean. --- home/worker.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/home/worker.ts b/home/worker.ts index 1a58688c1..6547581db 100644 --- a/home/worker.ts +++ b/home/worker.ts @@ -110,7 +110,19 @@ function executeCancel(event: Event) { sendRawKey(event.project, CTRL_C); console.log(`[worker] sent Ctrl+C to project=${event.project} runId=${event.runId} reason=${event.reason}`); } catch (e) { + // Symmetric with executeDispatch's inject-failure branch: emit + // worker.crashed so the brain's state.applyEvent sets lastError and + // the UI surfaces a red error message. Without this, a failed cancel + // is silent — state.applyEvent already cleared currentRun + // optimistically on the bridge.cancel, so the UI would show the + // project as idle while the agent might still be running. const msg = e instanceof Error ? e.message : String(e); + appendEvent({ + kind: "worker.crashed", + project: event.project, + runId: event.runId, + error: `cancel failed: ${msg}`, + }); console.error(`[worker] cancel failed runId=${event.runId}: ${msg}`); } }