Skip to content

fix(ai): require explicit endpoints for compatible providers - #130453

Merged
joshavant merged 1 commit into
mainfrom
security/provider-endpoint-fail-closed
Aug 26, 2026
Merged

joshavant merged 1 commit into
mainfrom
security/provider-endpoint-fail-closed

Conversation

@joshavant

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes an issue where an OpenAI-compatible provider with incomplete endpoint metadata could inherit the OpenAI SDK's default endpoint instead of failing closed.

Why This Change Was Made

OpenAI remains allowed to use its SDK default. Every other provider must now supply an explicit base URL before an OpenAI Responses or Completions client is constructed.

The check lives at the shared OpenAI-compatible transport boundary and covers both package and managed Responses/Completions clients. This avoids a provider-specific exception and keeps Azure on its existing dedicated client path.

Alternatives considered:

  • Guard only the configured-model fallback: too narrow, because any malformed runtime model could still reach the SDK constructors.
  • Guard only the fetch wrapper: too late in the lifecycle and incomplete for package consumers that provide their own host fetch implementation.

User Impact

OpenAI-compatible providers with valid configured endpoints continue to work normally. If provider metadata is incomplete, the request now stops with an actionable configuration error before an SDK client or request is created.

Production LOC: +36/-6 (net +30) | Tests: +58/-1

The production growth establishes one explicit endpoint invariant across four existing client constructors.

Evidence

Real behavior proof

Claim: a non-OpenAI provider without an endpoint is rejected before SDK client construction, while the same provider with an explicit endpoint sends only to that configured origin.

Exercised surface: the production createOpenAIResponsesClient boundary using the real installed OpenAI SDK and a local HTTP server. The probe used a sentinel credential; no live provider or real credential was involved.

Environment: local Node runtime, exact commit b48a1d3003456412bdd9a4da6aa11b80c7b9688f.

Command: node --import tsx --input-type=module with an inline production-boundary probe.

Observed terminal output:

{
  "head": "b48a1d3003456412bdd9a4da6aa11b80c7b9688f",
  "missingEndpoint": "blocked before SDK client construction",
  "configuredEndpoint": "request reached only the configured loopback origin",
  "requestPath": "/v1/responses",
  "credential": "sentinel bearer observed only at configured loopback origin"
}

Limits: this proves real SDK construction and HTTP destination binding without contacting an external provider. Model-resolution fallback reachability is covered by source tracing and the regression tests below.

Regression and sibling coverage

  • Pre-fix Responses regression constructed the SDK client without an endpoint; it now fails before construction.
  • Pre-fix Completions parity surfaced an accidental undefined-base-URL error; both package and managed clients now return the same actionable failure.
  • Explicit OpenRouter endpoints remain accepted across Responses and Completions.
  • Focused verification: 84 tests passed across four files.
  • Full changed-file gate passed, including formatting, lint, core and test typechecks, dependency and package-boundary guards, dead-export scans, database guards, and import-cycle checks.
  • git diff --check passed.
  • Local structured review reported no actionable findings.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 6:17 PM ET / 22:17 UTC.

ClawSweeper review

What this changes

The PR rejects non-OpenAI Responses or Completions models with a blank endpoint before creating an OpenAI SDK client, while preserving OpenAI’s SDK-default endpoint behavior.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this maintainer-authored, maintainer-labeled PR open for normal merge review. The shared guard covers the four OpenAI-compatible client constructors and the PR supplies focused terminal proof, but fail-closed endpoint behavior is upgrade-sensitive and needs exact-head current-main/SDK confirmation.

Priority: P2
Reviewed head: b48a1d3003456412bdd9a4da6aa11b80c7b9688f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused boundary coverage and production-boundary terminal proof support a good patch, with upgrade and dependency-contract confirmation still needed before merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body supplies redacted terminal evidence from the production Responses boundary with the installed SDK and a local server: missing metadata is rejected before construction, while an explicit endpoint receives the request.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies redacted terminal evidence from the production Responses boundary with the installed SDK and a local server: missing metadata is rejected before construction, while an explicit endpoint receives the request.
Evidence reviewed 5 items Shared endpoint invariant: The new helper accepts a nonblank endpoint, permits only provider openai to omit one, and otherwise throws before client construction.
All compatible client boundaries: The helper is used by package Responses, package Completions, managed Responses, and managed Completions clients; Azure has its own endpoint-resolution path.
Boundary regression coverage: Tests assert that OpenRouter metadata lacking a base URL produces an error before request payloads or SDK mock configurations are created, while explicit endpoints remain accepted.
Findings None None.
Security None None.

