Repository navigation
fix(studio): fail a chat turn whose model stream goes idle - #850
Merged
Merged
Conversation
A model response that stopped sending events held its chat request open forever. The Studio OpenAI client now bounds the wait for response headers and each gap between provider events at 60 seconds with Effect's native timeouts. A stall fails the stream with an AiError, which the existing AG-UI lifecycle turns into RUN_ERROR, and interrupting the stream aborts the gateway request. Tool execution runs outside the provider stream and is not timed. Pre-810 chat had no idle bound to match. The boundary test drives the real handler with TestClock: a stall before headers and a stall after active events both end in RUN_ERROR with the gateway cancelled and no retry, and events arriving just inside the bound keep the turn alive.
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.
A Studio model response that stopped sending events held its chat request open forever.
The Studio OpenAI client override in
apps/studio/src/features/chat/model.server.tsnow limits two waits to 60 seconds each: the wait for response headers (Effect.timeoutOrElse) and each gap between provider events (Stream.timeoutOrElse, applied beforepreserveOutputLimit). A stall fails with anAiError. The existing AG-UI lifecycle turns that intoRUN_ERROR, and the browser already showsRUN_ERRORas an error. Interrupting the stream aborts the gateway request.Tool execution runs outside the provider stream, so tools are not timed. Pre-810 chat (
2b4ad29d) had no idle bound to match, so 60 seconds is new policy. Studio uses reasoning effort none, so we expect a healthy stream to send events every few seconds. That is a policy expectation, not a measured guarantee. A timeout that fires too early kills a valid turn, so the bound leans long.Proof
The boundary test in
agent.server.test.tsdrives the real handler and gateway withTestClock. It stalls before headers in one run and after events in another. Each run ends inRUN_ERRORwith noRUN_FINISHED, the gateway aborted and exactly one gateway call. In the second run, two 59-second gaps between events (118 seconds in total) do not time out.Each of these mutations makes the test fail: removing the stream timeout, removing the headers timeout, replacing the idle bound with a total deadline, or using the silent
Stream.timeout.Studio tests 218/218.
pnpm ci:local --no-signoffagainstorigin/mainpasses in 2m47s.Signoff:
pnpm ci:localon the pushed headdd8260f5passed and postedlocal-ci.Independent Sol review: ACCEPT on
dd8260f5, no findings. 28/28 focused tests and 3 independent mutations; request-owned telemetry is kept in both stall cases.Local split browser proof: PASS. This is not full end-to-end timeout proof. The real handler, gateway transport and OpenAI decoder produced the stall SSE:
RUN_ERRORbefore headers, two 59-second gaps kept alive, thenRUN_ERROR, plus a healthy turn ending inRUN_FINISHED. The built Studio page replayed those captures and showed "The agent run failed." with Try again. Retrying started a new run that recovered with a rendered reply. Console and page errors were empty. No paid, model or remote calls were made. Browser timing, real provider or Worker cancellation, preview and production were not tested.