CL-6486: time out a reply that stalls mid-stream - #220
Merged
Merged
Conversation
The existing test asserted that a single token permanently disarms the 120s backstop; that's the CL-6486 bug, not a contract worth keeping. Replace it with tests for the corrected contract: a token resets the silence window rather than clearing it, and silence after a token still times out a mid-stream stall.
The 120s backstop only armed while the reply was still tokenless (isPendingReply). The instant one token streamed it stopped re-arming, so a turn that starts streaming and then dies (model OOM, dropped Ollama connection, sidecar crash) froze mid-sentence behind a blinking cursor forever, with no error and no retry. Arm the backstop for the whole "awaiting" phase instead of just its empty-text prefix. Each token produces a new streamingReply object, so the effect's own dependency already tears down and re-arms the timer on every token — this measures the gap since the last token, not total elapsed time, so a healthy long-running local turn (round 1 measured ~216s on qwen3.8:27b) never trips it.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The 120s stale-backstop in
useStreamingReplyonly armed whileisPendingReplywas true — phase"awaiting"andtext === "". The instant one token streamed, the guard returned early and never re-armed. A reply that starts streaming and then dies (model OOM, dropped Ollama connection, sidecar crash — all routine with local models) froze mid-sentence behind a blinking cursor forever: no error, no retry, indistinguishable from "still thinking."The no-token case was already handled honestly (120s -> "No reply arrived — the agent may be unavailable."). This closes the gap for the mid-stream case, reusing the same honest-failure path.
Fix
Arm the backstop for the whole
"awaiting"phase instead of just its tokenless prefix. Each token produces a newstreamingReplyobject (awaiting(text)always returns a fresh literal), so the effect's own[streamingReply, clearMs]dependency already tears down and re-arms the timer on every token, with no extra ref bookkeeping needed. That means the timer measures silence since the last token, not total elapsed time.Window: kept at 120s (
PENDING_REPLY_CLEAR_MS)Reused the existing constant rather than introducing a second one:
qwen3.8:27b— but that's cumulative time across multiple inference rounds, tool calls, and thinking, not a single continuous gap with zero new tokens. Because the window now resets on every token, a turn producing tokens at any reasonable cadence never gets close to 120s of pure silence, no matter how long the whole turn runs.Tests (
packages/chat-ui/test/use-streaming-reply.test.tsx)packages/chat-ui.tsc --noEmitclean.bun run lintfrom repo root: 0 errors (12 pre-existing warnings, none in touched files).Not done — reporting as the next unit (audit finding 7)
useWorkbenchStream's connection state ("connecting"|"live"|"polling") is still discarded by its only caller inchat-workspace.tsxand never rendered. Surfacing it quietly when the transport is degraded (without turning it into chrome on a healthy connection) is a separate, judgment-heavy UI change and didn't fit this timebox alongside the backstop fix + tests. Flagging for a follow-up issue rather than rushing it in.What I did not verify
settle()), per the no-stack-boot constraint on this lane.chat.reply-timed-outnotice renders through the same honest-failure path as before (unchanged), but there's no retry affordance wired to it in the codebase today (unlike the pending-send retry/discard flow). Wiring a retry action for a stalled agent reply looked like its own feature (re-invoking a turn, not just re-sending a message) rather than a one-line addition, so I left it out rather than bolt on something half-considered under time pressure.Fixes CL-6486