Skip to content

fix(upstream): REQUEST_TIMEOUT guards TTFB only, never the streamed body - #355

Merged
trefeon merged 1 commit into
mainfrom
fix/stream-timeout-ttfb
Sep 5, 2026
Merged

fix(upstream): REQUEST_TIMEOUT guards TTFB only, never the streamed body#355
trefeon merged 1 commit into
mainfrom
fix/stream-timeout-ttfb

Conversation

@trefeon

@trefeon trefeon commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Problem

Healthy long streams were cut at REQUEST_TIMEOUT (default 15m): the request-context deadline killed the body read mid-stream even while upstream kept feeding data. Observed live: turn-heavy agent sessions die at exactly the bound with no upstream error.

Change

  • client.go: transport.ResponseHeaderTimeout = c.requestTimeout — the knob now bounds only the wait for response headers (TTFB).
  • chat.go: removed the context.WithTimeout wrap around the chat request; the streamed body runs until upstream EOF or the caller's context cancels (client disconnect).
  • Control calls unaffected: SessionCallTimeout ctx deadlines are tighter and untouched.
  • keycatalog.go: REQUEST_TIMEOUT description now states TTFB-only semantics; fixture regenerated.

Verification

  • TestChatStreamSurvivesPastRequestTimeout: 1.5s stream with 400ms knob — passes post-fix, failed pre-fix (context deadline exceeded at 400ms).
  • TestChatTTFBTimeoutStillAborts: stalled headers still abort near the bound.
  • Hermetic backend suite: all packages green.

The request-context deadline cut healthy long streams at the default 15m:
a turn-heavy agent session died mid-stream while the connection was still
feeding data (observed live). Move the bound to the transport's
ResponseHeaderTimeout so it aborts only when response headers never
arrive; the streamed body now runs until upstream EOF or the caller's
context cancels (client disconnect). Control calls keep their own
SessionCallTimeout ctx deadlines, unaffected.

- client.go: transport.ResponseHeaderTimeout = c.requestTimeout
- chat.go: drop the WithTimeout wrap around the chat request context
- keycatalog.go: REQUEST_TIMEOUT description states TTFB-only semantics
- client_chat_test.go: stream survives past REQUEST_TIMEOUT; stalled
  headers still abort near the bound
- config-meta.json: regen fixture (FP_REGEN_FIXTURE=1)
Copilot AI balanced review requested due to automatic review settings September 5, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@trefeon
trefeon merged commit fc58fff into main Sep 5, 2026
6 checks passed
@trefeon
trefeon deleted the fix/stream-timeout-ttfb branch September 5, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants