Skip to content

The agent that grows with you

fix(desktop): salvage session-race sequencing cluster — widen Stop cooldown to tile interrupts, prove submit ownership both ways

Teknium898cc871250f
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 4a236aa2b45..c00fa222558 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
@@ -100,3 +100,29 @@ describe('useSessionTileDelegate resumeTile', () => {
})
})
})
+
+describe('useSessionTileDelegate interruptSession', () => {
+ beforeEach(() => {
+ setSessions([])
+ })
+
+ afterEach(async () => {
+ setSessions([])
+ const { clearSessionRecentlyInterrupted } = await import('../../session/hooks/use-prompt-actions/utils')
+ clearSessionRecentlyInterrupted()
+ })
+
+ it('marks the session recently interrupted so a quick tile edit/resend still interrupt-firsts (#83855)', async () => {
+ const { isSessionRecentlyInterrupted } = await import('../../session/hooks/use-prompt-actions/utils')
+
+ const requestGateway = vi.fn(async () => ({}) as never)
+
+ renderTile(requestGateway)
+ await sessionTileDelegate()!.interruptSession('runtime-tile-1')
+
+ expect(requestGateway).toHaveBeenCalledWith('session.interrupt', { session_id: 'runtime-tile-1' })
+ // Same 3s cooldown the primary chat's Stop sets: busy reads false while the
+ // gateway winds down, so the rewind path must still interrupt-first.
+ expect(isSessionRecentlyInterrupted('runtime-tile-1')).toBe(true)
+ })
+})
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 0fd18f15b78..86936bb8488 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
@@ -6,7 +6,7 @@ import { publishSessionState, setSessionTileDelegate } from '@/store/session-sta
import type { SessionResumeResponse } from '@/types/hermes'
import type { usePromptActions } from '../../session/hooks/use-prompt-actions'
-import { withSessionNotFoundResume } from '../../session/hooks/use-prompt-actions/utils'
+import { markSessionRecentlyInterrupted, withSessionNotFoundResume } from '../../session/hooks/use-prompt-actions/utils'
import { resolveSessionProfile } from '../../session/hooks/use-session-actions/utils'
import type { useSessionStateCache } from '../../session/hooks/use-session-state-cache'
import type { GatewayRequester } from '../types'
@@ -85,11 +85,23 @@ export function useSessionTileDelegate({
await executeSlashCommand(rawCommand, { sessionId })
},
interruptSession: async runtimeId => {
+ // Same cooldown as the primary chat's Stop (#83855): the gateway may
+ // still be winding down after this interrupt, so a quick edit/resend
+ // on the tile must go interrupt-first even though busy already reads
+ // false. Mark the runtime id (and any recovered id) before the RPC so
+ // the window covers the whole wind-down.
+ markSessionRecentlyInterrupted(runtimeId)
await withSessionNotFoundResume(
runtimeId,
storedSessionIdForRuntime(runtimeId),
liveId => requestGateway('session.interrupt', { session_id: liveId }),
- { requestGateway, onRecovered: rebindTileRuntime(runtimeId) }
+ {
+ requestGateway,
+ onRecovered: recoveredId => {
+ markSessionRecentlyInterrupted(recoveredId)
+ rebindTileRuntime(runtimeId)(recoveredId)
+ }
+ }
)
},
resumeTile: async storedSessionId => {
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 2796d3edda7..f8c41b76253 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
@@ -4288,7 +4288,7 @@ describe('usePromptActions submit entry-time runtime ownership proof (#64789/#65
await handle!.submitText('ordinary text for the selected project B session')
- expect(calls.find(c => c.method === 'session.resume')?.params).toEqual({
+ expect(calls.find(c => c.method === 'session.resume')?.params).toMatchObject({
session_id: STORED_SESSION_B,
source: 'desktop'
})
@@ -4345,7 +4345,7 @@ describe('usePromptActions submit entry-time runtime ownership proof (#64789/#65
await handle!.submitText('ordinary text for the freshly created project B session')
- expect(calls.find(c => c.method === 'session.resume')?.params).toEqual({
+ expect(calls.find(c => c.method === 'session.resume')?.params).toMatchObject({
session_id: STORED_SESSION_B,
source: 'desktop'
})
@@ -4430,7 +4430,7 @@ describe('usePromptActions submit entry-time runtime ownership proof (#64789/#65
await handle!.submitText('message after an ownership-cache miss')
- expect(calls.find(c => c.method === 'session.resume')?.params).toEqual({
+ expect(calls.find(c => c.method === 'session.resume')?.params).toMatchObject({
session_id: STORED_SESSION_B,
source: 'desktop'
})
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.test.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.test.ts
index e00efecf66e..c21e38f9c91 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.test.ts
@@ -19,8 +19,8 @@ import {
isSessionRecentlyInterrupted,
isSubmitInFlight,
markSessionRecentlyInterrupted,
- RECENT_INTERRUPT_COOLDOWN_MS,
readFileDataUrlForAttach,
+ RECENT_INTERRUPT_COOLDOWN_MS,
releaseSubmitInFlight,
renderRpcResult,
SessionRecoveryAborted,