mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 09:20:03 +01:00
fix(home): cancel failures emit worker.crashed so they surface in the UI
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: <msg>"). 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.
This commit is contained in:
1 file changed
+12
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user