Repository navigation
fix(relay): report an untyped SSE error envelope as response.failed #8299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,6 +210,23 @@ function payloadType(payload: string): string | null { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * An untyped `{"error":{...}}` envelope (#8216): not a Responses event, but not a malformed frame | ||
| * either. The SSE relay boundary keeps the error and reports it as `response.failed` at EOF unless a | ||
| * real terminal arrives first, so the pump skips the frame and lets that terminal reach the client. | ||
| * Mirrors the untyped half of `isBareUpstreamErrorEvent` in `relay.ts`. | ||
| */ | ||
| function isUntypedErrorEnvelope(payload: string): boolean { | ||
| try { | ||
| const json = JSON.parse(payload) as unknown; | ||
| if (!json || typeof json !== "object" || Array.isArray(json)) return false; | ||
| const root = json as { type?: unknown; error?: unknown }; | ||
| return root.type === undefined && !!root.error && typeof root.error === "object" && !Array.isArray(root.error); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function terminalStatusFromType(type: string): ResponsesTerminalStatus | null { | ||
| switch (type) { | ||
| case "response.completed": | ||
|
|
@@ -290,6 +307,7 @@ export async function pumpResponsesSseToWebSocket( | |
| /* payload observation must not affect WebSocket delivery */ | ||
| } | ||
| const type = payloadType(payload); | ||
| if (!type && isUntypedErrorEnvelope(payload)) return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (!type) { | ||
| reportTerminal("incomplete"); | ||
| sendProtocolError(ws, 502, "Invalid JSON payload in upstream SSE frame"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.