Repository navigation
fix: pause the Responses WS lane under backpressure instead of failing the exchange - #2093
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2132-pr.2093.b9c4d7aThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2093.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Review of #2093: simulating the exact retained formula against the fixture frame sizes shows the 2x guard trips during the 17th delta (index 16), not around delta 23. Comment-only fix.
[bot] 🏷 Reviewed #2093 against #2076. Verdict: mergeable — root-cause fix, teeth-verified regression tests, clean diff, all 14 CI checks green, base is current master. Verification performed (not just read-the-diff):
Structured seven questions:
Minor fix applied directly (labeled follow-up commit Sequencing note (not a blocker): open PR #2004 also touches Closes #2076. Ready to merge. |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.13-master.93d3677 # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
ResponsesWsUpstream.fetch(src/responses-ws.ts:273) hard-failed the whole exchange whenever the consumer's stream backlog exceeded ~1xMAX_REQUEST_BYTES(~100 MiB):if ((controller?.desiredSize ?? 0) < 0) throw new Error("Responses WebSocket upstream buffer limit exceeded"). A slow client (or the pipeline legitimately stalling between chunks while doing async kernel work —src/loop/adapter-responses.tsreads viagetReader()/for await) plus a large/large-terminal-frame Responses stream aborted mid-generation even though both ends were healthy.Root cause & fix approach
The undici
WebSocketsocket cannot be paused, so "pause the source" has to be a software gate. The fix makes the ReadableStream's own native queue the backpressure buffer: frames arriving while the consumer lags simply wait in the queue — delivery is consumer-paced by construction, which IS the pause. No pull-promise gating (a pending pull that only resolves on the next WS message deadlocks in the tail state: all messages received, backlog parked, consumer stalled, no further message to wake the engine — reproduced before shipping).A consumer that NEVER catches up must still be bounded, so a
retainedestimate tracks the backlog: exact while the queue is under the highWaterMark (requestBytes - desiredSize, Node's byte-sized formula), conservative accumulation beyond. The guard now trips atretained > 2 * requestByteswith the SAME error message and the SAME shared-catch path (reason=invalid-event, checkpoint reset, socket teardown) as before.requestBytesis an internal constructor parameter (defaultMAX_REQUEST_BYTES, identical to the previous hard-coded value) so tests can exercise the backpressure window with small budgets; it is NOT user-facing configuration.Behavior change (old -> new)
reason=invalid-eventlog path, cancel/close semantics, non-streaming branch) is unchanged.Config surface
N/A — no user-facing config, env var, or CLI flag added or changed. The new constructor parameter is internal test injection with a default equal to the previous hard-coded constant.
Tests
Closes #2076