Skip to content

The agent that grows with you

fix(desktop): reject stale tile branch actions

embwl0xd5f02af602e3
diff --git a/apps/desktop/src/app/chat/session-tile-actions.test.ts b/apps/desktop/src/app/chat/session-tile-actions.test.ts
index d9d0c67b302..90a144d008e 100644
--- a/apps/desktop/src/app/chat/session-tile-actions.test.ts
+++ b/apps/desktop/src/app/chat/session-tile-actions.test.ts
@@ -89,6 +89,7 @@ describe('useSessionTileActions sleep/wake session recovery', () => {
setSessionTileDelegate({
archiveSession: vi.fn(async () => undefined),
branchSession: vi.fn(async () => undefined),
+ branchSessionAtMessage: vi.fn(async () => true),
deleteSession: vi.fn(async () => undefined),
executeSlash: vi.fn(async () => undefined),
interruptSession: vi.fn(async () => undefined),
diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts
index bbd6fc89dc9..973273ed2ec 100644
--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts
@@ -603,6 +603,15 @@ describe('useSessionTileDelegate resumeTile', () => {
storedSessionId: 'stored-x'
})
})
+
+ it('does not branch when the clicked tile no longer has live state', async () => {
+ const branchLoadedSession = vi.fn(async () => true)
+
+ renderTile(vi.fn(), { branchLoadedSession })
+
+ await expect(sessionTileDelegate()!.branchSessionAtMessage('stored-x', 'runtime-gone', 'a1')).resolves.toBe(false)
+ expect(branchLoadedSession).not.toHaveBeenCalled()
+ })
})
describe('useSessionTileDelegate retireBusyClaim', () => {
diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
index f8b00411399..6136a9b0410 100644
--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts
@@ -211,11 +211,18 @@ export function useSessionTileDelegate({
branchSessionAtMessage: async (storedSessionId, runtimeId, messageId) => {
const state = sessionStateByRuntimeIdRef.current.get(runtimeId)
+ // The tile can disappear between render and click. Without its live
+ // state we cannot prove the busy flag or the transcript boundary, so
+ // do not manufacture an empty, apparently-idle branch.
+ if (!state) {
+ return false
+ }
+
return await branchLoadedSession({
- busy: state?.busy ?? false,
- cwd: state?.cwd,
+ busy: state.busy,
+ cwd: state.cwd,
messageId,
- messages: state?.messages ?? [],
+ messages: state.messages,
runtimeId,
storedSessionId
})
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
index 5218d06db6b..4c867dcc2cd 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
@@ -2940,12 +2940,6 @@ export function useSessionActions({
return false
}
- const startingActiveSessionId = activeSessionIdRef.current
- const messages = $messages.get()
- const storedSessionId = selectedStoredSessionIdRef.current
- const startingRouteToken = getRouteToken()
- const startingCwd = $currentCwd.get().trim()
-
// Message-level branches still need the local message id to choose their
// prefix. Whole-chat branches send only the parent identity below; the
// backend reads the durable display projection without materializing it in