Skip to content

The agent that grows with you

fix(desktop): retire status rows and re-sync background processes past Stop

Brooklyn Nicholson154615bee10b
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts
index e28ccd4ba64..c85e0b494fe 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/tools.ts
@@ -118,8 +118,10 @@ export function handleToolEvent(ctx: GatewayEventContext): boolean {
updateSessionState(sessionId, state => (state.needsInput ? { ...state, needsInput: false } : state))
// terminal/process tool calls are the only things that spawn or reap
- // background processes — sync the composer status stack right after.
- if (!sessionInterrupted(sessionId) && (payload?.name === 'terminal' || payload?.name === 'process')) {
+ // background processes — sync the composer status stack right after,
+ // even on an interrupted turn (idempotent re-sync; the 5s poll may be
+ // unarmed when no running row is on screen yet, #81114).
+ if (payload?.name === 'terminal' || payload?.name === 'process') {
void refreshBackgroundProcesses(sessionId)
}
}
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
index 6ebd95d6f60..1db0674c8e9 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
@@ -551,10 +551,12 @@ export function useMessageStream({
// a tool part can't jump ahead of the text that preceded it.
flushQueuedDeltas(sessionId)
- if (sessionInterrupted(sessionId)) {
- return
- }
-
+ // Status-store projections (todo mirror, delegate subagent upserts)
+ // bypass the interrupted gate below — they retire rows, they don't
+ // repaint the sealed bubble. Only the assistant bubble stays sealed
+ // after a Stop (mutateStream drops late writes on its own). Background
+ // work outlives the turn, so completions must still retire status rows
+ // (#81114).
// The composer status stack owns todo display now (no inline panel) —
// mirror every todo state the tool reports into its session store.
if (payload && isTodoToolName(payload.name)) {
@@ -576,6 +578,10 @@ export function useMessageStream({
}
}
+ if (sessionInterrupted(sessionId)) {
+ return
+ }
+
mutateStream(
sessionId,
parts => dedupeGeneratedImageEchoesInParts(upsertToolPart(parts, payload, phase, occurredAt)),
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/interrupted-status-sync.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/interrupted-status-sync.test.tsx
new file mode 100644
index 00000000000..a70b90f00a5
--- /dev/null
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/interrupted-status-sync.test.tsx
@@ -0,0 +1,94 @@
+import type { GatewayEvent } from '@hermes/shared'
+// #81114: a Stop/interrupt seals the assistant bubble, but background work
+// keeps running and its completions still arrive. Those completions must
+// retire the status-stack rows (subagent/delegate) that have no poll to
+// cover them — otherwise spinners run forever and async results only appear
+// after the next user message forces a re-hydrate.
+import { act, cleanup } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { finalizeUserInterruptedMessages } from '@/app/session/hooks/use-prompt-actions/rewind'
+import { $subagentsBySession } from '@/store/subagents'
+
+import { type MessageStreamHarness, renderMessageStream } from './test-harness'
+
+const SID = 'interrupted-status-sync-session'
+
+let stream: MessageStreamHarness
+
+function mountStream() {
+ stream = renderMessageStream(SID)
+}
+
+const emit = (event: GatewayEvent) => act(() => stream.handleEvent(event))
+
+// The state transform both Stop paths apply at the click.
+const pressStop = () =>
+ act(() => {
+ const state = stream.state()
+ stream.states.set(SID, {
+ ...state,
+ messages: finalizeUserInterruptedMessages(state.messages, state.streamId),
+ busy: false,
+ awaitingResponse: false,
+ streamId: null,
+ pendingBranchGroup: null,
+ needsInput: false,
+ interrupted: true,
+ turnStartedAt: null,
+ turnLive: false
+ })
+ })
+
+const subagentsFor = (sid: string) => $subagentsBySession.get()[sid] ?? []
+
+describe('interrupted turn still retires status rows (#81114)', () => {
+ beforeEach(() => {
+ $subagentsBySession.set({})
+ mountStream()
+ })
+
+ afterEach(() => {
+ cleanup()
+ vi.restoreAllMocks()
+ })
+
+ it('a delegate_task tool.complete after Stop retires the fallback row', () => {
+ emit({ payload: {}, session_id: SID, type: 'message.start' })
+ emit({
+ payload: { args: { goal: 'do it' }, name: 'delegate_task', tool_id: 't1' },
+ session_id: SID,
+ type: 'tool.start'
+ })
+ expect(subagentsFor(SID).length).toBe(1)
+
+ pressStop()
+
+ emit({
+ payload: { name: 'delegate_task', result: { status: 'success', summary: 'done' }, tool_id: 't1' },
+ session_id: SID,
+ type: 'tool.complete'
+ })
+
+ expect(subagentsFor(SID)[0]?.status).toBe('completed')
+ })
+
+ it('late tool completions still do not grow the sealed bubble', () => {
+ emit({ payload: {}, session_id: SID, type: 'message.start' })
+ emit({
+ payload: { args: { command: 'ls' }, name: 'terminal', tool_id: 'call-1' },
+ session_id: SID,
+ type: 'tool.start'
+ })
+ pressStop()
+ const sealed = JSON.stringify(stream.state().messages)
+
+ emit({
+ payload: { name: 'terminal', result: 'file.txt', tool_id: 'call-1' },
+ session_id: SID,
+ type: 'tool.complete'
+ })
+
+ expect(JSON.stringify(stream.state().messages)).toBe(sealed)
+ })
+})