Skip to content

refactor(providers): centralize request attribution policy - #59433

Merged
vincentkoc merged 7 commits into
openclaw:mainfrom
vincentkoc:fix/provider-request-policy
Apr 2, 2026
Merged

vincentkoc merged 7 commits into
openclaw:mainfrom
vincentkoc:fix/provider-request-policy

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • centralize request-time provider attribution and endpoint classification in one policy layer
  • route OpenAI stream, websocket, shared media HTTP, and OpenRouter default headers through that policy
  • add matrix coverage for native vs proxy/self-hosted attribution behavior across transports

Testing

  • pnpm check
  • pnpm build
  • pnpm test -- src/agents/provider-attribution.test.ts src/agents/openai-ws-connection.test.ts src/agents/pi-embedded-runner/extra-params.openai.test.ts src/media-understanding/openai-compatible-audio.test.ts

Notes

  • OpenRouter behavior is intentionally unchanged in this pass; it is modeled in the same classifier so future host-gating can reuse the same seam.
  • extensions/openai/media-understanding-provider.test.ts timed out in the extension lane locally, so the new audio-path coverage lives at the shared helper layer instead.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: openai labels Apr 2, 2026
@vincentkoc vincentkoc self-assigned this Apr 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Apr 2, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review April 2, 2026 04:59
@greptile-apps

greptile-apps Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes provider attribution and endpoint classification into a single resolveProviderRequestPolicy / resolveProviderRequestAttributionHeaders layer, replacing four inline URL-detection helpers across the OpenAI stream, WebSocket, and audio paths. The refactor is well-structured and the new tests give good matrix coverage. Two areas worth confirming before merge:

  • The capability === "audio" branch in the attributionProvider condition bypasses the API allowlist entirely — any API string satisfies the condition, so tightening it to also require api === "openai-audio-transcriptions" would be safer.
  • usesExplicitProxyLikeEndpoint explicitly exempts OpenRouter endpoints, silently reversing the old shouldStripResponsesPromptCache behavior for models configured with provider: "openrouter" and api: "openai-responses" (they would no longer have prompt_cache_key/prompt_cache_retention stripped).

Confidence Score: 5/5

  • Safe to merge; all findings are P2 confirmations or style suggestions with no current production breakage.
  • Both open findings are P2: a subtle behavioral change in prompt-cache stripping for an unlikely OpenRouter+openai-responses configuration, and an overly broad audio capability bypass in the attribution gate. Neither causes a current runtime error. The core logic is sound, host verification is correct, and test coverage is meaningful.
  • src/agents/provider-attribution.ts — the attributionProvider condition (audio capability bypass) and the usesExplicitProxyLikeEndpoint OpenRouter exemption.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/provider-attribution.ts
Line: 334-335

Comment:
**OpenRouter silently removed from proxy-like classification**

`usesExplicitProxyLikeEndpoint` explicitly excludes `endpointClass !== "openrouter"`, but the old `isDirectOpenAIBaseUrl` treated openrouter.ai as proxy-like (it only whitelisted `api.openai.com`, `chatgpt.com`, and `*.openai.azure.com`). `shouldStripResponsesPromptCache` relied on that flag, so OpenRouter-hosted models with `api: "openai-responses"` will no longer have `prompt_cache_key`/`prompt_cache_retention` stripped — a subtle reversal from prior behavior. The PR description says "OpenRouter behavior is intentionally unchanged in this pass," so this is worth confirming is deliberate.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/provider-attribution.ts
Line: 338-344

Comment:
**`capability === "audio"` bypasses the API allowlist entirely**

When `input.capability === "audio"`, the `api` value is completely ignored — any API string (or no API at all) will satisfy the condition and trigger OpenAI attribution headers. If a caller mistakenly sets `provider: "openai"`, `capability: "audio"`, and an unrelated API string (e.g. `"openai-completions"`) with `api.openai.com` as the base URL, hidden attribution headers would still be injected. Tightening the OR to a dedicated capability branch (i.e. checking for both `api === "openai-audio-transcriptions"` and `capability === "audio"`) would make the gate explicit.

```typescript
if (
  provider === "openai" &&
  (api === "openai-completions" ||
    api === "openai-responses" ||
    (input.capability === "audio" && api === "openai-audio-transcriptions")) &&
  usesOpenAIPublicAttributionHost
) {
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/proxy-stream-wrappers.ts
Line: 114-120

Comment:
**OpenRouter attribution applies on non-OpenRouter base URLs**

Because `resolveProviderRequestPolicy` sets `attributionProvider = "openrouter"` solely based on `provider === "openrouter" && policy?.enabledByDefault` — with no endpoint-class check — the OpenRouter attribution headers (`HTTP-Referer`, `X-OpenRouter-Title`, `X-OpenRouter-Categories`) are also injected when a user configures `provider: "openrouter"` with a custom proxy `baseUrl`. The PR notes this is intentionally deferred, but it's worth a comment in the code since a user routing through `provider: "openrouter"` against their own proxy will silently receive OpenRouter-branded headers on every request.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/provider-re..." | Re-trigger Greptile

Comment thread src/agents/provider-attribution.ts Resolved
Comment thread src/agents/provider-attribution.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28aa1693b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/provider-attribution.ts Resolved
@vincentkoc
vincentkoc merged commit 1a037ff into openclaw:main Apr 2, 2026
26 of 27 checks passed
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…59433)

* refactor(providers): centralize request attribution policy

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* style(providers): normalize request policy formatting

* docs(changelog): note provider request policy fix

* fix(providers): tighten request policy gates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: openai maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant