Skip to content

fix(ai): honor chunkTimeout on HTTP SSE streams - #48158

Open
holny wants to merge 2 commits into
anomalyco:v2from
holny:sse-chunk-timeout
Open

fix(ai): honor chunkTimeout on HTTP SSE streams#48158
holny wants to merge 2 commits into
anomalyco:v2from
holny:sse-chunk-timeout

Conversation

@holny

@holny holny commented Sep 9, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #46692

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

chunkTimeout was accepted in provider settings but never read on the native path — HttpOptions had no field, the HTTP transport applied no stall guard, and the setting was silently dropped. A stalled provider stream was bounded only by the OS socket.

  • Add chunkTimeout (ms) to HttpOptions and thread it through mergeHttpOptions
  • Apply it as a per-chunk timeout on the response stream in the HTTP transport (transport/http.ts), failing with a typed TransportError (chunk-timeout) when no chunk arrives within the window
  • Add chunkTimeout to ProviderPackage.Settings and wire it through the azure provider first; remaining providers share the same config() pattern and can adopt the same field
  • Preserve chunkTimeout when model.request hooks rebuild HttpOptions

How did you verify your code works?

  • New test/chunk-timeout.test.ts: a stalled SSE stream (one frame then silence) aborts with code: chunk-timeout under a real clock; mergeHttpOptions keeps the rightmost configured value
  • bun typecheck + bun test in packages/ai (954 passing) and packages/core (only pre-existing environment-dependent failures in git-worktree/pty tests, confirmed on a clean baseline)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Supersedes #46802 — the PR head fork was accidentally deleted on 2026-09-09 (not intentional, see the notification comment there); re-filing so the review can continue. Original conversation: #46802

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found related PRs that may be duplicates or closely related to PR #48158:

Potentially Related PRs:

  1. fix(provider): enforce chunk timeout regardless of content type #47621 - fix(provider): enforce chunk timeout regardless of content type

  2. fix(core): default provider header and chunk timeouts to five minutes #46917 - fix(core): default provider header and chunk timeouts to five minutes

  3. fix(provider): ignore SSE comment heartbeats for chunk timeout #43607 - fix(provider): ignore SSE comment heartbeats for chunk timeout

These PRs may have overlapping concerns with honoring chunkTimeout on HTTP SSE streams. Note that the current PR (#48158) explicitly supersedes #46802 (as mentioned in the description).

The chunkTimeout provider setting was accepted but never read on the native path: HttpOptions had no field, the HTTP transport applied no stall guard, and settings dropped it silently. A stalled provider stream was bounded only by the OS socket. Add chunkTimeout to HttpOptions, apply it as a per-chunk timeout on the response stream in the HTTP transport, and thread it through provider settings (azure wired first; the remaining providers share the same config() pattern). The field flows through route defaults and mergeHttpOptions, which resolve after session model.request hooks, so no core-side preservation is needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant