Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(desktop): keep a user Stop authoritative over a later sidecar crash
vastsa67e83f308eec
diff --git a/apps/desktop/electron/main/runtime/plans.ts b/apps/desktop/electron/main/runtime/plans.tsindex 021cda6c8..7aa678437 100644--- a/apps/desktop/electron/main/runtime/plans.ts+++ b/apps/desktop/electron/main/runtime/plans.ts@@ -211,7 +211,11 @@ function finishTurn(options.createNotification ??(!wasPlanSubmission && shouldCreateTaskNotification(id));const recoverInflight = options.recoverInflight === true;- const interruptionError = options.interruptionError;+ // A user Stop locked before the crash owns the outcome: the turn ends as an+ // ordinary abort, without a crash card or a crash code in Agent Host.+ const interruptionError = peekAbortReason(id, turnId) === undefined+ ? options.interruptionError+ : undefined;const ownsLiveTurn = () => !isQuitting() && isActiveTurn(id, turnId);const runFinalization = async (): Promise<void> => {@@ -262,6 +266,7 @@ function finishTurn(const message: UiMessage = {id: randomUUID(),role: "assistant",+ turnId,content: "",createdAt: new Date(ts).toISOString(),status: "error",diff --git a/apps/desktop/test/queued-turn-finalization.test.mjs b/apps/desktop/test/queued-turn-finalization.test.mjsindex 00a387deb..f71b76f78 100644--- a/apps/desktop/test/queued-turn-finalization.test.mjs+++ b/apps/desktop/test/queued-turn-finalization.test.mjs@@ -254,6 +254,7 @@ for (const errorCode of ["AGENT_SIDECAR_CRASHED", "AGENT_SIDECAR_OOM"]) {]);assert.equal(f.rendererEvents[0].event.message.id, "partial");assert.equal(f.rendererEvents[1].event.message.error.code, errorCode);+ assert.equal(f.rendererEvents[1].event.message.turnId, FIRST_TURN);assert.deepEqual(f.appends[0].message, f.rendererEvents[1].event.message);assert.deepEqual(f.outboxWrites, []);assert.deepEqual(f.rendererEvents[2].event.error, error);@@ -265,6 +266,27 @@ for (const errorCode of ["AGENT_SIDECAR_CRASHED", "AGENT_SIDECAR_OOM"]) {});}+test("a sidecar crash after the user pressed Stop settles as a plain abort", { timeout: 5_000 }, async () => {+ const f = fixture();+ await f.bridge.queue.push({ sessionId: SESSION, content: "follow-up" });+ f.bridge.markAborting(SESSION);+ f.coordination.lockAbortReason(SESSION, FIRST_TURN);+ const error = { code: "AGENT_SIDECAR_CRASHED", message: "Agent sidecar exited unexpectedly" };+ const pending = f.finishTurn(SESSION, "aborted", error.code, {+ turnId: FIRST_TURN, recoverInflight: true, interruptionError: error,+ });+ await setImmediate();+ f.writes[0].resolve({ ok: true });+ await pending;+ await setImmediate();+ assert.deepEqual(f.appends, [], "no crash card is persisted");+ assert.equal(f.rendererEvents.some(({ event }) => event.type === "error"), false);+ const interrupted = f.bridge.agentHost.getTurn(FIRST_TURN);+ assert.equal(interrupted.status, "interrupted");+ assert.notEqual(interrupted.error?.code, error.code);+ assert.deepEqual(f.prompts.map(({ content }) => content), ["follow-up"]);+});+test("a crashed turn does not publish recovered rows after its session moved on", async () => {const f = fixture();const error = { code: "AGENT_SIDECAR_CRASHED", message: "Agent sidecar exited unexpectedly" };