Live Verification

Command: pnpm test packages/ai/src/providers/openai-responses.test.ts

Result: FAIL (partial) — step 2 expect_output fails closed before constructing an OpenAI client for another provider without an endpoint: expected terminal output was not visible within 30 seconds: "fails closed before constructing an OpenAI client for another provider without an endpoint"

$ node --import tsx scripts/test-projects.mts packages/ai/src/providers/openai-responses.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130453-XOObex/target

 ✓  unit  packages/ai/src/providers/openai-responses.test.ts (4 tests) 93ms

 Test Files  1 passed (1)
      Tests  4 passed (4)
   Start at  22:18:35
   Duration  2.09s (transform 1.47s, setup 969ms, import 667ms, tests 93ms, environment 0ms)

[test] passed 1 Vitest shard in 14.87s
$ node --import tsx scripts/test-projects.mts packages/ai/src/providers/openai-responses.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130453-XOObex/target

 ✓  unit  packages/ai/src/providers/openai-responses.test.ts (4 tests) 53ms

 Test Files  1 passed (1)
      Tests  4 passed (4)
   Start at  22:18:51
   Duration  1.14s (transform 475ms, setup 447ms, import 397ms, tests 53ms, environment 0ms)

[test] passed 1 Vitest shard in 13.68s

Assertions:

  • FAIL expect_output: fails closed before constructing an OpenAI client for another provider without an endpoint

How this fits together

OpenClaw’s AI package converts provider model metadata into OpenAI SDK clients for Responses and Completions requests. Those clients carry provider credentials to the configured HTTP endpoint.

flowchart LR
  A[Provider model metadata] --> B[OpenAI-compatible transport]
  B --> C[Endpoint validation]
  C -->|OpenAI| D[SDK default endpoint]
  C -->|Other provider with URL| E[Configured SDK client]
  C -->|Other provider without URL| F[Actionable configuration error]
  E --> G[Provider HTTP endpoint]
Loading

Decision needed

Question Recommendation
Should existing non-OpenAI compatible-provider configurations that resolve to a blank endpoint fail immediately, or need a catalog/config repair path before this guard lands? Validate and land the fail-closed rule: Confirm current provider metadata and supported user configuration cannot legitimately produce a blank non-OpenAI endpoint, then retain the shared guard.

Why: The patch deliberately changes provider routing from SDK fallback to a hard configuration error, so current user configuration and upgrade intent cannot be inferred from the branch alone.

Before merge

  • Resolve merge risk (P1) - Existing compatible-provider configurations whose metadata resolves to a blank endpoint will now stop with an error; confirm those states are intentionally invalid or are repaired before landing.
  • Resolve merge risk (P1) - Current-main/release comparison and direct OpenAI SDK contract inspection were unavailable in this grafted, dependency-less checkout.
  • Complete next step (P2) - The protected maintainer item needs an explicit upgrade-policy choice and exact-head dependency/current-main verification, not an automated repair.
Agent review details

Security

None.

PR surface

Source +30, Tests +57. Total +87 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 36 6 +30
Tests 3 58 1 +57
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 94 7 +87

Review metrics

Metric Value Why it matters
Production vs test delta production +36/-6 (net +30); tests +58/-1 (net +57) The fail-closed invariant adds shared production logic across four client constructors and focused regression coverage.

Stored data model

Persistent data-model change detected: vector/embedding metadata: packages/ai/src/transports/openai-transport-shared.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate compatible-provider upgrades (recommended)
    Check current catalog and persisted provider configurations for blank endpoints, then merge once those states are either impossible or have a supported repair path.
  2. Accept an intentional breaking error
    Land the guard as-is only if maintainers explicitly accept that formerly fallback-dependent configurations must be corrected by operators.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Verify current catalog and upgrade configuration paths cannot leave a non-OpenAI compatible model without an endpoint; inspect the installed OpenAI SDK contract and rerun exact-head focused proof.

