Skip to content

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

fix: 激活分支时清除旧会话切换状态

geng yue4e7bbcbbf549
diff --git a/apps/desktop/src/stores/runtime/session-coordination.ts b/apps/desktop/src/stores/runtime/session-coordination.ts
index 015386573..c16101b8f 100644
--- a/apps/desktop/src/stores/runtime/session-coordination.ts
+++ b/apps/desktop/src/stores/runtime/session-coordination.ts
@@ -196,6 +196,7 @@ export function createSessionCoordination({
...shared,
...retainSessionPane(current, summary.id, messages),
activeSessionId: summary.id,
+ selectingSessionId: undefined,
messages,
page: "chat" as const,
isRunning: false,
diff --git a/apps/desktop/test/session-fork-running.test.mjs b/apps/desktop/test/session-fork-running.test.mjs
index 62b6c85f5..f7bee0137 100644
--- a/apps/desktop/test/session-fork-running.test.mjs
+++ b/apps/desktop/test/session-fork-running.test.mjs
@@ -19,6 +19,7 @@ function harness(t) {
workPanelContexts: {}, workPanelTabs: [], workPanelOpen: false,
navStack: [{ page: "chat", sessionId: "parent" }], navIndex: 0,
restorePendingPlan: async () => {},
+ restorePendingInteractive: async () => {},
};
let intent = 0;
const cache = new Map([["parent", state.messages]]);
@@ -78,6 +79,28 @@ test("a fork that finishes after navigation lists the child without stealing the
assert.deepEqual(h.get().sessions.map(s => s.id), ["child", "parent"]);
});
+test("a superseded fork does not clear the newer session selection", async (t) => {
+ const h = harness(t);
+ const action = h.slice.forkAssistantMessage("old");
+ h.runtime.beginNavigationIntent();
+ h.set({ selectingSessionId: "other" });
+ h.complete();
+ await action;
+ assert.equal(h.get().selectingSessionId, "other");
+ assert.equal(h.get().activeSessionId, "parent");
+});
+
+test("fork activation clears an in-flight selection so the child is visible immediately", async (t) => {
+ const h = harness(t);
+ // 侧边栏分支可以在旧会话后台重新验证时触发。
+ h.set({ isRunning: false, runningSessions: {}, selectingSessionId: "parent" });
+ t.mock.method(api, "forkSession", async () => ({ session: { id: "child", title: "Branch", mode: "agent", messages: [] } }));
+ await h.slice.forkSession("parent");
+ assert.equal(h.get().activeSessionId, "child");
+ assert.equal(h.get().selectingSessionId, undefined);
+ assert.equal(h.get().retainedSessionIds[0], "child");
+});
+
test("a rejected fork reports the error and keeps the original turn and transcript", async (t) => {
const h = harness(t);
const parent = h.get().messages;
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 398034650..42aeda842 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -4763,3 +4763,7 @@ Closing the connected Browser tab clears its connection. Subsequent session-only
### Issue #2164 correction
While a checkpoint estimate supplies context occupancy, use its recorded provider/model capacity, or the current exact session binding for legacy checkpoints. Keep historical request usage unchanged. Unknown capacity is marked approximate. Verify 20,619 / 1,000,000 = 2%, unknown routes, legacy records and usage after a newer request with `compaction-context-usage.test.mjs`.
+
+### Fork activation selection ownership (#2086)
+
+Activating a completed session fork clears the previous selectingSessionId together with its visible pane switch. A superseded fork only lists its durable child and does not clear a newer pending selection. This prevents stale switching UI from hiding the activated branch.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 12473a3dc..7cd0109d2 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -20399,3 +20399,7 @@ While a checkpoint estimate supplies context occupancy, use its recorded provide
- Specs: `03-runtime/02-agent-runtime.md`, Session job controls.
- Acceptance: wait, report re-read and running-delegate cancellation complete
through the real tool loop. Milestone: maintenance. Status: automated.
+
+#### E2E-ISSUE-2086-fork-selection
+
+While the parent is revalidating, invoke sidebar forkSession and complete the Host response. The child becomes active/retained and selectingSessionId clears. If a newer selection supersedes a reply fork, its selection remains. Cover existing running-parent transcript and fork-error paths through session-fork-running.test.mjs.
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 f469785d4..6aa185147 100644
--- a/docs/zh-CN/spec/04-ux/08-component-spec.md
+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md
@@ -3111,3 +3111,7 @@ default nor provider configuration. OAuth accounts remain in their separate sect
### Issue #2164 修正
压缩估算作为占用时使用检查点模型容量,旧检查点使用当前会话完整绑定;历史请求用量不变,未知容量标记估算。验证 20,619 / 1,000,000 为 2%、未知路由、旧记录及新请求恢复。
+
+### 分支激活选择状态(#2086)
+
+完成分支并激活时,同步清除旧 selectingSessionId;已被新导航替代的分支只加入列表,不清除后来选择。防止分支已创建但界面仍显示旧切换状态。
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 918e091b6..b0402ed91 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
@@ -10420,3 +10420,7 @@ Electron 一侧——工具自动签发、指示器、"停止"中止轮次、绘
#### E2E-ISSUE-2164
压缩估算作为占用时使用检查点模型容量,旧检查点使用当前会话完整绑定;历史请求用量不变,未知容量标记估算。验证 20,619 / 1,000,000 为 2%、未知路由、旧记录及新请求恢复。
+
+#### E2E-ISSUE-2086-fork-selection
+
+父会话重新读取时创建侧边栏分支,完成后子会话立即激活且旧选择清除;若被新导航替代,只列出分支并保留新选择。覆盖原运行中父会话与失败路径。