Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix: 停止请求失败时保留会话运行状态

geng yue3717ef36c197
diff --git a/apps/desktop/src/stores/slices/session-slice.ts b/apps/desktop/src/stores/slices/session-slice.ts
index 34d364034..82ba64bd5 100644
--- a/apps/desktop/src/stores/slices/session-slice.ts
+++ b/apps/desktop/src/stores/slices/session-slice.ts
@@ -870,15 +870,12 @@ export function createSessionSlice({
/** Abort one session's running turn, whether or not it is the visible one. */
abortSession: async (sessionId) => {
if (!sessionId) return;
- try {
- await api.abort(sessionId);
- } finally {
- set((state) => ({
- isRunning:
- state.activeSessionId === sessionId ? false : state.isRunning,
- runningSessions: { ...state.runningSessions, [sessionId]: false },
- }));
- }
+ await api.abort(sessionId);
+ set((state) => ({
+ isRunning:
+ state.activeSessionId === sessionId ? false : state.isRunning,
+ runningSessions: { ...state.runningSessions, [sessionId]: false },
+ }));
},
};
}
diff --git a/apps/desktop/test/failed-session-stop-state.test.mjs b/apps/desktop/test/failed-session-stop-state.test.mjs
new file mode 100644
index 000000000..c09867f96
--- /dev/null
+++ b/apps/desktop/test/failed-session-stop-state.test.mjs
@@ -0,0 +1,19 @@
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import test from "node:test";
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
+const { createSessionSlice } = await import("../src/stores/slices/session-slice.ts");
+const { api } = await import("../src/lib/api.ts");
+
+test("a rejected remote stop preserves running state and allows retry", async t => {
+ let state = { activeSessionId: "remote:session", isRunning: true, runningSessions: { "remote:session": true }, sessions: [] };
+ const slice = createSessionSlice({ get: () => state, set: patch => { state = { ...state, ...(typeof patch === "function" ? patch(state) : patch) }; } });
+ t.mock.method(api, "abort", async () => { throw new Error("remote host disconnected"); });
+ await assert.rejects(slice.abortSession("remote:session"), /disconnected/);
+ assert.equal(state.isRunning, true);
+ assert.equal(state.runningSessions["remote:session"], true);
+ t.mock.method(api, "abort", async () => ({ ok: true }));
+ await slice.abortSession("remote:session");
+ assert.equal(state.isRunning, false);
+ assert.equal(state.runningSessions["remote:session"], false);
+});
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 55ee6f22e..5edc878cf 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1,5 +1,9 @@
# 08. Component Spec
+A rejected session Stop request retains the last known running state. A
+transport failure is not confirmation of process settlement; successful Stop
+and authoritative terminal events continue to clear the running indicator.
+
Live delegation reconstruction crosses system notices as well as steering
messages. An ordinary user prompt remains the run boundary. A running Task
behind a system notice must not become aborted on navigation (Refs #1990).
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 8d3fd8660..9c57d7505 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,12 @@
# 04. E2E Test Plan
+### E2E-SESSION-rejected-stop-state
+
+Reject a remote Stop at the API boundary: the production session slice keeps
+its running state and rethrows the error. Retry successfully: both the active
+indicator and owning session running entry clear. Coverage:
+`failed-session-stop-state.test.mjs`, without provider execution.
+
### E2E-SUBAGENT-system-notice-reconstruction
Reconstruct a transcript with a running Task followed by a system notice.
diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.md
index 69011ffcb..11dc7da16 100644
--- a/docs/zh-CN/spec/04-ux/08-component-spec.md
+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md
@@ -1,5 +1,8 @@
# 08. 组件规格
+会话 Stop 请求失败时保留最后已知的运行状态,传输错误不能当作进程停止确认。
+成功 Stop 和权威结束事件继续清除运行标记。
+
运行中子代理状态重建跨过系统通知及 steering 消息,普通用户提示仍作为回合边界。
系统通知之前仍在运行的 Task 不会因导航而显示已停止(Refs #1990)。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index a1e9b5c5d..9a88c0058 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,11 @@
# 04. E2E 测试 Plan
+### E2E-SESSION-rejected-stop-state
+
+在 API 边界拒绝远端 Stop,生产会话 slice 保留运行状态并传播错误。再次成功
+停止后,当前标记和目标会话运行条目清除。覆盖
+`failed-session-stop-state.test.mjs`,不执行提供商请求。
+
### E2E-SUBAGENT-system-notice-reconstruction
重建运行中的 Task 后接系统通知的会话,生产条目构建、运行状态选择及结果