Skip to content

feat(providers): reject unsupported provider×platform pairs (#1009) - #1025

Merged
chaholl merged 1 commit into
mainfrom
feat/reject-unsupported-platform-pairs-1009
Apr 20, 2026
Merged

chaholl merged 1 commit into
mainfrom
feat/reject-unsupported-platform-pairs-1009

Conversation

@chaholl

@chaholl chaholl commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes three fail-fast cells of the provider matrix — combinations
where the hyperscaler does not host the model vendor as a partner
endpoint. These pairs previously would 404 at the wire or silently
route to the wrong URL with the wrong auth; they now fail at provider
construction with a typed, actionable error.

Cell Reason
openai × vertex Vertex AI does not host OpenAI as a partner endpoint
gemini × bedrock AWS Bedrock does not host Google Gemini
gemini × azure Azure AI Foundry does not host Google Gemini

This follows the three real-partner cells already landed —
openai+azure (#1010), gemini+vertex (#1023), claude+vertex (#1024) —
leaving 2 real cells still open in #1009 (claude+azure, openai+bedrock).

Mechanism

  • New UnsupportedProviderPlatformError{ProviderType, Platform} in
    runtime/providers/registry.go, a sibling to the existing
    UnsupportedProviderError for unknown provider types.
  • New RejectPlatforms(rejected, inner) helper that wraps a
    ProviderFactory and short-circuits with the typed error when
    spec.Platform is in the rejected set. Reusable for future cells.
  • openai factory init() wraps with RejectPlatforms{vertex}.
  • gemini factory init() wraps with RejectPlatforms{bedrock, azure}.
  • Existing real pairs (openai+azure, gemini+vertex, claude+bedrock,
    claude+vertex, plus non-platform direct-API paths) fall through
    RejectPlatforms unchanged.

Tests

runtime/providers/reject_platforms_test.go:

  • RejectPlatforms wrapper — rejects listed, allows unlisted+empty,
    error surfaces through errors.As(..., &UnsupportedProviderPlatformError).
  • End-to-end CreateProviderFromSpec rejection for openai+vertex
    and gemini+{bedrock,azure}.

Pre-commit

  • lint: 0 issues
  • coverage on changed files: registry.go 93.5%, openai_tools.go 85.2%,
    gemini_tools.go 88.1% (all ≥80%)

Test plan

  • go test -race -count=1 ./runtime/providers/... ./runtime/providers/claude/... ./runtime/providers/openai/... ./runtime/providers/gemini/... — all green
  • New unit tests exercise each rejection path and the fall-through behaviour
  • Existing openai+azure, gemini+vertex, claude+bedrock, claude+vertex, direct-API tests unaffected

Matrix status after this PR

providerType bedrock vertex azure
claude ✅ ✅ (#1024) ❌ still open
openai ❌ still open ⛔ rejected ✅ (#1010)
gemini ⛔ rejected ✅ (#1023) ⛔ rejected

Refs #1009

Closes the three fail-fast cells of the provider matrix — combinations
where the hyperscaler does not host the model vendor as a partner
endpoint. Previously these pairs would either 404 at the wire or
silently route traffic to the wrong URL with the wrong auth; now they
fail at provider construction with a clear, typed error.

Cells rejected:

- openai × vertex    — Vertex AI does not host OpenAI as a partner
- gemini × bedrock   — AWS Bedrock does not host Gemini
- gemini × azure     — Azure AI Foundry does not host Gemini

Mechanism:

- New `UnsupportedProviderPlatformError{ProviderType, Platform}` in
  runtime/providers/registry.go — sibling to the existing
  `UnsupportedProviderError` for unknown provider types.
- New `RejectPlatforms(rejected, inner)` helper that wraps a
  `ProviderFactory` and short-circuits with the typed error when
  `spec.Platform` is in the rejected set. Reusable for future cells
  we discover aren't offered.
- openai init() wraps its factory to reject `vertex`.
- gemini init() wraps its factory to reject `bedrock` and `azure`.
- Existing real pairs (openai+azure, gemini+vertex, claude+bedrock,
  claude+vertex, plus the non-platform direct-API paths) fall through
  `RejectPlatforms` unchanged.

Tests in reject_platforms_test.go cover:
- RejectPlatforms wrapper: rejects listed, allows unlisted+empty,
  surfaces UnsupportedProviderPlatformError via errors.As.
- End-to-end CreateProviderFromSpec rejection for openai+vertex and
  gemini+{bedrock,azure}.

Refs #1009
@sonarqubecloud

Copy link
Copy Markdown

@chaholl
chaholl merged commit 4e3704a into main Apr 20, 2026
23 checks passed
@chaholl
chaholl deleted the feat/reject-unsupported-platform-pairs-1009 branch April 20, 2026 12:14
chaholl added a commit that referenced this pull request Apr 20, 2026
Adds the AWS Bedrock OpenAI-partner cell (gpt-oss family) to the
provider matrix. 7th cell delivered against #1009 following:
openai+azure (#1010), gemini+vertex (#1023), claude+vertex (#1024),
fail-fast rejections (#1025).

Wire format (verified against live Bedrock us-west-2):

- URL:      {baseURL}/model/{model-id}/invoke  (standard Bedrock invoke)
- Auth:     AWS SigV4 via credentials.AWSCredential
- Request:  OpenAI Chat Completions JSON. Bedrock ignores the model
            field in the body (it routes by URL) so no stripping is
            needed — the existing request builder works as-is.
- Response: standard OpenAI Chat Completions JSON — parsed by the
            existing openAIResponse unmarshal path.

Code structure:

- `bedrockPlatform` constant + `isBedrock()` predicate in openai.go.
- `chatCompletionsURL()` and `responsesURL()` branch for Bedrock:
  the invoke URL path; Responses API falls back to Chat Completions
  (mirrors the existing Azure fallback — neither partner exposes it).
- `NewProviderFromConfig` derives baseURL from PlatformConfig.Region
  via credentials.BedrockEndpoint when BaseURL is empty, forces
  APIModeCompletions, and auto-adds `max_tokens` and `top_p` to
  UnsupportedParams for the Bedrock default set:
    * max_tokens: gpt-oss requires `max_completion_tokens` instead
      (same switch the request builder already flips for o-series).
    * top_p:      gpt-oss rejects 0.0 and the framework default is 0;
      omitting leaves the model default in place.
  Operators can override the full unsupported set via
  ProviderSpec.UnsupportedParams.
- registry.go: api.openai.com/v1 default now skipped for
  Platform=="bedrock" as well as "azure", so the factory's
  PlatformConfig URL derivation is reachable (same root cause as
  #1010).

Streaming (known limitation):

Bedrock's `invoke-with-response-stream` returns binary event-stream
framing with OpenAI-format chunks inside — distinct from the SSE the
rest of the openai stream code expects. Until a dedicated scanner
lands, PredictStream / PredictStreamWithTools run a non-streaming
Predict and emit a single terminal StreamChunk with content +
FinishReason + CostInfo. This is honest (Bedrock's plain `invoke` is
non-streaming) and keeps Arena scenarios with `streaming: true`
compatible.

Tests:

- bedrock_unit_test.go covers predicates, URL builders, factory URL
  derivation, API-mode forcing, unsupported-params auto-detection,
  and that explicit UnsupportedParams overrides Bedrock auto-detect.
- bedrock_integration_test.go (//go:build integration) covers
  URL construction, predict, predict-with-tools, streaming fallback,
  error propagation, and cost calculation against a real Bedrock
  gpt-oss deployment. All 6 pass locally against us-west-2 on the
  omnia-aws profile.

Refs #1009
chaholl added a commit that referenced this pull request Apr 20, 2026
* feat(providers): add openai bedrock code path (#1009 cell)

Adds the AWS Bedrock OpenAI-partner cell (gpt-oss family) to the
provider matrix. 7th cell delivered against #1009 following:
openai+azure (#1010), gemini+vertex (#1023), claude+vertex (#1024),
fail-fast rejections (#1025).

Wire format (verified against live Bedrock us-west-2):

- URL:      {baseURL}/model/{model-id}/invoke  (standard Bedrock invoke)
- Auth:     AWS SigV4 via credentials.AWSCredential
- Request:  OpenAI Chat Completions JSON. Bedrock ignores the model
            field in the body (it routes by URL) so no stripping is
            needed — the existing request builder works as-is.
- Response: standard OpenAI Chat Completions JSON — parsed by the
            existing openAIResponse unmarshal path.

Code structure:

- `bedrockPlatform` constant + `isBedrock()` predicate in openai.go.
- `chatCompletionsURL()` and `responsesURL()` branch for Bedrock:
  the invoke URL path; Responses API falls back to Chat Completions
  (mirrors the existing Azure fallback — neither partner exposes it).
- `NewProviderFromConfig` derives baseURL from PlatformConfig.Region
  via credentials.BedrockEndpoint when BaseURL is empty, forces
  APIModeCompletions, and auto-adds `max_tokens` and `top_p` to
  UnsupportedParams for the Bedrock default set:
    * max_tokens: gpt-oss requires `max_completion_tokens` instead
      (same switch the request builder already flips for o-series).
    * top_p:      gpt-oss rejects 0.0 and the framework default is 0;
      omitting leaves the model default in place.
  Operators can override the full unsupported set via
  ProviderSpec.UnsupportedParams.
- registry.go: api.openai.com/v1 default now skipped for
  Platform=="bedrock" as well as "azure", so the factory's
  PlatformConfig URL derivation is reachable (same root cause as
  #1010).

Streaming (known limitation):

Bedrock's `invoke-with-response-stream` returns binary event-stream
framing with OpenAI-format chunks inside — distinct from the SSE the
rest of the openai stream code expects. Until a dedicated scanner
lands, PredictStream / PredictStreamWithTools run a non-streaming
Predict and emit a single terminal StreamChunk with content +
FinishReason + CostInfo. This is honest (Bedrock's plain `invoke` is
non-streaming) and keeps Arena scenarios with `streaming: true`
compatible.

Tests:

- bedrock_unit_test.go covers predicates, URL builders, factory URL
  derivation, API-mode forcing, unsupported-params auto-detection,
  and that explicit UnsupportedParams overrides Bedrock auto-detect.
- bedrock_integration_test.go (//go:build integration) covers
  URL construction, predict, predict-with-tools, streaming fallback,
  error propagation, and cost calculation against a real Bedrock
  gpt-oss deployment. All 6 pass locally against us-west-2 on the
  omnia-aws profile.

Refs #1009

* test(providers): unit-test bedrock streaming fallbacks for SonarCloud coverage

The bedrock_integration_test.go suite covers the new code path
end-to-end against real AWS Bedrock, but build-tag `integration` is
not run in CI so SonarCloud sees the predictStreamBedrockFallback and
predictStreamWithToolsBedrockFallback bodies as uncovered (new_coverage
41.4% < 80% threshold).

Adds httptest-based unit tests that mock the Bedrock invoke endpoint
with canned OpenAI Chat Completions JSON and exercise:

- PredictStream Bedrock path: emits exactly one terminal chunk with
  Content/Delta/FinishReason=stop/CostInfo populated.
- PredictStream Bedrock error: 4xx upstream surfaces as error from
  the streaming entrypoint.
- PredictStreamWithTools Bedrock path: emits exactly one terminal
  chunk with ToolCalls populated and FinishReason=tool_calls.
- PredictStreamWithTools Bedrock error: 5xx upstream surfaces as
  error.

No production code changes.
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.

1 participant