fix(ai): keep per-provider failures when every chat route fails - #3836
Merged
Salazareo merged 1 commit intoSep 9, 2026
Conversation
When the chat fallback chain is exhausted, the driver already records each attempt (model, provider, status, code, message, timeout) in the error's `fields.attempts`, but the alarm keyed on the classified message alone and the alarm client printed the error at inspect depth 2, so the log and Slack line read `internal_error:All providers failed` with nothing about which providers failed or why. Deduped repeats printed only a count. - The HTTP alarm gate now attaches an HttpError's `fields` to the alarm under a single `details` key. One key can't shadow the gate's own request fields, and a repeat from another thrower on a shared id replaces it instead of merging into it. - The chat driver logs one warn line per exhausted chain with the completion id, the resolved route, the classified code and the attempts as JSON, so every occurrence is greppable by trace even when the alarm dedupes it. Chains marked `noAlarm` don't log. - Docs: `fields` reaches both the client and the alarm, so it has to be safe to show the caller. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
404oops
marked this pull request as ready for review
September 9, 2026 16:05
404oops
requested review from
ProgrammerIn-wonderland,
Salazareo and
reynaldichernando
as code owners
September 9, 2026 16:05
ProgrammerIn-wonderland
approved these changes
Sep 9, 2026
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
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.
TL;DR
When the chat fallback chain exhausts every provider, the alarm and log line read
internal_error:All providers failedand nothing else, even though the driver already records each attempt's model, provider, status, code and message in the error'sfields.attempts. This PR carries that detail into the alarm and adds one log line per exhausted chain, so an occurrence says which providers failed and how. 91 tests pass across the three touched suites; typecheck, ESLint and Prettier are clean on the source files.Closes PUT-1615.
Why
The per-provider detail has existed since #3123, but it was dropped on the way to the operator:
legacyCode:messageonly, on purpose, so repeats dedupe into one incident.inspectstops at depth 2, so the log showsfields: { attempts: [ [Object], [Object] ] }.errorfield in favour of the stack trace, which contains only the message.What changed
src/backend/server.ts): anHttpError'sfieldsare attached to the alarm under a singledetailskey. One key cannot shadow the gate's own request fields, and because the alarm client merges fields on repeat, a repeat from a different thrower on a shared id (the forced 4xx codes are shared across drivers) replaces the previousdetailsinstead of leaving stale keys beside it. Slack, PagerDutycustom_detailsand the occurrence history all receive it.ChatCompletionDriver.ts): oneconsole.warnper exhausted chain with the completion id, the resolvedprovider:model, the classified code and the attempts as JSON. The JSON console wrapper stamps the trace id on it, so every occurrence is greppable even when the alarm dedupes it. Chains the classifier marksnoAlarm(a free model throttled upstream) do not log, for the same reason they do not alarm.fieldsoption onHttpErroranddoc/alarms.mdnow say thatfieldsreaches both the client response body and the alarm, so it has to be safe to show the caller.Verification
vitestonserver.test.ts,ChatCompletionDriver.test.ts,ChatCompletionDriver.edges.test.ts: 91 passed.HttpErrorwhosefieldsreuse the gate's own key names and asserts they land underdetailswhile the HTTP status and error object stay intact; the other throws a plainErrorand asserts the same alarm id shape with nodetails. The driver test asserts the log line's prefix, route and serialized attempts; the existing free-model rate-limit test asserts no line is written.npm run typecheck: no new errors. ESLint and Prettier: clean on the changed source files. (doc/alarms.mdfails Prettier on five pre-existing*italics*lines outside this diff; left alone.)Not in this PR
attempts[].erroris the raw upstream message and is unbounded; an SDK error embedding an HTML 502 page yields a large line. This predates the PR and also reaches the response body; capping it intoAttemptvia the existingsanitizeUpstreamMessagewould change what clients receive, so it deserves its own change.critical, but connection resets andfetch failederrors land there too. Once this PR surfaces the attempts, most of the 34 reported occurrences will likely turn out to be that case. Reclassifying them is a separate alerting-behaviour change.Reviewer callouts
HttpErrorwithfieldsnow carries adetailsentry in Slack and PagerDuty. Nothing new reaches clients;fieldswas already serialized into the response body.🤖 Generated with Claude Code