Skip to content

feat(proxy): stream Responses answers with our tool search (#884) - #894

Merged
amiddavid merged 3 commits into
mainfrom
feat/responses-884
Nov 4, 2026
Merged

amiddavid merged 3 commits into
mainfrom
feat/responses-884

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior change (needs a human's yes)

  • Who: ultrahigh users on the OpenAI Responses wire (POST /openai/v1/responses) whose request declares our tool search AND has store: false and no previous_response_id. Codex CLI over HTTP is one.

  • Old: the proxy held the whole stream. The answer reached the client at once, at the end.

  • New: text streams as it arrives. The proxy holds from our search call. The follow-up joins the same stream. The client sees ONE response id (round 1's) and ONE merged response.completed.

  • Not changed: a request with store true or absent, or with previous_response_id, keeps the full buffering.

  • Turn off: leave ultrahigh (tool search off). There is no separate switch.

  • Second behavior change, same PR (owner approved): a WebSocket upgrade (GET /openai/v1/responses with Upgrade: websocket) now gets 426 Upgrade Required.

    • Who: Codex users behind the proxy.
    • Old: 405. Codex retried 5 times (~9 s at session start), then fell back to HTTPS.
    • New: Codex falls back to HTTPS at once (~1 s). Measured live, same fake server.
    • Off: none needed. A plain GET still gets 405 with Allow: POST.

Summary

What changed

  • proxy/ssepeek.go: newResponsesSSESplicer, responsesProxyToolCallName, rewriteResponses, terminateResponses.
    • Detect our call on response.output_item.added.
    • Drop the follow-up's response.created and response.in_progress.
    • Move output_index and sequence_number past what the client holds.
    • Give the follow-up round 1's id.
    • Replace the follow-up's response.completed with one that holds every item the client saw, in order, and the summed usage.
    • A turn with no terminal event ends with response.failed.
  • proxy/proxy.go: statelessResponses, and the routing of a stateless Responses stream to the splicer.
  • Fail open: on a call mixed with a client tool, a call that cannot be answered, or the round cap, handBack writes round 1's held bytes unchanged.

Data dependence

None new. Nothing is stored. docs/data-dependence.md needs no change.

WebSocket result (Codex 0.160.0, live)

  • The proxy has no WebSocket route. A WebSocket upgrade is a GET. It got 405 before this PR and now gets 426 (see above). Codex's source (core/src/client.rs) falls back at once only on UPGRADE_REQUIRED.
  • Fake server that mimics this: Codex retries 5 times, then prints "Falling back from WebSockets to HTTPS transport" and finishes the turn over HTTP. The final answer arrived.
  • So a Codex session with supports_websockets = true behind the proxy ends on HTTP with store: false — the case this PR splices. Cost: about 10 seconds of retries at the start of a session.
  • Not tested: a real WebSocket upstream. The proxy would not forward one.

How it was tested

Box 2, fresh tar sync into an empty dir.

Command Result
go test ./proxy/ -run "Responses|Splice|ClientSearch" ok
CGO_ENABLED=1 go test -race ./proxy/... ok (507 s)
CGO_ENABLED=1 go test -race ./expand/... ok
gofmt -l proxy, go vet ./proxy/ clean

New tests (proxy/ssepeek_responses_test.go): text and client tool pass byte for byte; our call is held and rounds merge (one id, one completed, 2 items, summed usage, renumbered output_index / sequence_number); an item missing from or only in the follow-up's completed; opening call counts as buffered; hand-back is verbatim; cut-off stream ends with response.failed; statelessResponses cases; end to end through the handler for store:false (spliced) and store absent (buffered).

Mutation checks (both caught, then restored):

  1. Merged output without round 1's items: 3 tests fail.
  2. Remove the statelessResponses gate: the store default end-to-end test fails.

Client behavior behind these shapes is in the #884 comment: Codex and the OpenAI SDK read output_item.done, ignore sequence_number; the SDK responses.stream fails if created and completed ids differ, so one id is required.

Technical notes

  • usage is summed over rounds only when response.usage is an object.
  • The merged output is round 1's output_item.done items the client saw, then the follow-up's own output list. An item only in the follow-up's completed is kept. One missing from round 1's completed is still in the merge.
  • Not covered: Agents SDK, openai-node (owner: ignore). Chained clients (WebSocket, previous_response_id) keep buffering.

🤖 Generated with Claude Code

A stateless Responses request (store:false, no previous_response_id) that
declares context_guru_tool_search now goes through the existing sseSplicer.
Text streams at once. The stream holds from our call. The follow-up joins
the same stream under round 1's id, with one merged response.completed.
A request that may chain keeps the full buffering.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 14f5db44cf46 blocking

Verdict: blocking

Findings

  1. proxy/proxy.go:1798 — respSplice stays true after the 400-retry turns our search off, so the retried original gets the splice the code says it must not get
    • What fails: a stateless Responses request (store:false) declares our search. The upstream refuses the rewritten request with 400 or 422. Line 2069 resets di, searchOn = nil, false — "nothing to hold or answer from here on". But respSplice was computed once before the loop and is not reset. The retried original (di.orig) then matches the splice case at proxy.go:2167 through respSplice alone, with searchOn false.
    • Result on that path: the retried answer is spliced and inspected, not streamed through. An expand call in it is withheld and answered in band, and a stream without its own terminator gets a synthetic response.failed appended. On the base commit the same request streams through untouched (case at proxy.go:2229), and the chat and Anthropic wires still do, because their case tests searchOn, which was reset. So this is an edge-case behavior change that only the new flag makes, and it contradicts the comment written one line above the reset.
    • Proof: proxy.go:1798 sets respSplice := searchOn && ... before the loop; proxy.go:2069 resets searchOn only; proxy.go:2167 reads ... || respSplice with no searchOn; proxy.go:2187 then calls sp.pass without tooldefer.ClientSearchName because searchOn is false.
    • Fix: reset the flag with the state it derives from — di, searchOn, respSplice = nil, false, false at proxy.go:2069. Add a test like TestClientSearchRetriesOriginalOn400 on the /openai/v1/responses route with "store":false and an SSE answer.

Non-blocking

  • proxy/ssepeek.go:818 — terminateResponses does not treat data: [DONE] as a terminator. A gateway that ends a Responses stream with [DONE] (the official API does not) gets a response.failed appended after the done marker, because sp.ended is set only by response.completed / failed / incomplete. Chat has isChatDone for this. Low risk; the event shapes were checked against Codex 0.160.0 and the OpenAI SDK.
  • proxy/ssepeek.go:801 — the merged usage is written only when the later round's response.completed carries a usage object. When it does not, the tokens summed from the earlier rounds are dropped and the client sees no usage. Fail-open direction; no wrong number is reported.
  • proxy/ssepeek.go:757 — msgStart is set only by response.created. A stream that opens straight into output items (no response.created) gets no synthetic response.failed when it is cut off, because terminate returns early. The protocol always sends response.created first.
  • Pre-existing, not from this PR: searchTally.add reads ReadSearchesSSE, which parses content_block_start (Anthropic shape only). The deferral ledger therefore counts no searches on a Responses SSE round. The chat splice (#879) has the same gap.

What I checked

  • The full diff (proxy.go, ssepeek.go, both test files) and the code around each change.
  • The splicer invariants: withheld always belongs to the last round that ran round(), and base matches that round, so no handBack can double-shift an index. Checked the JSON-round-after-stream anomaly, the round-cap exit, the upstream-failure exit, and the 16 MB retain-bound over path inside pass.
  • Index and event numbering: output_index remap past the items the client holds, sequence_number continued from evCount, dropped response.created / in_progress / queued in later rounds, round 1 byte-for-byte.
  • The merged terminal event: prevItems snapshot at round() start plus the follow-up's own list, no duplicates across rounds 2 and 3, usage summed once per response.completed (withheld ones included, handBack does not re-add).
  • statelessResponses: store:false plus no previous_response_id; a null previous_response_id fails safe toward buffering; the string "false" is rejected.
  • The serve loop wiring: case order at proxy.go:2167, sp.opened() for an opening call, countLeak, noteLeakedSearches at the cap, AggregateSSE on the retained round bytes, and the recorder path.
  • Fail-open paths: mixed client-tool call, aggregation failure, Continuation failure, handBack verbatim in round 1.
  • Tests: read all new tests in ssepeek_responses_test.go and the changed helper in tooldefer_search_test.go. They cover passthrough, withhold-and-merge, keeps-what-the-client-saw, opening call, handBack, cut-off rounds, statelessResponses, and the end-to-end pair (spliced vs buffered). The 400-retry path on Responses is the one gap (finding 1).
  • CLAUDE.md rules: fail-open holds on every path I traced; no new data dependence (the splice works on stream bytes only, like the chat splice); no new exported metrics.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 14f5db44 approve

Verdict: approve

Findings

None. I traced every new path and found no wrong behavior, no data loss, and no broken
fail-open path. The checks that convinced me:

  1. Round 1 is byte-for-byte. rewriteResponses (proxy/ssepeek.go:734) changes nothing in
    round 1: the later block is skipped, and np == payload returns the event untouched.
    TestResponsesSpliceTextStreamsUntouched pins it.
  2. The merged response.completed lists what the client holds. prevItems is snapshotted
    in round() before the round streams (ssepeek.go:189), so a round can never duplicate its
    own items. A later round's dropped response.created/in_progress cannot reset state.
  3. Fail-open paths hold. I traced bail(), the upstream-error path, the round cap, the
    retain bound, and the hand-back. In each case the client ends with a complete turn:
    either the withheld events verbatim (round 1, later == false), or renumbered correctly
    (round() has run, so base matches the items the client holds), or a synthetic
    response.failed (ssepeek.go:818). base advances only inside round(), so round-1
    bytes handed back after a round-2 failure are still renumbered by 0 — verbatim.
  4. The stateless gate is sound. store:false means the server keeps nothing to chain on,
    and previous_response_id is refused on top (proxy/proxy.go:2488). The string "false"
    is rejected (st.Type == gjson.False). expand.Continuation copies the request body, so
    round 2 stays stateless too.
  5. Usage sums once. addUsage runs only in pass, never in forward or handBack, so a
    handed-back completed cannot double-count. The merged event reports the sum of every round.
  6. The injected tools are all type:"function" on this wire (expand.ToolDefRaw,
    tooldefer/clientsearch.go:52), so a call always arrives as a function_call item, which is
    the only shape responsesProxyToolCallName accepts. No proxy call can slip past the cut.

Non-blocking

  • proxy/proxy.go:1798 vs proxy/proxy.go:2069 — respSplice is not reset on the deferral
    retry.
    The retry sets di, searchOn = nil, false but leaves respSplice true, so the
    retried original-body response still takes the splice path (with the search tool dropped
    from the withhold set). The Chat Completions splice resets its equivalent condition. The
    outcome is still correct: store is unchanged in di.orig, so the stateless check holds,
    and the splice machinery is dialect-correct for expand/adjudicate calls. Worth a comment
    or a reset, for symmetry with the chat path.
  • ssepeek.go:801 — the usage merge covers only the three top-level counts. Nested
    input_tokens_details / output_tokens_details keep the last round's values, and a later
    response.completed with no usage object gets no merge at all. Client-side accounting
    fidelity only; the proxy's own usage reads each round's raw events.
  • ssepeek.go:818 — terminateResponses ignores its withheld argument. Every call site
    runs handBack first, so a withheld terminator has already gone out and terminate is a
    no-op via sp.ended. Correct, but the signature reads as if the bytes were used.

What I checked

  • The full diff: proxy/proxy.go, proxy/ssepeek.go, proxy/ssepeek_responses_test.go,
    proxy/tooldefer_search_test.go.
  • The code around each change: the whole serve loop (rounds, retry, bail, cap, upstream
    error), all of ssepeek.go, and the shared pass/forward/rewrite/terminate plumbing.
  • expand/response.go (Continuation for the responses wire — round 2 preserves store),
    expand/expand.go (tool shapes), expand/inject.go, schema/wire.go (WireResponses is
    distinct from WireOpenAI, so the chat-splice condition cannot catch a Responses stream),
    tooldefer/clientsearch.go, proxy/usage.go (response.usage is a supported SSE path).
  • State traces: round-1 passthrough, withhold at the call, round-2 renumber
    (output_index + base, sequence_number = events written), merged completed, hand-back
    in round 1 and round 2, truncated rounds, the retain bound, and the buffering fallback for
    a request that may chain.
  • Tests: all eight new splicer tests plus the end-to-end test, both subtests. They cover
    passthrough, withhold + merge, completed/client divergence, the buffered classification,
    hand-back, cut-off rounds, and statelessResponses itself.
  • Docs: no stale claim about Responses streaming; docs/data-dependence.md needs no change
    (transport only, no new stored-data dependence).
  • I did not run builds or tests (not approved). I read the code only.

…sage (#884)

- The 400 retry now turns respSplice off with searchOn and di.
- [DONE] ends a Responses stream: no response.failed follows it.
- The merged usage sums the nested *_details counts and is written even
  when the last round has no usage.
- terminateResponses drops its unused argument.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 replies (fix commit 4be2ff8)

Finding Result
R1 #1 (blocking), R2 non-blocking 1: respSplice stays on after the 400 retry Fixed in 4be2ff8. The retry now sets di, searchOn, respSplice = nil, false, false. New test TestResponsesSearchRetriesOriginalOn400 (/openai/v1/responses, store:false, SSE answer with no terminal event): the retried original reaches the client byte for byte. Mutation: without the reset, the test fails (a response.failed is appended).
data: [DONE] as a terminator Fixed. rewriteResponses sets sp.ended on [DONE]. Test TestResponsesSpliceDoneIsATerminator.
Usage merge Fixed. The nested input_tokens_details and output_tokens_details numbers are summed. The sum is written even when the last round has no usage. Test TestResponsesSpliceSumsUsage (both cases).
terminateResponses unused withheld argument Fixed. The argument is gone. The doc comment says why.
msgStart set only by response.created Not changed. The protocol always sends response.created first. If it is missing, the splicer fails open: bytes go as they came.
ReadSearchesSSE reads Anthropic events only Not changed here. It was already so before #894, and our client search is counted elsewhere. New issue: #895.

Tests on box 2, fresh tar sync: CGO_ENABLED=1 go test -race ./proxy/... ok (508 s). gofmt -l proxy and go vet ./proxy/ clean. git diff --stat origin/main shows only the 4 intended files.

🤖 Generated with Claude Code

…426 (#884)

Codex tries a WebSocket first. The proxy serves HTTP only, and the mux
answered 405, so Codex retried 5 times (~9 s) before it fell back to HTTPS.
426 Upgrade Required makes it fall back at once. Any other GET keeps 405.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

WebSocket fast-fail (commit added to this PR, owner approved)

  • Status picked: 426 Upgrade Required, for GET /openai/v1/responses with Upgrade: websocket. In Codex (core/src/client.rs), only UPGRADE_REQUIRED skips the retries and falls back to HTTPS at once.
  • Timing, live, same fake server: 405 took 9 s to the answer, with a "Falling back" notice after 5 retries. 426 took 1 s, with no retries.
  • Pattern: a GET route on the mux next to the POST route, plain http.Error, as the other routes do. A plain GET still returns 405 with Allow: POST.
  • Test: TestResponsesWebSocketUpgradeGets426. Mutation (426 changed to 405) makes it fail.
  • Tests: CGO_ENABLED=1 go test -race ./proxy/... ok (510 s). gofmt and go vet clean.

🤖 Generated with Claude Code

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 eb0bef701e6e approve

Verdict: approve

Findings

None. My round-1 finding is fixed, and both new commits are clean.

Earlier findings

  1. Mine, round 1: respSplice stays true after the 400 retry — fixed in 4be2ff8. proxy.go:2082 now sets di, searchOn, respSplice = nil, false, false. I traced the retried request through the case ladder: with the flag reset, the SSE answer takes the plain stream-through case and reaches the client untouched. The new TestResponsesSearchRetriesOriginalOn400 pins it — I checked its logic myself: it uses an SSE answer with no terminal event, so without the reset the splicer would append a response.failed and the byte-for-byte assert would fail. Sound test.
  2. Mine, round 1 (non-blocking): [DONE] not a terminator — fixed. rewriteResponses now checks isChatDone first and sets sp.ended (ssepeek.go:745). The event is returned verbatim, so round 1 stays byte-for-byte. TestResponsesSpliceDoneIsATerminator pins it.
  3. Mine, round 1 (non-blocking): merged usage skipped without a usage object — fixed. The sum is now written unconditionally in the merged completed (ssepeek.go:817), and addUsage also sums the nested input_tokens_details / output_tokens_details numbers. TestResponsesSpliceSumsUsage covers both cases; I re-derived its expected numbers (120/10/130, cached 74, reasoning 5; and 100/6/106 without round-2 usage) and they match the sums. Nested paths go through sjson.Set, which creates the objects when the last event has none.
  4. Mine and reviewer 2's (non-blocking): terminateResponses unused argument — fixed. The argument is gone; the comment says why.
  5. Mine, round 1 (non-blocking): msgStart only from response.created — not changed, reason accepted. The protocol always opens with response.created. Without it the splicer fails open: bytes go as they came.
  6. Mine, round 1 (non-blocking, pre-existing): ReadSearchesSSE parses Anthropic events only — not changed here, issue #895 opened. Accepted; it predates this PR.
  7. Reviewer 2 approved round 1 and raised no blocking finding. Their three non-blocking items map to points 1, 3 and 4 above. I checked each myself; all fixed or accepted with a reason I verified.

New commits

  • 4be2ff8 "reset the Responses splice on the 400 retry, sum nested usage" — reviewed in full. The reset is the one-line fix I proposed. The [DONE] check sits before the round filter, so it covers every round. The usage write moved out of the IsObject guard; when the last completed carries a usage object with keys the sum lacks, those keys keep their own values (nothing is zeroed). No new defect.
  • eb0bef7 "answer a WebSocket upgrade on /openai/v1/responses with 426" — reviewed in full. New GET /openai/v1/responses route: 426 for Upgrade: websocket, 405 with Allow: POST otherwise. No route conflict in Mux(); no upstream call and a fixed message, so nothing leaks; a plain GET keeps its old answer. This is a behavior change (405 → 426 for a WebSocket attempt) and it is named, measured (9 s → 1 s to Codex's fallback) and owner-approved in the PR comment. TestResponsesWebSocketUpgradeGets426 covers both branches. I did not verify the codex-rs source claim; the owner approved the pick.

Non-blocking

  • ssepeek.go:745 — the [DONE] check runs before the cheap round-1 prefilter, so every delta now pays a line scan (isChatDone). The chat splicer pays the same. Measured cost only; not worth a change.
  • proxy.go:548 — the 426 test looks at the Upgrade header alone, without Connection: Upgrade. A plain GET with a stray Upgrade: websocket header gets 426 instead of 405. Codex sends both headers, so this cannot misfire in practice.

What I checked

  • Last review: round 1, 14f5db4, 2026-11-04T14:08:48Z
  • New commits read: 2 — 4be2ff8 (fix(proxy): reset the Responses splice on the 400 retry, sum nested usage), eb0bef7 (feat(proxy): answer a WebSocket upgrade on /openai/v1/responses with 426)
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files)
  • New items since my last review: reviewer 2's round-1 review (read in full, its non-blocking items checked against the fixes); the author's reply table (each row checked against the diff); the author's WebSocket comment (owner approval for the behavior change); both new commits (reviewed as a first review: full diff plus the code around each hunk).
  • The fix commit: the reset line, the [DONE] early return and its effect on round-1 byte identity, the nested usage sums (re-derived the test's expected numbers by hand), the unconditional usage write, and the dropped argument with its single caller.
  • The WebSocket commit: route registration against the existing Mux() patterns, auth and leak surface (fixed strings, no upstream), plain-GET behavior, and the test's two branches.
  • The three new tests in ssepeek_responses_test.go: read each, traced what it asserts and what its failure would mean. The 400-retry test's mutation claim (fails without the reset) matches my own trace.
  • The two "not changed" replies (msgStart, ReadSearchesSSE): reasons checked and accepted.
  • CLAUDE.md rules on the new code: fail-open holds (both new paths return fixed responses and revert nothing); the one behavior change is named and owner-approved; no new data dependence; no new exported metrics.
  • I did not run builds or tests (not approved). The author reports go test -race ./proxy/... ok on box 2.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 eb0bef701e approve

Verdict: approve

Findings

None. Both new commits are correct, and every round-1 finding is fixed or answered.

Earlier findings, status

  • R1 reviewer 1, finding 1 (blocking) / my non-blocking 1 — respSplice stayed on after the
    400 retry.
    Fixed in 4be2ff8a. The retry now sets di, searchOn, respSplice = nil, false, false (proxy/proxy.go:2082). I traced the retried round: the splice case no longer matches,
    and a marker-free original falls to the plain SSE stream-through and returns, so the client
    gets the retried stream untouched. TestResponsesSearchRetriesOriginalOn400 pins it with an
    answer that has no terminal event — under the old code the splicer would append a
    response.failed, so the test fails without the fix. Verified the test's own logic, not the
    author's word.
  • My non-blocking 2 / R1 non-blocking — the usage merge was partial. Fixed. addUsage now
    sums the nested input_tokens_details / output_tokens_details numbers (proxy/ssepeek.go:724),
    and the merge writes the sum even when the last round's terminal event has no usage
    (ssepeek.go:815). TestResponsesSpliceSumsUsage covers both cases with real arithmetic
    (120/10/130, cached 74, reasoning 5; and the no-usage case keeps round 1's sums).
  • My non-blocking 3 — terminateResponses took an unused withheld argument. Fixed. The
    argument is gone and the doc comment says why nothing is replayed.
  • R1 non-blocking — data: [DONE] did not end a Responses stream. Fixed.
    rewriteResponses now checks isChatDone first and sets sp.ended (ssepeek.go:745), so no
    response.failed follows a [DONE] terminator. TestResponsesSpliceDoneIsATerminator pins
    the byte-for-byte output.
  • R1 non-blocking — msgStart is set only by response.created. Rejected by the author:
    the protocol always sends response.created first, and a stream without it fails open —
    bytes go as they came, no synthetic event. I checked the reason: it is right. A missing
    created means a non-conformant gateway; adding a synthetic terminator there would guess.
    Accept.
  • R1 non-blocking — ReadSearchesSSE parses Anthropic events only. Deferred to issue #895,
    which I verified exists and is open. Pre-existing, out of scope for this PR. Accept.

What I checked in the new commits

4be2ff8a (fix round 1). The respSplice reset, the [DONE] terminator, the nested usage
sum, and the dropped argument — each traced through pass, forward/rewriteResponses,
terminate, and the merge. Two details I proved rather than assumed:

  1. gjson.ForEach on a missing *_details key does not iterate. No Go on this machine, so
    I proved it from existing tested code: rewriteChat calls d.Get("tool_calls").ForEach on
    every chat chunk (ssepeek.go:622), and its tests pass — if a missing result iterated once,
    sp.blocks would grow on every text chunk and the #879 tests would fail. A scalar or nested
    object inside the details is guarded by v.Type == gjson.Number, and a bad sjson path in
    the merge is skipped by set — fail-open both ways.
  2. The unconditional usage write is safe when usage is absent or null. sjson.Set
    creates the missing object; on an array or a malformed shape it errors and set skips.

eb0bef70 (WebSocket 426). The route is a plain mux handler next to the POST route
(proxy/proxy.go:547). Checked:

  1. No pattern conflict: Go's method-patterned mux keeps GET and POST distinct, and a
    non-websocket GET still gets 405 with Allow: POST, same as the mux's own answer before.
  2. No shadowing: Mux() is mounted directly in cmd/context-guru-proxy/main.go:826, with only
    the optional activity-stamping wrapper, so the 426 reaches every client of this binary.
  3. No data, no auth concern: the handler answers 426/405 only and leaks nothing.
  4. The behavior change is named and has the owner's approval, with live timing (9 s → 1 s), in
    the PR comment of 2026-11-04T14:34:07Z. This satisfies the CLAUDE.md rule that an edge-case
    behavior change needs a human developer's yes.

Non-blocking

None.

What I checked

  • Last review: round 1, 14f5db4, 2026-11-04T14:10:24Z.
  • New commits read: 2 — 4be2ff8a "fix(proxy): reset the Responses splice on the 400 retry,
    sum nested usage (#894)", eb0bef70 "feat(proxy): answer a WebSocket upgrade on
    /openai/v1/responses with 426 (#884)". Full diff of both, plus the code around each hunk:
    Mux(), the retry block in serve, all touched parts of ssepeek.go, and the four new
    tests.
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files).
  • New items since my last review:
    • Commit 4be2ff8a — reviewed above, fixes verified against the code, not the reply table.
    • Commit eb0bef70 — reviewed above, including the mount site and mux semantics.
    • Author reply of 14:22:45 (round-1 fix table) — each row checked; both "not changed"
      rows carry reasons I verified (#895 exists and is open; the response.created fail-open
      reason is sound).
    • Author comment of 14:34:07 (WebSocket fast-fail, owner approval) — checked the route, the
      test, and the approval claim against the CLAUDE.md rule.
  • Tests on the box were run by the author (go test -race ./proxy/... ok, 508 s and 510 s);
    I did not run builds or tests myself (not approved). I read the code only.

@amiddavid
amiddavid merged commit 6460acd into main Nov 4, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 4, 2026
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Summary

Live check of #894 passed for the 426 answer and for stateless streaming with our tool search.

Setup

  • Proxy built from origin/main at dd3cfa6f. Run on the laptop. Upstream: the internal gateway.
  • Check A used preset ultrahigh. Check B added toolfilter always_defer: [lookup_widget_price], because an empty history defers nothing.
  • Model gpt-5.5. Every prompt held a nonce.

A. 426 to a WebSocket upgrade

Step Result
GET /openai/v1/responses with Upgrade: websocket (curl) 426 in 1.5 ms
Codex 0.160.0, supports_websockets = true, seen through a tap GET -> 426 Upgrade Required, then POST -> 200 OK, 1.98 s later
Whole codex exec run 4.7 s to 4.9 s

B. Stateless streaming with our search

Python openai SDK, stream=True, store=False, array input, no tool_search. Two tools. lookup_widget_price was large (1533 tokens) and on always_defer.

Turn Status First delta Last event Response ids response.completed
1: model searches, calls the tool 200 2.96 s (args delta) 3.10 s 1 1
2: tool result, model explains 200 6.62 s (51 text deltas) 9.28 s 1 1
  • Deltas arrive before the end. On turn 2 the first text delta came 2.66 s before response.completed.
  • One response id from response.created to response.completed, on each turn.
  • No 400.
  • Search answered in band. The client saw only the lookup_widget_price call. /stats: decisions 2, add_backs 2, searches 2, retries_400 0.
  • The first try with a string input deferred nothing (input_not_array). That is the documented rule, not a fault.

Notes

  • wrong_guesses is 2 and the ledger net was negative (-$0.009). The test asked for the tool at once, so the deferral had no saving. This is not a defect.
  • Captured bodies, the venv and the throwaway state were deleted.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Stream Responses API answers with our tool search (follow-up to #879)

1 participant