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(mods): preserve stale closeout cancellation ordering
new-Beginnerecb25d2bb742
diff --git a/packages/agent-runtime/src/modes/complete-stage-tool.test.ts b/packages/agent-runtime/src/modes/complete-stage-tool.test.tsindex 669a3d386..37d595ef3 100644--- a/packages/agent-runtime/src/modes/complete-stage-tool.test.ts+++ b/packages/agent-runtime/src/modes/complete-stage-tool.test.ts@@ -243,6 +243,22 @@ describe("CompleteStage", () => {expect(endTurn).not.toHaveBeenCalled();});+ it("keeps stale-reply handling ahead of cancellation after a claim is lost", async () => {+ const options = { claimed: true };+ const controller = new AbortController();+ const { host, tool, gates, failTurn, endTurn } = harness({}, options);+ host.call.mockImplementation(async () => {+ options.claimed = false;+ controller.abort();+ return { status: "run", gateIndex: 0, command: "npm test", timeoutMinutes: 1, run: RUN };+ });+ const result = await tool.execute("call-1", { summary: "Done" }, controller.signal);+ expect(text(result)).toContain("earlier run turn");+ expect(gates).toEqual([]);+ expect(failTurn).not.toHaveBeenCalled();+ expect(endTurn).not.toHaveBeenCalled();+ });+it("submits an explicit blocked report with unfinished criteria and ends without running gates", async () => {const report = {status: "blocked", outcomes: [{ criterion: "Build", outcome: "unverified", evidence: "Required approval is missing" }],diff --git a/packages/agent-runtime/src/modes/complete-stage-tool.ts b/packages/agent-runtime/src/modes/complete-stage-tool.tsindex ec6578698..3c22546ed 100644--- a/packages/agent-runtime/src/modes/complete-stage-tool.ts+++ b/packages/agent-runtime/src/modes/complete-stage-tool.ts@@ -266,6 +266,8 @@ export function createCompleteStageTool(deps: CompleteStageToolDeps): AgentTool}const staleResult = (): ToolResult => textResult("This completion reply belongs to an earlier run turn.", { errorCode: "MODE_CLAIM_MISMATCH" }, { isError: true, terminate: true });+ // Keep stale replies inert even when their old turn was also cancelled.+ if (!ownsContext()) return staleResult();let previousGate = -1;while (outcome.status === "run") {if (signal?.aborted) throw abortedError();