fix(pixel-relay): return 502 bad gateway when upstream model router is unavailable - #5605
Open
vaibhavsrv wants to merge 1 commit into
Open
vaibhavsrv wants to merge 1 commit into
vaibhavsrv wants to merge 1 commit into
Conversation
This was referenced Sep 17, 2026
vaibhavsrv
force-pushed
the
fix/pixel-relay-upstream-502
branch
from
September 17, 2026 04:08
ef21605 to
762bfe7
Compare
vaibhavsrv
force-pushed
the
fix/pixel-relay-upstream-502
branch
from
September 17, 2026 04:25
762bfe7 to
81f6b4d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this matters
When Pixel agent forwards chat or model discovery requests to the internal model router through
ods/extensions/services/pixel-model-relay/relay.py, an unavailable, terminating, or restartingmodel-routercontainer causesupstream_taskto raise an uncaughtaiohttp.ClientConnectorError(orClientError/OSError/TimeoutError). Because the reverse proxy endpoint_inferenceinrelay.pyevaluatedupstream = await upstream_taskwithout connection error handling, transport failures bubble up to the aiohttp framework, resulting in an unhandled HTTP 500 "Server got itself in trouble" error rather than a structured HTTP 502 Bad Gateway response. Additionally, sendingdata=bodyon GET requests (such as/v1/models) passes an empty string body with a forced JSON content-type header, which can break upstream endpoints expecting clean GET requests.This fix surgically guards
await upstream_taskin_inferenceagainst(ClientError, OSError, asyncio.TimeoutError)and returns a standardized JSON 502 Bad Gateway payload ({"error": {"message": "upstream model router unavailable", "type": "bad_gateway", "code": "502"}}). It also sanitizes GET requests to avoid sending empty request bodies, and cleanly catches client errors during chunk consumption. Existing routing, authentication, authorization checks, and stream piping semantics remain untouched.Validation
relay.UPSTREAMto an unreachable port raised unhandledClientConnectorErrorinside_inference, failing with HTTP 500 Internal Server Error (500 != 502)./v1/chat/completionsand/v1/modelsagainst an unreachable upstream cleanly return HTTP 502 Bad Gateway with standard JSON error payload."[Pixel-model-relay] suites: 2 passed. New-test Ruff, ShellCheck, and diff checks pass; new regressions wired into Linux CI."Overlap check
fix(pixel-edge): accumulate content before finish reason in stream fallback guard): Focused on edge runtime chunk buffering and fallback finish reasoning; no overlap with reverse proxy upstream connection handling inpixel-model-relay.fix(pixel): guard task group exception groups during stream revocation cleanup): Touches agent stream revocation inpixel-agent; does not modifypixel-model-relaytransport or error mapping.codex/portal-public-beta-integration): Introducedpixel-model-relay; this patch directly hardens its upstream error boundaries without conflicting with any ongoing portal integration work.Risk / AI disclosure
AI-assisted investigation, implementation and CLI regressions. This strengthens reverse proxy upstream connection error handling, not runtime admission. Independent human review and platform/runtime qualification remain gates. No running configuration, deployment or upstream merge changed.
Follow-up integration evidence
Composed with #5604 at 8e30bba without conflicts. Production and test diffs passed together; pixel model relay checks remain intact.
Backlog composition was local-only (production/test diffs, excluding workflow/Makefile wiring); it is not an upstream merge or independent human approval. Declared live-review gates remain open.