Skip to content

The agent that grows with you

fix(desktop): clear the compaction overlay when a turn is stopped

PRATHAMESH75f05a3ca9310b
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 35b2d841a71..325d43df1f7 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
@@ -7,6 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { getLatestSessionMessages, getSession } from '@/hermes'
import { textPart, toChatMessages } from '@/lib/chat-messages'
import { createClientSessionState } from '@/lib/chat-runtime'
+import { $compactingSessions, setSessionCompacting } from '@/store/compaction'
import { $composerAttachments, $composerDraft, type ComposerAttachment, setComposerDraft } from '@/store/composer'
import { $queuedPromptsBySession, getQueuedPrompts } from '@/store/composer-queue'
import { requestGatewayForAgent } from '@/store/gateway'
@@ -5343,6 +5344,35 @@ describe('usePromptActions submit entry-time runtime ownership proof (#64789/#65
})
})
+describe('usePromptActions cancelRun', () => {
+ afterEach(() => {
+ cleanup()
+ $compactingSessions.set({})
+ vi.restoreAllMocks()
+ })
+
+ it('clears a stuck compaction overlay so Stop dismisses "Summarizing thread"', async () => {
+ // A hung compaction never emits message.start/complete/error, so the
+ // per-session compacting flag (and its overlay) sticks. Stop is the user's
+ // only recourse and must clear it.
+ setSessionCompacting(RUNTIME_SESSION_ID, true)
+ expect($compactingSessions.get()[RUNTIME_SESSION_ID]).toBe(true)
+
+ const requestGateway = vi.fn(async () => ({}) as never)
+
+ let handle: HarnessHandle | null = null
+ render(
+ <Harness onReady={h => (handle = h)} refreshSessions={async () => undefined} requestGateway={requestGateway} />
+ )
+ await waitFor(() => expect(handle).not.toBeNull())
+
+ await handle!.cancelRun()
+
+ expect($compactingSessions.get()[RUNTIME_SESSION_ID]).toBeUndefined()
+ expect(requestGateway).toHaveBeenCalledWith('session.interrupt', { session_id: RUNTIME_SESSION_ID })
+ })
+})
+
describe('usePromptActions eager attachment upload (drop-time)', () => {
afterEach(() => {
cleanup()
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 4d96abdf7a5..02e4137e511 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
@@ -16,6 +16,7 @@ import { isWindowsAbsolutePath } from '@/lib/path-compare'
import { normalize } from '@/lib/text'
import { transcribeAudioClientDirect } from '@/lib/voice-client-direct'
import { clearClarifyRequest } from '@/store/clarify'
+import { setSessionCompacting } from '@/store/compaction'
import {
$composerAttachments,
type ComposerAttachment,
@@ -739,6 +740,11 @@ export function usePromptActions({
clearSessionSubagents(sessionId)
resetSessionBackground(sessionId)
setSessionDraftingTool(sessionId, '')
+ // Auto-compaction sets a per-session flag that only clears on message.start
+ // / message.complete / error. A hung compaction emits none of those, so the
+ // "Summarizing thread" overlay sticks and Stop is the user's only recourse —
+ // clear it here too so cancelling actually dismisses the panel.
+ setSessionCompacting(sessionId, false)
// Stop ends the turn, so the gateway is no longer blocked on any prompt it
// raised. Drop this session's pending clarify / approval / sudo / secret so
// a dead panel (and the sidebar "needs input" dot) can't linger and accept