Skip to content

fix(relay): normalize bifrost errors, remap credential 404, fix analytics - #10797

Merged
diegosouzapw merged 4 commits into
release/v3.8.50from
fix/10785-relay-bifrost-recreated
Aug 20, 2026
Merged

diegosouzapw merged 4 commits into
release/v3.8.50from
fix/10785-relay-bifrost-recreated

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Recreated from #10785 (OPX-Aminul) — the fork's push access was not available for the mandatory pre-merge fix, so this branch was cut fresh from release/v3.8.50 and carries the original commit unmodified plus the required follow-up fix on top.

Originally-proposed-by: @OPX-Aminul in #10785

What this does

  • Normalizes Bifrost provider errors (plain-text 404, HTML 502) into structured JSON error responses.
  • Remaps credential 404s.
  • Fixes analytics recording for upstream error paths.
  • Follow-up fix (mandatory pre-merge item from analysis): strips stale upstream content-length/content-encoding/transfer-encoding headers before serializing the JSON error body, so the response headers don't lie about the freshly-serialized body's real size/encoding — with a regression test that mocks a real upstream Response carrying those headers.

Test plan

  • node --import tsx/esm --test tests/unit/api/v1/relay-completions-errors.test.ts — 4/4 pass
  • npm run typecheck:core — clean
  • npx eslint on touched files — clean

MonkeyCode-AI and others added 2 commits August 19, 2026 21:26
…tics

- Normalize non-OK Bifrost upstream responses through parseUpstreamError +
  buildErrorBody/sanitizeErrorMessage so plain-text/HTML errors are wrapped
  into valid OpenAI JSON instead of leaking raw bodies (invalid character 'd').
- handleNoCredentials() now takes an isCombo flag: single-model requests
  remap the combo 404 to 401/503 so direct clients no longer see a misleading
  'No active credentials' 404. Combo routing keeps 404 for fall-through.
- recordUsage() now records any non-2xx upstream status as 'error' rather
  than 'success' (was status < 500), fixing 4xx analytics misclassification.

Adds/updates tests covering all three scenarios.
…sponse

The new !upstream.ok error path copies upstream.headers (which can carry a
content-length/content-encoding/transfer-encoding for the ORIGINAL upstream
body) onto the freshly re-serialized JSON error Response, causing a
byte-length mismatch. Route the headers through stripStaleEncodingHeaders()
before serializing the error body, and add a regression test that mocks an
upstream Response with an explicit content-length header.

Co-authored-by: OPX-Aminul <305739020+OPX-Aminul@users.noreply.github.com>
diegosouzapw added a commit that referenced this pull request Aug 20, 2026
…10797) + pre-existing chatBodyAdmission.ts drift

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
giauphan pushed a commit to giauphan/OmniRoute that referenced this pull request Aug 20, 2026
…zapw#10722, diegosouzapw#10797) + pre-existing chatBodyAdmission.ts drift

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
hartmark and others added 2 commits August 20, 2026 06:32
…del requests

This PR's own handleNoCredentials change remaps the leaked combo-fallback 404 to
401 for non-combo (single-model) requests, but left 5 pre-existing tests
asserting the old 404 for exactly that single-model path:
vscode-token-routes.test.ts (both routes), chat-route-coverage.test.ts,
chat-pipeline.test.ts (both cases), combo-routing-e2e.test.ts (unmapped-model
case), llama-cpp-provider.test.ts. Combo-routing tests that legitimately expect
404 (isCombo=true fall-through) are untouched.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit bc6129b into release/v3.8.50 Aug 20, 2026
6 of 8 checks passed
backryun added a commit to backryun/OmniRoute that referenced this pull request Aug 21, 2026
…souzapw#10797

diegosouzapw#10797 (bc6129b) remapped credential-lookup misses for unknown
providers from 404 to 401, so the preserve-mode fall-through request in
chat-previous-response-id-preserve-mode.test.ts now returns 401 instead
of 404. The assertion's real contract — the error is NOT the
virtualization's previous_response_not_found rejection — is unchanged;
only the expected status moves with the remap. 2/2 green.
backryun added a commit to backryun/OmniRoute that referenced this pull request Aug 21, 2026


diegosouzapw#10797 (bc6129b) remapped credential-lookup misses for unknown
providers from 404 to 401. The two schema-pass-through assertions in
chat-early-schema-validation-6412.test.ts still expected the old 404;
their real contract (schema validation runs first, provider lookup
after, no false 400) is unchanged. 7/7 green.
backryun added a commit to backryun/OmniRoute that referenced this pull request Aug 21, 2026
…souzapw#10797

diegosouzapw#10797 (bc6129b) remapped credential-lookup misses for unknown
providers from 404 to 401, so the preserve-mode fall-through request in
chat-previous-response-id-preserve-mode.test.ts now returns 401 instead
of 404. The assertion's real contract — the error is NOT the
virtualization's previous_response_not_found rejection — is unchanged;
only the expected status moves with the remap. 2/2 green.
backryun added a commit to backryun/OmniRoute that referenced this pull request Aug 21, 2026


diegosouzapw#10797 (bc6129b) remapped credential-lookup misses for unknown
providers from 404 to 401. The two schema-pass-through assertions in
chat-early-schema-validation-6412.test.ts still expected the old 404;
their real contract (schema validation runs first, provider lookup
after, no false 400) is unchanged. 7/7 green.
@diegosouzapw
diegosouzapw deleted the fix/10785-relay-bifrost-recreated branch August 21, 2026 15:33
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…zapw#10722, diegosouzapw#10797) + pre-existing chatBodyAdmission.ts drift

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…tics (diegosouzapw#10797)

Merged — the 5 pre-existing tests that broke from this PR's intentional 404→401 remap (single-model no-credentials) are now realigned to the new contract. Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants