Repository navigation
Conversation
The HTTP transport applied the chunk timeout to the raw response byte stream before framing. Framing drops SSE comment keepalives and other empty events, so any such byte reset the stall timer and a provider could hold a stalled generation warm forever (anomalyco#43519). This matched the native path but not the AI SDK path, whose wrapSSE resets only on parsed events. Bound the timeout on framed progress instead. A stream that only sends keepalives now still trips the chunk timeout, while real events keep resetting it.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
fix(ai): bound native stream stalls on framed events Move chunkTimeout from the raw byte stream to the framed stream so SSE comment keepalives no longer reset the deadline and mask a stalled generation. Aligns the native @opencode/ai transport with the AI SDK path, which already resets only on parsed events. Closes anomalyco#43519
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Related: #43618 (merged, AI SDK path) and #51879 (open, v1 + SDK path). This fixes the remaining native @opencode/ai HTTP transport, which still measured the stall on raw bytes after #49229.
Issue for this PR
Closes #43519
Type of change
What does this PR do?
chunkTimeoutwas applied to the raw response byte stream before framing inpackages/ai/src/route/transport/http.ts.Framing.ssedrops SSE comments(
: keepalive), empty events anddata: null, but the stall timer reset on anybyte, so a provider or proxy that keeps a stalled generation warm with comment
heartbeats never tripped the timeout (#43519).
This moves the timeout onto the framed stream so it resets on emitted events
only. A keepalive produces no frame and no longer counts as progress, so the
request fails with the existing
Transport{ operation: "read", code: "Timeout" }error and follows the retry policy. The AI SDK path already workedthis way (
wrapSSEinpackages/core/src/aisdk.tsresets only on parsedevents); this makes the native path match it.
Why it works:
Stream.timeoutOrElsearms its deadline per pull, and framingconsumes and drops non-event bytes within a single pull without emitting an
empty chunk, so dropped bytes cannot reset the deadline.
How did you verify your code works?
ignores SSE comment keepalives when bounding a stalled streamtopackages/ai/test/http-timeout.test.ts: a server sends one content chunk,then a
: keepalivecomment 10s later; withchunkTimeout: 20_000therequest must fail with the read timeout. Against the current
v2http.tsthe test times out instead of failing, so it is a real regression test.
bun typecheckinpackages/ai: passes.bun testinpackages/ai: 1730 pass, 28 skip, 0 fail.Screenshots / recordings
N/A (no UI change).
Checklist