Repository navigation
Fix native Responses recovery after prelude-only EOF - #8292
Conversation
|
Caution Review failedThe pull request is closed.
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. |
|
✅ Deterministic PR hygiene checks passed. |
Native passthrough reset recovery returned the original HTTP head at once and then refused any replacement whose status or headers differed. Per-send quota headers, request ids and x-codex-turn-state always differ, so an ordinary pre-output reset or clean EOF could no longer recover. Dispatch now starts the protocol preflight immediately and waits for the first of selection, abort, or one heartbeat interval capped by the stall timeout. A selection that finishes first publishes the selected response, including a replacement with its own status, headers and body. When the deadline wins, the original head is returned and the same preflight continues behind it; a replacement must then match that head, checked at acceptance and on arrival. The published head is bound to the main quota proof of the attempt that produced it, so a renewed context proof cannot move ownership. The OpenGateway completion hold is shortened by the time selection already held the head. Abort ends selection or the hold at once without awaiting source cleanup.
Pre-head reset selection holds a canonical buffered turn for up to one heartbeat interval (capped by the stall budget) before the collector starts. The collector then began a fresh first-byte clock and treated any delivered byte as activity, so a silent upstream with a 5 s stall budget failed after about 10 s, a prelude read during selection and replayed later reset the clock, and a quiet replacement behind a committed head inherited the original's last activity and was cut short. Guard the original body and any accepted replacement at their upstream reads for the canonical buffered consumer, as OpenGateway already is, so each physical attempt's stall budget runs from its own head. The collector reports the guard's failure as a stall timeout, which the reset gate never resends. The held stream also reports a replacement head that lands behind a committed head, so the collector's own byte clock never ends a turn before the guard.
Native reset selection held a direct streaming client's response head for up to one 15-second heartbeat interval while it inspected the original upstream. A client with a shorter header timeout failed on a healthy slow turn, including requests the resend gate could never replace. A request that is not self-contained now skips the preflight entirely, so its head and prelude are relayed as for a provider without reset replay. A direct stream commits the original head once the original's own inspection has run for 250 ms; inspection continues behind that head and a replacement must then match it exactly. A failure observed inside the window still waits for the replacement's own head, bounded by the existing deadline. Bun's server writes a head only with the first body bytes, so the window commit owes the client an SSE comment at once, as the deadline commit already did. Canonical buffered JSON and combo children keep the deadline because their consumers publish no head first. The physical replay guard memoizes its verdict for the body that left, so the eligibility check does not parse a large outbound body twice.
The quota observation case for a head committed before a reset used a one-second stall budget as its commitment timer. The same budget arms the upstream inactivity guard on the original body, and a guard timeout is never replayed, so on a slow runner the guard could win and the case saw one send instead of two. The case now arms the fixture clock to capture the direct-stream inspection window and fires it itself before releasing the reset, while the inactivity guard keeps the default 300-second budget. The window moves from 250 ms to 200 ms because the fixture clock already claims every 250 ms timer as the quota persistence debounce, which had silently swallowed the window in this file.
# Conflicts: # src/server/responses/combo-stream-preflight.ts # structure/transports/responses-combo-boundaries.md # tests/routing/combo-stream-preflight.test.ts
…ls; cover the physical replay guard
Maintainer judgment: hold (not merging yet)Taken over from the unreachable lane. At Regression: post-head reset recovery becomes unreachable. On I tried relaxing the check to status plus media type. It breaks 23 tests that deliberately pin refusal on a different model, quota, turn state, request id or
Fixed at Verification at |
…carry # Conflicts: # src/server/responses/combo-stream-preflight.ts # src/server/responses/passthrough-dispatch.ts # src/server/responses/reset-replay.ts # structure/transports/responses-failover.md # tests/fixtures/test-layout-expected.json # tests/routing/combo-stream-preflight.test.ts
…relude A native Responses SSE body that closes cleanly after only lifecycle events left the client with a head and no output. The recovery lane already replaced that body, but only when the replacement's complete header set matched the committed one. Real origins vary `date`, `x-request-id`, `x-codex-turn-state` and the quota headers per attempt, so post-head recovery was unreachable, and the same check also narrowed the reset lane, which had always accepted any replacement after a mid-stream reset. Acceptance now follows how the stream ended. A read error keeps the reset lane's behaviour unchanged. A clean pre-output EOF behind a committed head compares a normalized identity subset instead: status, status text, content-type media type, `openai-model` and `x-codex-turn-state`. The first is the model the origin actually served; the second is this proxy's own turn handle, bound at issuance and redeemed only at a matching physical send. Volatile and hop-by-hop headers are ignored because the client already holds the original's values. The physical replay guard moved to `native-replay-guard.ts` so dispatch stays under its line cap, and `record` clears a pending authorization in `finally` so a send that throws before leaving cannot fence a later unrelated send. Covered by real local HTTP tests for both post-window outcomes and by unit tests for the guard's throwing, hosted and provider-executed paths.
…nventory The replay guard extracted from passthrough dispatch is reached from core.ts, so the source-oracle inventory must list it (responses-core-modules).
Maintainer judgment: mergeHead reviewed: Value. Fixes #8231. A native Responses SSE body that closed cleanly after only its lifecycle events left the client with a response head and no output. The proxy now recovers such a stream with one bounded replacement. While the head is still open, which lasts up to 200 ms, the replacement publishes its own head. After the head is committed, the replacement is accepted only if it matches the original's identity. No other open PR covers this. Owner decision applied (option c). User-visible change. For a reset inside the 200 ms window, before the head is committed, the client now receives the replacement's own head. Only the replacement attempt's quota is published, under that attempt's proof (99% versus the arrival attempt's 17% in the fixture). No regression for existing users. I ran Windows. No platform-specific code changed. Evidence.
NOT RUN: full |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Summary
Closes #8231
Verification
bun scripts/test.ts --parallel=1 --dotswith nine focused and guard files: 680 passed, 0 failed. The set includes layout, file-size ratchet and Lab guards.bun run typecheck,bun run privacy:scanandbun run structure:checkpassed.test:changedat an earlier head timed out at its existing 900-second limit; it did not complete. Full local suite and live provider tests were not run. Exact-head hostedci:fullis pending.git push --no-verify; focused verification above was run explicitly.Checklist