Repository navigation
Read the Responses event type from the SSE event field - #8608
Conversation
#8511 added response_event_type(), which raises when neither the JSON nor the SSE name carries a type. The external-provider Responses loop discarded `event:` lines outright and passed only the parsed object, so a standard `event: response.completed` + `data: {}` frame raised and killed the whole completion. Both failing suites are red on main today. Two changes: keep the SSE name and pass it, and skip a frame whose type still cannot be determined instead of failing the stream. An OpenAI-compatible endpoint behind this base URL can answer a Responses request with Chat Completions frames, which is what the second failing test serves; skipping is the pre-existing behaviour. The ChatGPT path keeps raising, where the wire shape is guaranteed.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c00d608686
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # behaviour and beats failing the whole completion; the | ||
| # ChatGPT path stays strict, where the shape is guaranteed. | ||
| sse_event_name = "" | ||
| continue |
There was a problem hiding this comment.
Preserve Chat Completions frames instead of discarding them
When an OpenAI-compatible base URL responds to the Responses request with Chat Completions SSE, every content frame has choices but no Responses type, so this handler discards every token and eventually forwards only [DONE], presenting a successful but empty assistant response. The compatibility scenario described here therefore needs to forward or translate the Chat Completions frames rather than merely swallowing the validation error; the existing test at test_external_provider_usage_chunk.py:564-589 exercises exactly this response shape but never asserts that "ok" survives.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. Two points:
-
The empty-response behaviour is pre-existing, not introduced here. Before Unsloth Studio: add ChatGPT subscription chat with Codex tools #8511 the loop read
event_type = event.get("type")and every branch below is anif event_type == ..., so a Chat Completions frame already fell through and was dropped. This PR restores exactly that; Unsloth Studio: add ChatGPT subscription chat with Codex tools #8511 turned the drop into aValueErrorthat killed the stream instead. -
The cited test at test_external_provider_usage_chunk.py:564-589 is
test_streamed_usage_is_requested_only_where_documented, which drivesstream_chat_completion, andopenaiis deliberately absent from its parametrization, so it never reaches the Responses handler.
Translating Chat Completions frames inside the Responses loop, or detecting the shape and re-routing, is a separate feature and a bigger change than a red-suite fix should carry. Filed as follow-up work.
An event name applies to its own event only. A named event whose data line is empty or unparseable left the name set, so the next data-only frame inherited it: a stale response.failed turned that frame into a 502 and broke the stream. Clearing at the blank-line delimiter is the single place an event can end, so the two per-frame resets go away.
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Cross-check, because this PR and the other one each fix half of the same main-wide red and neither can go green on its own. #8590's own CI still shows the Applied both on top of Running the exact tests that are red across the repo: 103 passed. For the record, the third family seen on some boards is not part of this: Together these unblock #8440, #8489, #8496, #8500, #8548 and #8576, which are all red only on this shared set. They should land as a pair. |
|
Cross-platform CI and a real before/after run, plus one correction to how this PR should be described. Cross-OSReplicated onto a staging repo so the org queue is spared, and run on the OS triple. I read the logs rather than trusting the green, because the generated per-OS jobs treat pytest exit 5 ("no tests ran") as a pass, which is exactly how a job goes vacuously green:
Real pass counts on all three, so these are genuine gates. Before/after, two isolated installsBEFORE is the merge base What the two servers logged:
Visually: both sides carry the same model chip and the same prompt. BEFORE shows a "Generation failed / An internal error occurred" toast and a red error bubble with Retry where the assistant reply belongs. AFTER shows the completed reply at 1.60s. The stub's output carries a marker token specifically so a locally loaded model answering the same question could not be mistaken for a pass. A scripted reproduction driving the real BrowsersSame scene on both sides, five browsers, with the BEFORE column as the control:
5/5 fail before, 5/5 pass after. The control column is what makes this the backend fix rather than a browser quirk. Safari proper is not covered and I am not claiming it: WebKit is Safari's engine, not Safari, and Safari needs macOS. Correction to the framing
Gaps, stated plainlyStaging runners are GPU-less, and the per-OS jobs scope to this PR's own test files rather than the full backend suite. The staging Playwright job is not a gate (its smoke step is |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
CI status, since the red checks here are not this PR's. Measured on main's own Backend CI at This PR clears the Responses family completely. The 8 that remain here are the GGUF family, which #8635 fixes. #8635 shows the mirror image: 0 GGUF failures, and the same 2 Responses failures this PR removes. So the two are complementary and mutually blocking. Merging both should take Backend CI to zero. The |
* Surface an untyped error frame instead of skipping it #8608 made the Responses reader skip a frame it cannot type, which is right for the case it was written for: an OpenAI-compatible endpoint behind a Responses base URL answering with Chat Completions chunks. An error payload is the exception. The bare {"error": {...}} such a proxy emits mid-stream carries no type and no SSE event name either, so it took the same path, and the generation ended with zero chunks and nothing to explain it -- a blank answer where the endpoint had said "rate limited". Measured on main: 0 chunks returned, no mention of the error. Before the skip existed that frame raised, which was at least loud. This says what happened instead, through the same _error_sse_line the typed response.failed and error events already use. A frame with no type, no event name and no error key is still skipped. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Check the frame is an object before reading its error field data: null and data: [] are valid JSON and not dicts. response_event_type rejects them, and the error check that followed then called .get() on them, which raised AttributeError and killed the stream -- the exact failure the skip exists to avoid. Guard on the type first. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Shorten the comments on the untyped error frame path --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Two suites are red on
origin/maintoday, and every open PR inherits them:response_event_type()arrived with #8511 and raises when neither the JSON object nor the SSE event name carries a type. It takes the event name as its second argument for exactly that reason, andopenai_codex_client.pypasses it. The external-provider Responses loop did not: it discardedevent:lines outright and then passed only the parsed object, so a perfectly standard frameraised and killed the whole completion.
Two changes:
response_event_type(). The Responses API puts the type there and need not repeat it in the data object.Verification, and one part worth reading:
test_other_providers_do_not_get_the_continuation_flags.event: response.completedframe is silently dropped and its usage never surfaces.test_a_type_carried_only_by_the_sse_event_field_is_honourednow pins it by asserting the usage chunk appears, and reverting change 1 fails it.dicewaregap and the fourth is the routes-stub drift covered by Fix the desktop-auth routes stub so the health test runs again #8590.