From 8a22f0512b168564da4c34f55a5cf55782398692 Mon Sep 17 00:00:00 2001 From: Sergii Demianchuk Date: Sat, 25 Jul 2026 17:08:24 -0400 Subject: [PATCH 1/3] fix(ai): stop mislabeling gateway errors as "OpenAI" and dumping raw HTML into chat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A gateway run that hit an upstream 502 surfaced, verbatim: OpenAI API 502: ...

502 Bad Gateway

... 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 "