Closing the chat stream cancels the turn and loses the reply #1848

Closed
opened 2026-11-10 08:06:58 +00:00 by sam · 2 comments
Owner

A chat turn dies when the browser stream that started it closes, so the operator never gets the answer. Two turns on 2026-11-10 ran five and six minutes, made 8 tool calls each, and ended cancelled with context canceled and no assistant message. The trace shows archie-ui's ChatService/Stream call cancelled first and the gateway turn following it.

The UI aborts the stream on a conversation switch or unmount (selectSession → abortActiveTurn in ui/src/chat/state.ts), and the gateway runs the turn on the request's context, so the abort cancels model and tool work already paid for.

Done when a turn runs to completion and persists its reply after the stream that started it closes, and reopening the conversation shows that reply (or the running turn). Stop stays the only way to cancel a turn.

A chat turn dies when the browser stream that started it closes, so the operator never gets the answer. Two turns on 2026-11-10 ran five and six minutes, made 8 tool calls each, and ended `cancelled` with `context canceled` and no assistant message. The trace shows archie-ui's `ChatService/Stream` call cancelled first and the gateway turn following it. The UI aborts the stream on a conversation switch or unmount (`selectSession` → `abortActiveTurn` in `ui/src/chat/state.ts`), and the gateway runs the turn on the request's context, so the abort cancels model and tool work already paid for. Done when a turn runs to completion and persists its reply after the stream that started it closes, and reopening the conversation shows that reply (or the running turn). Stop stays the only way to cancel a turn.
Author
Owner

Fixed in 13ec69372 on main: the gateway runs a streamed turn on a context detached from the caller's stream, so a conversation switch or reload no longer cancels it; the reply is saved and shows when the conversation is reopened. Stop still cancels through /api/chat/cancel. task check passes. Not deployed.

Fixed in 13ec69372 on main: the gateway runs a streamed turn on a context detached from the caller's stream, so a conversation switch or reload no longer cancels it; the reply is saved and shows when the conversation is reopened. Stop still cancels through /api/chat/cancel. task check passes. Not deployed.
sam added the bug label 2026-11-12 15:52:54 +00:00
Author
Owner

Fixed by 13ec6937: the streamed turn runs on a context detached from the stream, so closing the stream (UI abortActiveTurn only aborts the fetch) leaves the turn running and its reply persisted. Stop is the only cancel path. TestStreamedTurnSurvivesCallerDisconnect covers both, and fails with the fix reverted.

Fixed by 13ec6937: the streamed turn runs on a context detached from the stream, so closing the stream (UI abortActiveTurn only aborts the fetch) leaves the turn running and its reply persisted. Stop is the only cancel path. TestStreamedTurnSurvivesCallerDisconnect covers both, and fails with the fix reverted.
sam closed this issue 2026-11-13 16:45:31 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1848