Skip to content

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

fix(session): keep running native Pi turns stoppable after reload

zszz33a26e8c1644c
diff --git a/apps/desktop/electron/main/ipc/session-ipc.ts b/apps/desktop/electron/main/ipc/session-ipc.ts
index 62b1c237d..13897cd5d 100644
--- a/apps/desktop/electron/main/ipc/session-ipc.ts
+++ b/apps/desktop/electron/main/ipc/session-ipc.ts
@@ -41,6 +41,12 @@ type RuntimeSession = {
[key: string]: unknown;
};
+function nativeTurnRunning(session: RuntimeSession): boolean {
+ const capabilities = session.capabilities;
+ return typeof capabilities === "object" && capabilities !== null &&
+ (capabilities as { canStop?: unknown }).canStop === true;
+}
+
let scannedImportSessions = new Map<string, ExternalSessionSummary>();
let scannedModelConfigs = new Map<string, ModelConfigImportDraft>();
@@ -226,7 +232,15 @@ export function registerSessionIpc({
: { sessions: [] as RuntimeSession[] };
return {
...result,
- runningSessionIds: [...activeTurns.keys()],
+ // Native Pi turns run in the sidecar and are absent from activeTurns; a
+ // reloaded renderer must still see them as running to offer Stop.
+ runningSessionIds: [
+ ...activeTurns.keys(),
+ ...native.sessions.flatMap((session) =>
+ typeof session.id === "string" && !activeTurns.has(session.id) && nativeTurnRunning(session)
+ ? [session.id]
+ : []),
+ ],
sessions: [
...result.sessions.map((session) => ({
...enrichSession(session, providers, defaults),
diff --git a/apps/desktop/test/native-pi-sessions.test.mjs b/apps/desktop/test/native-pi-sessions.test.mjs
index 86efb7c76..fef7ba757 100644
--- a/apps/desktop/test/native-pi-sessions.test.mjs
+++ b/apps/desktop/test/native-pi-sessions.test.mjs
@@ -350,6 +350,49 @@ test("session list forwards local project paths to native discovery (#1732)", as
assert.deepEqual(hostCalls.map((call) => call.method), ["projects.list", "session.list"]);
});
+test("session list reports running native sessions so a reloaded renderer offers Stop (#2575)", async () => {
+ const { list } = forkHarness({
+ activeTurns: new Map([["desktop-1", "turn-1"]]),
+ host: () => ({
+ call: async (method) => {
+ if (method === "projects.list") return { projects: [{ path: "/work/demo" }] };
+ if (method === "session.list") {
+ return { sessions: [{ id: "desktop-1", updatedAt: "2026-09-14T00:00:01.000Z" }] };
+ }
+ return {};
+ },
+ }),
+ sidecar: () => ({
+ call: async () => ({
+ sessions: [
+ {
+ id: "native-pi:busy",
+ updatedAt: "2026-09-14T00:00:03.000Z",
+ source: "pi-native",
+ readOnlyReason: "busy",
+ capabilities: { canPrompt: false, canStop: true, canRefresh: true },
+ },
+ {
+ id: "native-pi:idle",
+ updatedAt: "2026-09-14T00:00:02.000Z",
+ source: "pi-native",
+ capabilities: { canPrompt: true, canStop: false, canRefresh: true },
+ },
+ {
+ id: "native-pi:locked",
+ updatedAt: "2026-09-14T00:00:01.500Z",
+ source: "pi-native",
+ readOnlyReason: "busy",
+ capabilities: { canPrompt: false, canStop: false, canRefresh: true },
+ },
+ ],
+ }),
+ }),
+ });
+ const result = await list();
+ assert.deepEqual(result.runningSessionIds, ["desktop-1", "native-pi:busy"]);
+});
+
test("a failed projects.list keeps Desktop sessions and logs the skip (#1732)", async () => {
const warnings = [];
const original = console.warn;