Skip to content

The agent that grows with you

fix(desktop): refuse steer into a session with no live turn (Closes #105176)

finn763aea969677c60
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
index 4f6ada67228..793a652108e 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx
@@ -2828,6 +2828,40 @@ describe('usePromptActions redirectPrompt', () => {
expect(await handle!.redirectPrompt('too late')).toBe(false)
})
+ it('refuses to steer a session with no live turn — no echo, no RPC (#105176)', async () => {
+ // The composer's busy belief lags the slice by an effect tick on the
+ // busy→false settle edge, so a steer can reach redirectPrompt for a session
+ // whose turn already settled: not busy, no stream, not awaiting a response.
+ // There is nothing to redirect, so it must NOT echo a bubble into this chat
+ // nor RPC an idle session — returning false lets the caller queue the text
+ // for the conversation whose run is actually live.
+ publishSessionState(RUNTIME_SESSION_ID, createClientSessionState(RUNTIME_SESSION_ID))
+
+ try {
+ const requestGateway = vi.fn(async () => ({ status: 'redirected' }) as never)
+ // The stale belief: busy was true when the steer was fired.
+ const staleBusyRef = { current: true }
+
+ let handle: HarnessHandle | null = null
+ const capturedStates: Record<string, unknown>[] = []
+ await actRender(
+ <Harness
+ busyRef={staleBusyRef}
+ onReady={h => (handle = h)}
+ onSeedState={state => capturedStates.push(state)}
+ refreshSessions={async () => undefined}
+ requestGateway={requestGateway}
+ />
+ )
+
+ expect(await handle!.redirectPrompt('stale steer')).toBe(false)
+ expect(requestGateway).not.toHaveBeenCalled()
+ expect(capturedStates).toEqual([])
+ } finally {
+ dropSessionState(RUNTIME_SESSION_ID)
+ }
+ })
+
it('reports rejection without throwing when the redirect RPC errors', async () => {
const requestGateway = vi.fn(async () => {
throw new Error('agent does not support redirect')
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
index 03bb7367c23..6877698f13c 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
@@ -38,7 +38,7 @@ import {
setMessages,
setTurnStartedAt
} from '@/store/session'
-import { $sessionStates, isSessionRemote } from '@/store/session-states'
+import { $sessionStates, isLiveTurnAwaitingEvents, isSessionRemote } from '@/store/session-states'
import { clearSessionSubagents } from '@/store/subagents'
import { runGatewayRestart } from '@/store/system-actions'
import { clearSessionTodos } from '@/store/todos'
@@ -792,6 +792,23 @@ export function usePromptActions({
return false
}
+ // #105176: a steer reaches here on the composer's own busy belief, and
+ // the composer keeps that belief one effect tick past the busy→false
+ // settle. When it lags, the turn has already ended: redirecting would
+ // echo the bubble into a chat the user never typed in and RPC an idle
+ // session whose text the backend can cross-deliver into another
+ // session's live run. The slice is authoritative, so refuse before the
+ // optimistic insert and the caller queues the text for the conversation
+ // whose run is actually live. Without a stale belief there is nothing
+ // stale to catch: the caller deliberately asked for a correction (a
+ // rotation gap, a recovery retry) and the gateway authoritatively
+ // rejects an idle redirect.
+ const liveTurn = $sessionStates.get()[target.sessionId]
+
+ if (busyRef.current && liveTurn && !isLiveTurnAwaitingEvents(liveTurn)) {
+ return false
+ }
+
// Accepted whether the live turn was redirected in place or queued for
// the next turn (the build window, before the agent is wired) — either
// way the correction reaches the model, so record it once as a real user
@@ -868,6 +885,7 @@ export function usePromptActions({
[
activeSessionIdRef,
appendSessionTextMessage,
+ busyRef,
getRoutedStoredSessionId,
requestGateway,
runtimeIdByStoredSessionIdRef,
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index ff2fc18c21e..b76dac383b6 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -461,7 +461,7 @@ function clearEventSilence(runtimeId: string) {
}
}
-function isLiveTurnAwaitingEvents(state: ClientSessionState | undefined): boolean {
+export function isLiveTurnAwaitingEvents(state: ClientSessionState | undefined): boolean {
return Boolean(state && (state.busy || state.awaitingResponse || state.turnLive) && !state.needsInput)
}