Skip to content

fix(providers): centralize Anthropic endpoint classification - #59608

Merged
vincentkoc merged 2 commits into
mainfrom
fix/anthropic-provider-endpoint-classification
Apr 2, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/anthropic-provider-endpoint-classification

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Problem: Anthropic native-host detection for service_tier injection still lived in extensions/anthropic/stream-wrappers.ts, while the shared request-policy engine already owned equivalent native-vs-proxy classification for OpenAI-family and Google-family.
  • Why it matters: provider-local host parsing is easy to drift, and the old Anthropic helper used a loose fallback that could treat Anthropic-looking hosts as native.
  • What changed: added anthropic-public to the shared endpoint classifier in src/agents/provider-attribution.ts, migrated the Anthropic stream wrappers to use that classifier, and added spoofed-host regressions at both the classifier and payload-mutation layers.
  • What did NOT change (scope boundary): this PR does not add Anthropic attribution behavior, does not change missing-baseUrl semantics, and does not broaden request policy beyond endpoint classification for service_tier gating.

Change Type (select all)

  • Bug fix
  • Refactor required for the fix
  • Feature
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause / Regression History (if applicable)

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/provider-attribution.test.ts, src/agents/pi-embedded-runner-extraparams.test.ts
  • Scenario the test should lock in: only native api.anthropic.com endpoints get Anthropic service_tier injection; proxied and spoofed Anthropic-looking hosts do not.
  • Why this is the smallest reliable guardrail: the classifier test pins endpoint resolution, and the payload-mutation test proves the actual user-visible Anthropic behavior stays correct.
  • Existing test that already covers this (if any): proxied Anthropic service_tier non-injection coverage already existed and was extended.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • Anthropic service_tier defaults still apply on native Anthropic endpoints.
  • Anthropic-looking spoofed/custom hosts no longer qualify as native Anthropic endpoints for service_tier injection.

Diagram (if applicable)

Before:
[Anthropic stream wrapper] -> local api.anthropic.com check -> inject service_tier
[shared endpoint policy] -> no Anthropic-native class

After:
[Anthropic stream wrapper] -> shared endpoint classifier -> inject service_tier only on anthropic-public
[shared endpoint policy] -> Anthropic joins the central native-vs-proxy model

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: local Node 25 + pnpm worktree
  • Model/provider: Anthropic message transport
  • Integration/channel (if any): N/A
  • Relevant config (redacted): native vs proxied baseUrl for Anthropic models

Steps

  1. Resolve native and proxied Anthropic endpoints through the shared classifier.
  2. Apply Anthropic fast-mode/service-tier payload mutation against native, proxied, and spoofed Anthropic-looking hosts.
  3. Run focused tests plus pnpm build and pnpm check.

Expected

  • Native api.anthropic.com classifies as anthropic-public.
  • Proxy/custom/spoofed hosts classify as non-native.
  • service_tier injects only on native Anthropic endpoints.

Actual

  • Matches expected.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: shared classifier returns anthropic-public for native Anthropic; Anthropic fast-mode and explicit service-tier injection still work on native hosts; spoofed Anthropic-looking hosts do not get service_tier.
  • Edge cases checked: proxied Anthropic URLs stay non-native; missing baseUrl still preserves prior native-default behavior.
  • What you did not verify: any broader Anthropic auth/header policy beyond service_tier endpoint gating.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk: another provider-specific endpoint class slightly grows the shared enum.
    • Mitigation: this is the intended architecture direction, and the new class is immediately consumed by Anthropic instead of staying dead surface.

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

greptile-apps Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes Anthropic endpoint classification by adding anthropic-public to the shared resolveProviderEndpoint classifier in provider-attribution.ts, then migrating isAnthropicPublicApiBaseUrl in the Anthropic stream wrappers to use it instead of a local hostname check that had a vulnerable includes("api.anthropic.com") substring fallback. The refactor is minimal, correctly scoped, and accompanied by targeted regression tests for both the classifier and the payload-mutation layer.

Confidence Score: 5/5

  • Safe to merge — the change is a tightly scoped refactor that closes a spoofed-host bypass and is fully covered by the new regression tests.
  • All remaining findings are P2 or lower. The core logic is correct: exact hostname matching via resolveProviderEndpoint replaces the prior includes("api.anthropic.com") substring fallback, null/empty-string semantics are preserved by the early returns in isAnthropicPublicApiBaseUrl, and the two new tests directly pin both the classifier and the payload-injection gate.
  • No files require special attention.

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

@vincentkoc
vincentkoc force-pushed the fix/anthropic-provider-endpoint-classification branch from 354b0d7 to a52b3dd Compare April 2, 2026 10:51
@vincentkoc
vincentkoc merged commit d49460b into main Apr 2, 2026
40 of 43 checks passed
@vincentkoc
vincentkoc deleted the fix/anthropic-provider-endpoint-classification branch April 2, 2026 10:54
ngutman pushed a commit that referenced this pull request Apr 3, 2026
* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…w#59608)

* fix(providers): centralize Anthropic endpoint classification

* fix(agents): share Anthropic thinking recovery gating
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: anthropic maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant