Repository navigation
fix(responses): give the bounded JSON read a first-byte deadline distinct from inter-chunk inactivity (#1065) - #1088
Merged
Conversation
…inct from inter-chunk inactivity (#1065) Thinking-capable models can send early or chunked headers and then spend more than 30 seconds generating before emitting the first JSON body byte. Keep the 30-second inactivity deadline once body flow starts, but give the bounded JSON call site its existing 180-second total budget for the first byte. The total deadline wins the no-byte race, so a dead upstream remains bounded.
Contributor
|
✅ Deterministic PR hygiene checks passed. |
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughChangesBounded JSON response timeout
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant UpstreamJSONResponse
participant ResponsesCore
participant BoundedBodyReader
ResponsesCore->>BoundedBodyReader: readBoundedResponseBody(UPSTREAM_JSON_BODY_READ_OPTIONS)
BoundedBodyReader->>UpstreamJSONResponse: wait up to firstByteTimeoutMs
UpstreamJSONResponse-->>BoundedBodyReader: first JSON body chunk
BoundedBodyReader->>UpstreamJSONResponse: enforce inactivityTimeoutMs for later chunks
UpstreamJSONResponse-->>BoundedBodyReader: remaining JSON body chunks
BoundedBodyReader-->>ResponsesCore: bounded JSON response body
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4 tasks done
This was referenced Aug 7, 2026
Closed
7 tasks done
agentHits
pushed a commit
to agentHits/opencodex
that referenced
this pull request
Sep 17, 2026
…ody-first-byte fix(responses): give the bounded JSON read a first-byte deadline distinct from inter-chunk inactivity (lidge-jun#1065)
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.
Summary
502 upstream JSON response stalled before completingafter ~30.5s. Root cause:readBoundedResponseBodyarmed its 30s inactivity timer at reader creation — before the first body byte. A thinking model that flushes chunked headers promptly but computes >30s before emitting its first JSON byte was indistinguishable from a stalled upstream. Everydeepseek-v4-flashturn takes this bounded JSON path because the registry deliberately pinsmodelResponsesUpstreamStreaming: falsefor it ([Bug] DeepSeek V4 Flash Responses route stalls after tool calls #875 terminal-event unreliability), so slow-thinking turns athigh/maxeffort crossed the window and failed locally.BoundedBodyOptionsgainsfirstByteTimeoutMs, defaulting toinactivityTimeoutMsso every existing caller is behavior-identical (web-search loop, images loop, upstream-http-error, kiro-retry, auth-api, quota-rejection, and the other two core call sites). Only the bounded JSON upstream read opts in, passing the existing 180s total budget as the first-byte allowance — the total wall-clock deadline still bounds a genuinely dead upstream, and the 30s inter-chunk stall protection is unchanged once bytes flow.Verification
bun run typecheck— clean.bun test tests/bounded-body.test.ts— 21 pass, 0 fail (new: first byte delayed past inactivity but under first-byte deadline completes; no first byte before the deadline still fails closed; on-time first byte with a later inter-chunk stall still times out; defaulted option behaves identically to today; call-site policy pin assertingfirstByteTimeoutMs === totalTimeoutMsfor the bounded JSON read).Expected: "first byte" / Received: "" — 0 pass, 1 fail).bun test tests/responses-shadow-intercept.test.ts— 14 pass, 0 fail.bun run privacy:scan— passed.Closes #1065.
Checklist
Summary by CodeRabbit