Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: separate session switching from quit guard

yasakei1e659738cbe4
diff --git a/apps/app/src/app/lib/good-session.ts b/apps/app/src/app/lib/good-session.ts
index ac725859..147a0ba1 100644
--- a/apps/app/src/app/lib/good-session.ts
+++ b/apps/app/src/app/lib/good-session.ts
@@ -731,10 +731,12 @@ export function messageFacts(messages: readonly UIMessage[]): { calls: ToolCall[
return { calls, lastTurn };
}
-/** Whether leaving (closing, quitting, switching or deleting) is about a session whose turn runs. */
+/** Whether ending or deleting a session is about a session whose turn runs. */
export function leavingRunningTurn(input: { action: "close" | "quit" | "switch" | "delete"; turnRunning: boolean; targetSessionId?: string | null; currentSessionId?: string | null }): boolean {
if (!input.turnRunning) return false;
- if (input.action === "switch") return Boolean(input.currentSessionId) && input.targetSessionId !== input.currentSessionId;
+ // Viewing another session does not end this one. Only explicit termination
+ // actions should warn about cutting off its last turn.
+ if (input.action === "switch") return false;
return true;
}
diff --git a/apps/app/src/react-app/domains/session/chat/session-page.tsx b/apps/app/src/react-app/domains/session/chat/session-page.tsx
index 8d7c44e1..d1c2eaa1 100644
--- a/apps/app/src/react-app/domains/session/chat/session-page.tsx
+++ b/apps/app/src/react-app/domains/session/chat/session-page.tsx
@@ -1181,9 +1181,10 @@ export function SessionPage(props: SessionPageProps) {
return status === "thinking" || status === "responding" || status === "compacting" || status === "waiting";
}, [props.sidebar.sessionStatusById]);
- // Leaving a session whose turn runs (switching away, deleting it) asks
- // first; a second request, after "Wait for it", goes ahead. The guard
- // re-arms when a turn ends or a new one starts (the CLI's createQuitGuard).
+ // Ending a session whose turn runs asks first; a second request, after
+ // "Wait for it", goes ahead. Switching sessions is navigation, not
+ // termination, so it must not use this guard. The guard re-arms when a turn
+ // ends or a new one starts (the CLI's createQuitGuard).
const leaveGuard = useRef(createQuitGuard());
const runningTurns = Object.entries(props.sidebar.sessionStatusById)
.filter(([, status]) => status === "thinking" || status === "responding" || status === "compacting" || status === "waiting")
@@ -1201,13 +1202,6 @@ export function SessionPage(props: SessionPageProps) {
proceed();
}, []);
- // The sidebar's switch.
- const guardedOpenSessionTab = useCallback((workspaceId: string, sessionId: string) => {
- const currentSessionId = props.sidebar.selectedSessionId ?? null;
- const running = leavingRunningTurn({ action: "switch", turnRunning: sessionTurnRunning(currentSessionId), currentSessionId, targetSessionId: sessionId });
- guardLeave(running, () => openSessionTab(workspaceId, sessionId));
- }, [guardLeave, openSessionTab, props.sidebar.selectedSessionId, sessionTurnRunning]);
-
const closeSecondaryWorkbenchPane = useCallback(() => {
setWorkbenchSplit(null);
}, [setWorkbenchSplit]);
@@ -1434,7 +1428,7 @@ export function SessionPage(props: SessionPageProps) {
workspaceConnectionStateById={props.sidebar.workspaceConnectionStateById}
newTaskDisabled={props.sidebar.newTaskDisabled}
onSelectWorkspace={props.sidebar.onSelectWorkspace}
- onOpenSession={guardedOpenSessionTab}
+ onOpenSession={openSessionTab}
onPrefetchSession={props.sidebar.onPrefetchSession}
onCreateTaskInWorkspace={props.sidebar.onCreateTaskInWorkspace}
onCreateSplitTaskInWorkspace={props.sidebar.onCreateSplitTaskInWorkspace}
diff --git a/apps/app/tests/good-session.test.tsx b/apps/app/tests/good-session.test.tsx
index 3c385d48..08895c37 100644
--- a/apps/app/tests/good-session.test.tsx
+++ b/apps/app/tests/good-session.test.tsx
@@ -351,12 +351,16 @@ describe("the nudge", () => {
});
describe("the don't-leave-mid-turn guard", () => {
- test("leaving a running turn: quit, close, delete; switching only to another session", () => {
+ test("only explicit termination actions guard a running turn", () => {
expect(leavingRunningTurn({ action: "quit", turnRunning: true })).toBe(true);
expect(leavingRunningTurn({ action: "close", turnRunning: true })).toBe(true);
expect(leavingRunningTurn({ action: "delete", turnRunning: true })).toBe(true);
expect(leavingRunningTurn({ action: "quit", turnRunning: false })).toBe(false);
- expect(leavingRunningTurn({ action: "switch", turnRunning: true, currentSessionId: "a", targetSessionId: "b" })).toBe(true);
+ });
+
+ test("switching between active sessions never asks to quit either session", () => {
+ expect(leavingRunningTurn({ action: "switch", turnRunning: true, currentSessionId: "a", targetSessionId: "b" })).toBe(false);
+ expect(leavingRunningTurn({ action: "switch", turnRunning: true, currentSessionId: "b", targetSessionId: "a" })).toBe(false);
expect(leavingRunningTurn({ action: "switch", turnRunning: true, currentSessionId: "a", targetSessionId: "a" })).toBe(false);
});