You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ai): stop mislabeling gateway errors as "OpenAI" and dumping raw HTML into chat
A gateway run that hit an upstream 502 surfaced, verbatim:
OpenAI API 502: <html> ... <center><h1>502 Bad Gateway</h1></center> ... </html>
Two defects in one line:
1. Mislabeled. The gateway resolves to providerId 'openai' to reuse the OpenAI-
compatible adapter, so streamAgentTurn stamped the error with the OpenAI provider
row's label — even for Opus 5 over LevelCode Cloud. prepProviderRequest already
computes the right label ('LevelCode Cloud'); it was just never threaded past the
provider lookup. Thread req.label through runAgent/turnOpts, doStream, and compact,
and have the router prefer o.label over p.label. BYOK still falls back to the
provider's own label, so an OpenRouter failure still reads "OpenRouter".
2. Raw HTML dumped. The three throw sites appended the raw response body; a proxy 5xx
is an HTML page, not JSON, so the whole nginx document landed in the transcript.
Two pure helpers in openaiCompat: extractApiError() returns a provider's JSON
{error:{message}} when present, '' for an HTML page, and a hard-capped string
otherwise; httpError() composes "<label> API <status>: <detail>", falling back to
the status reason ("Bad Gateway") when there's no usable message, and sets e.status.
The 502 itself is a transient upstream blip we can't fix — this is about surfacing it
honestly. The same failure now reads:
LevelCode Cloud API 502: Bad Gateway
providers.test.js +10 (extractApiError / httpError, incl. the exact nginx body).
Verified end-to-end with a stubbed fetch: the label threads through the real
index.js -> openaiCompat.js chain and BYOK's p.label fallback is intact.
Full gate: 24 suites, 0 failures.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments