You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wait helpers ignore event: error and duplicate the stream parser #20
runStreamingAgentAndWait() has its own copy of the fetch, reader and SSE parser pipeline, separate from runStreamingAgent(). The copies have drifted, and the wait helper mishandles several stream endings:
event: error and event: timeout are ignored. The server sends error when the stream fails internally, and timeout after 600s, then closes the stream. The wait helper treats that as an early end, and the server's message is lost.
A final line without a trailing newline is dropped. Text left in the parser's buffer at the end of the stream is never parsed.
The response body stays open after done. The reader is cancelled only on the returnOnResult path.
Abort listeners leak.anySignal adds a listener to the caller's signal and never removes it, so a caller that reuses one AbortSignal collects one listener per call.
A timeout produces two different errors, depending on whether it fires during the fetch or during the read. The incomplete-run message is also built in two places.
Why it matters
A run that failed on the server comes back as a generic error, without the server's message. Every fix to the stream handling has to land in two places.
Done when
runStreamingAgentAndWait() is built on runStreamingAgent() (for await, tracking the latest snapshot and returning early).
event: error and event: timeout throw SeclaiStreamingError with the server's message (for error) and the latest snapshot in run.
A final unterminated line is parsed.
Every exit cancels the reader.
No listener is left on the caller's signal after a call.
Each case above has a test.
Out of scope
Changing what the default mode returns for a stream that ends without done. That stays as released until throwOnIncomplete becomes the default in the next major version.
More from the review of #19 (round 5), for the same rework:
Abort handling:runAgentAndPoll checks signal only between polls, and never passes it to runAgent(), getAgentRun() or the sleep. So an already-aborted signal still starts a (billable) run, and an abort during the sleep still sends one more GET. Both were in 1.8.0.
Timeout overshoot: the timeout is checked only before each sleep, so timeoutMs can overshoot by up to one pollIntervalMs.
The fix for both is to pass signal through the requests and an abortable sleep, and to cap the sleep at the time left before the deadline.
More from the review of #19 (round 6): make runAgentAndPoll's abort surface as the abort error, as the streaming helpers do. Use signal.throwIfAborted() instead of throwing SeclaiError("Polling aborted."), so callers get an AbortError carrying signal.reason. That changes the type a caller catches, so it needs a changelog entry.
More from the review of #19 (round 9): with includeStepOutputs, the step-outputs fetch for a start run that already ended isn't bounded by timeoutMs. A slow or failing GET after the deadline delays the call or throws, though a finished run was in hand. Also untested today: that err.run is the runAgent() response when timeoutMs elapses before any poll.
Activity
burgaard commentedon Nov 6, 2026
More from the review of #19 (round 5), for the same rework:
runAgentAndPollcheckssignalonly between polls, and never passes it torunAgent(),getAgentRun()or the sleep. So an already-aborted signal still starts a (billable) run, and an abort during the sleep still sends one more GET. Both were in 1.8.0.timeoutMscan overshoot by up to onepollIntervalMs.The fix for both is to pass
signalthrough the requests and an abortable sleep, and to cap the sleep at the time left before the deadline.burgaard commentedon Nov 6, 2026
More from the review of #19 (round 6): make
runAgentAndPoll's abort surface as the abort error, as the streaming helpers do. Usesignal.throwIfAborted()instead of throwingSeclaiError("Polling aborted."), so callers get anAbortErrorcarryingsignal.reason. That changes the type a caller catches, so it needs a changelog entry.burgaard commentedon Nov 6, 2026
More from the review of #19 (round 9): with
includeStepOutputs, the step-outputs fetch for a start run that already ended isn't bounded bytimeoutMs. A slow or failing GET after the deadline delays the call or throws, though a finished run was in hand. Also untested today: thaterr.runis therunAgent()response whentimeoutMselapses before any poll.