Skip to content

feat(llm proxy helpers) expose a readable provider availability error#4080

Merged
St0rmz1 merged 5 commits into
mainfrom
fix/readable-provider-availability-error
Jun 17, 2026
Merged

feat(llm proxy helpers) expose a readable provider availability error#4080
St0rmz1 merged 5 commits into
mainfrom
fix/readable-provider-availability-error

Conversation

@St0rmz1

@St0rmz1 St0rmz1 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

When an OpenRouter request resolves to a model whose only providers are excluded by the org's provider routing settings, OpenRouter returns a raw 404 ("No allowed providers are available for the selected model") that surfaced to users as an opaque "Not Found". This adds a step in the LLM proxy error path that detects that specific response and rewrites it into a structured, actionable error, and teaches the code-review failure classifier to treat it as a known model-availability problem.

Changes

  • Add providerNotAllowedResponse in llm-proxy-helpers.ts. It only acts on OpenRouter 404 responses, validates the upstream body with zod (handling both the bare error shape and the { error: ... } wrapped shape), and returns a provider_not_allowed error with the message "No eligible provider can serve the selected model. Select another model or update the provider routing settings." Other providers and unrelated or malformed 404s pass through unchanged.
  • Wire that check into makeErrorReadable, ahead of the context-overflow check.
  • Classify the new error in code-reviews/action-required.ts and in the code-review-orchestrator.ts orchestrator: both now map provider_not_allowed / "no eligible provider can serve the selected model" to selected_model_unavailable so code reviews fail with an action-required terminal reason instead of a generic error.
  • Add unit tests for makeErrorReadable (bare and wrapped shapes, wrong provider, malformed bodies), the code-review-status route classifier, the action-required classifier, and an orchestrator integration test covering a prepareSession provider-routing failure.

Verification

  • No manual testing. Covered by the added unit and integration tests; run pnpm --filter web test llm-proxy-helpers action-required and the code-review-infra orchestrator suite.

Visual Changes

N/A

Reviewer Notes

The matched upstream message string ("No allowed providers are available for the selected model.") is duplicated as a literal in the zod schema and in the two classifier lists. If OpenRouter changes that wording, all three sites need updating.

@kilo-code-bot

kilo-code-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Safely detects OpenRouter 404 provider availability errors (both flat and {error: {...}} wrapped formats) and transforms them into a user-readable provider_not_allowed response. Schema validation prevents false positives from other providers or malformed responses. The response.clone() usage leaves the original response intact for downstream consumption and retry classification.

Files Reviewed (7 files)
  • apps/web/src/app/api/internal/code-review-status/[reviewId]/route.test.ts
  • apps/web/src/lib/ai-gateway/llm-proxy-helpers.test.ts
  • apps/web/src/lib/ai-gateway/llm-proxy-helpers.ts
  • apps/web/src/lib/code-reviews/action-required.test.ts
  • apps/web/src/lib/code-reviews/action-required.ts
  • services/code-review-infra/src/code-review-orchestrator.ts
  • services/code-review-infra/test/integration/code-review-orchestrator.test.ts

Reviewed by deepseek-v4-pro · 522,381 tokens

Review guidance: REVIEW.md from base branch main

@St0rmz1 St0rmz1 merged commit 69fd96c into main Jun 17, 2026
16 checks passed
@St0rmz1 St0rmz1 deleted the fix/readable-provider-availability-error branch June 17, 2026 18:18
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.

2 participants