[WRONG BRANCH] Bound stalled upstream response bodies - #176
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This pull request currently targets @luvs01 Please retarget this PR to Its title has been prefixed with This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again. |
📝 WalkthroughWalkthroughThe PR adds ChangesResponse body inactivity protection
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Upstream
participant ResponseGuard
participant Downstream
participant AbortController
Upstream->>ResponseGuard: Provide response body
Downstream->>ResponseGuard: Read wrapped body
ResponseGuard->>Downstream: Forward non-empty chunks
ResponseGuard->>ResponseGuard: Reset inactivity deadline
ResponseGuard->>AbortController: Abort upstream after inactivity timeout
Downstream->>ResponseGuard: Cancel stream
ResponseGuard->>AbortController: Abort upstream operations
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/server/responses/core.ts`:
- Line 2965: Update fetchTerminalGuardContinuation to pass the continuation
adapter response through guardResponseBodyInactivity before checking its status
or parsing the body, matching the initial upstreamResponse handling. Add a
regression test covering a headers-only continuation that stalls, and flag any
provider/adapter contract drift revealed by the fix.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 9d6fa39a-2d14-4f0c-ab68-439b689869ce
📒 Files selected for processing (4)
src/lib/response-body-inactivity.tssrc/server/index.tssrc/server/responses/core.tstests/response-body-inactivity.test.ts
| } | ||
| break; | ||
| } | ||
| upstreamResponse = guardResponseBodyInactivity(upstreamResponse, upstream, stallTimeoutMs); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Guard terminal-continuation response bodies.
Line 2965 guards only the initial adapter response. fetchTerminalGuardContinuation fetches another adapter response at line 3090. It parses that body at lines 3231-3235 without an inactivity guard.
If the continuation sends headers and then stalls, the parser remains pending and the upstream turn remains active. Wrap the continuation response before checking its status or parsing its body. Add a regression test for a headers-only continuation response.
Proposed fix
- response = await fetchContinuation(recoveryKind);
+ response = guardResponseBodyInactivity(
+ await fetchContinuation(recoveryKind),
+ upstream,
+ stallTimeoutMs,
+ );As per path instructions, flag provider/adapter contract drift.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/server/responses/core.ts` at line 2965, Update
fetchTerminalGuardContinuation to pass the continuation adapter response through
guardResponseBodyInactivity before checking its status or parsing the body,
matching the initial upstreamResponse handling. Add a regression test covering a
headers-only continuation that stalls, and flag any provider/adapter contract
drift revealed by the fix.
Source: Path instructions
Motivation
Description
src/lib/response-body-inactivity.tsthat arms only while an upstream read is pending, resets on non-empty chunks, and aborts the upstream controller on inactivity without counting downstream backpressure as a stall.src/server/responses/core.ts, using the configuredstallTimeoutSec(ms =stallTimeoutSec * 1000, default 300_000ms).src/server/index.tsso server consumers can reference it and preserve existing relay behavior for normal completion and client cancellation.tests/response-body-inactivity.test.tsthat cover headers-only upstream stalls, byte progress resetting the deadline, downstream backpressure, and presence of both server call sites.Testing
bun test tests/response-body-inactivity.test.tsand the new tests passed.bun run typecheck(bun x tsc --noEmit) and it passed.bun run privacy:scanand it passed.bun run test; the broader suite run encountered unrelated existing failures/timeouts (an auth-matrix assertion and a Grok model-list timeout) that are not caused by this change and prevented a complete end-to-end green run during this iteration.Codex Task
Summary by CodeRabbit