Technical review

Best possible solution:

Keep one shared endpoint rule, verify the installed OpenAI SDK and current catalog/config upgrade paths on the exact head, then land only if blank non-OpenAI endpoints are confirmed invalid or have a supported repair path.

Do we have a high-confidence way to reproduce the issue?

No live current-main reproduction was run in this read-only checkout; source shows that an absent endpoint reached each OpenAI SDK constructor before this patch, and the PR body records an after-fix local-server probe.

Is this the best way to solve the issue?

Likely yes: a single shared guard at the client-construction boundary avoids provider-specific bypasses, subject to upgrade-path and installed-SDK confirmation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 86e208310ff2.

Labels

Label changes:

  • add P2: This is a bounded provider-routing hardening change without evidence of a widespread active outage.
  • add merge-risk: 🚨 compatibility: Existing non-OpenAI configurations with absent or blank endpoints now fail before a request is made.
  • add merge-risk: 🚨 auth-provider: The change determines whether a provider credential reaches an OpenAI SDK client and which endpoint it may target.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies redacted terminal evidence from the production Responses boundary with the installed SDK and a local server: missing metadata is rejected before construction, while an explicit endpoint receives the request.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies redacted terminal evidence from the production Responses boundary with the installed SDK and a local server: missing metadata is rejected before construction, while an explicit endpoint receives the request.

Label justifications:

  • P2: This is a bounded provider-routing hardening change without evidence of a widespread active outage.
  • merge-risk: 🚨 compatibility: Existing non-OpenAI configurations with absent or blank endpoints now fail before a request is made.
  • merge-risk: 🚨 auth-provider: The change determines whether a provider credential reaches an OpenAI SDK client and which endpoint it may target.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies redacted terminal evidence from the production Responses boundary with the installed SDK and a local server: missing metadata is rejected before construction, while an explicit endpoint receives the request.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies redacted terminal evidence from the production Responses boundary with the installed SDK and a local server: missing metadata is rejected before construction, while an explicit endpoint receives the request.

Evidence

What I checked:

Likely related people:

  • joshavant: The available grafted history and blame attribute the new endpoint invariant to this commit; broader current-main ownership was unavailable locally. (role: introduced the proposed shared guard; confidence: low; commits: b48a1d300345; files: packages/ai/src/transports/openai-transport-shared.ts, packages/ai/src/transports/openai-completions-transport.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the installed OpenAI SDK’s omitted-base-URL behavior and current-main client inventory on the exact head.
  • Confirm supported catalog and persisted configuration cannot leave a non-OpenAI compatible model with a blank endpoint.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@joshavant
joshavant merged commit 60ea355 into main Aug 26, 2026
133 checks passed
@joshavant
joshavant deleted the security/provider-endpoint-fail-closed branch August 26, 2026 22:30
vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (275 commits)
  fix(ai): require explicit compatible-provider endpoints (#130453)
  test(control-ui): guard the hand-mirrored theme --bg copies (#130444)
  fix(onboard): preserve the saved skills package manager (#130438)
  improve(worker): diagnose admission-deadline failures and widen daemon revalidation budget (#130435)
  fix(plugins): align diffs external install metadata (#130362)
  refactor(models): consolidate config normalization (#130439)
  fix(browser): accept common keyboard aliases (#130401)
  fix(release): refresh IMAP plugin baselines (#130351)
  fix(tests): type sticky model agent fixtures (#130441)
  fix(qa): track current Slack progress cards (#130354)
  feat(ui): refine the mobile composer (#130308)
  fix(ui): clarify gateway disconnect status in tab title (#130364)
  test(qa): await gateway startup before network probes (#130353)
  fix(qa): run Buzz profile scenarios with pooled credentials (#130316)
  fix(crabbox): keep the setup failure reason and name its phase (#130425)
  fix: dashboard tools target the wrong Gateway after admission (#130112)
  fix(ui): distinguish inherited model defaults from session pins (#120805)
  feat(feishu): let agents resend received stickers (#130374)
  refactor(models): prepare selection policy once (#130413)
  fix(ui): make dashboard side panels enter split view (#130426)
  ...

# Conflicts:
#	test/scripts/docker-build-helper.test.ts
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant