Skip to content

fix(providers): centralize Google endpoint classification - #59556

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

vincentkoc merged 3 commits into
mainfrom
fix/google-provider-endpoint-classification

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Problem: Google-family official-host knowledge was still split across provider-specific helpers, while the shared request-policy engine only classified OpenAI-family endpoints.
  • Why it matters: Gemini base URL normalization and Anthropic Vertex region parsing could drift apart from the central native-vs-proxy model, making future proxy/auth/header policy work harder to centralize.
  • What changed: added shared Google-family endpoint classes in src/agents/provider-attribution.ts, exported the minimal classifier seam through openclaw/plugin-sdk/provider-http, and migrated Gemini normalization plus Anthropic Vertex region parsing onto that seam.
  • What did NOT change (scope boundary): this PR does not change hidden attribution behavior, does not add new config surface, and does not yet centralize Anthropic or Copilot endpoint policy.

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, extensions/google/api.test.ts, extensions/anthropic-vertex/region.test.ts, src/infra/google-api-base-url.test.ts
  • Scenario the test should lock in: native Gemini hosts classify separately from Vertex hosts and custom proxies; Vertex region parsing should come from the shared classifier rather than bespoke URL parsing.
  • Why this is the smallest reliable guardrail: these tests pin the shared endpoint seam plus the two provider consumers without needing a full transport-path integration test.
  • Existing test that already covers this (if any): existing Google normalization and Anthropic Vertex region tests were extended.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • Custom/proxied Gemini endpoints continue to avoid official Gemini host normalization.
  • Anthropic Vertex region detection now comes from the shared endpoint classifier, keeping native Vertex endpoints and proxy endpoints distinct.

Diagram (if applicable)

Before:
[Gemini helper] -> parse Google host locally
[Anthropic Vertex helper] -> parse Vertex host locally
[shared request policy] -> knows only OpenAI-family hosts

After:
[Gemini helper] -> shared endpoint classifier -> normalized Gemini base URL
[Anthropic Vertex helper] -> shared endpoint classifier -> Vertex region
[shared request policy] -> one endpoint model for OpenAI-family + Google-family

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: Google Gemini, Anthropic Vertex helper paths
  • Integration/channel (if any): N/A
  • Relevant config (redacted): custom baseUrl vs native Google/Vertex hosts

Steps

  1. Classify native Gemini, regional Vertex, global Vertex, and proxy base URLs through the shared endpoint helper.
  2. Normalize Google API base URLs and resolve Anthropic Vertex regions using that shared classifier.
  3. Run targeted tests plus full pnpm build and pnpm check.

Expected

  • Native Gemini and Vertex hosts classify distinctly; proxy/custom hosts remain custom.
  • Google normalization only applies to native Gemini hosts.
  • Anthropic Vertex region inference only applies to native Vertex hosts.

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 google-generative-ai and google-vertex for native hosts; Gemini normalization still appends /v1beta only for native Gemini; Anthropic Vertex resolves regional/global hosts and ignores proxies.
  • Edge cases checked: malformed/custom URLs stay non-native; global Vertex resolves to global; proxy Gemini/Vertex URLs do not get native classification.
  • What you did not verify: full transport-path integration beyond the covered unit/seam tests; Anthropic public-host service-tier centralization is intentionally deferred.

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: exposing the shared classifier through provider-http broadens the public SDK surface.
    • Mitigation: the seam is minimal, generic, and already backed by full build export verification plus focused tests.

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

greptile-apps Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR centralizes Google-family endpoint classification by introducing resolveProviderEndpoint in src/agents/provider-attribution.ts and exposing it through the openclaw/plugin-sdk/provider-http module. Gemini URL normalization (in both extensions/google/api.ts and src/infra/google-api-base-url.ts) and Anthropic Vertex region parsing now delegate to the shared classifier rather than maintaining their own hostname logic. The refactor is mechanically straightforward and consistently applied across the affected files.

Key observations:

  • The shared classifier correctly distinguishes google-generative-ai, google-vertex (regional and global), and custom/proxy endpoints, backed by unit tests in provider-attribution.test.ts.
  • ProviderAttributionPolicy is not re-exported from provider-http.ts despite being referenced in the exported ProviderRequestPolicyResolution.policy field — this leaves the SDK type surface incomplete for consumers who need to explicitly name that type.
  • src/infra/google-api-base-url.test.ts was listed in the regression test plan but no new Vertex pass-through test case was added to it (unlike its extension counterpart).
  • An unusual bare-block scope { ... } is used in resolveProviderEndpoint to limit the Vertex regex const; a top-level declaration is cleaner.
  • The duplicated normalizeGoogleApiBaseUrl implementation across src/infra/ and extensions/google/ is a pre-existing issue not introduced or consolidated by this PR.

Confidence Score: 4/5

  • Safe to merge with the missing ProviderAttributionPolicy export addressed; no behavioral regressions in tested paths.
  • The refactor is low-risk: it replaces bespoke string matching with a shared classifier using identical logic, and test coverage confirms both Google Generative AI and Vertex classification. The main concern is the incomplete SDK type export (ProviderAttributionPolicy not re-exported while referenced in an exported type), which could cause friction for external SDK consumers. A missing test case in src/infra/google-api-base-url.test.ts is a minor gap. No security surface, auth logic, or transport behavior is changed.
  • src/plugin-sdk/provider-http.ts — type export completeness. src/infra/google-api-base-url.test.ts — missing Vertex pass-through test.

Comments Outside Diff (1)

  1. src/infra/google-api-base-url.ts, line 1-28 (link)

    P2 Vertex URL pass-through not covered in this module's test file

    The PR description lists src/infra/google-api-base-url.test.ts as a target test file for this change, and extensions/google/api.test.ts correctly gains a new assertion verifying that a Vertex host (https://aiplatform.googleapis.com) is passed through unchanged. However, src/infra/google-api-base-url.test.ts has no equivalent test case covering the same scenario for this parallel implementation.

    Since both files implement normalizeGoogleApiBaseUrl identically but independently, adding the same assertion here would pin the behavior and guard against future divergence:

    {
      value: "https://aiplatform.googleapis.com",
      expected: "https://aiplatform.googleapis.com",
    },
    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/infra/google-api-base-url.ts
    Line: 1-28
    
    Comment:
    **Vertex URL pass-through not covered in this module's test file**
    
    The PR description lists `src/infra/google-api-base-url.test.ts` as a target test file for this change, and `extensions/google/api.test.ts` correctly gains a new assertion verifying that a Vertex host (`https://aiplatform.googleapis.com`) is passed through unchanged. However, `src/infra/google-api-base-url.test.ts` has no equivalent test case covering the same scenario for this parallel implementation.
    
    Since both files implement `normalizeGoogleApiBaseUrl` identically but independently, adding the same assertion here would pin the behavior and guard against future divergence:
    
    ```ts
    {
      value: "https://aiplatform.googleapis.com",
      expected: "https://aiplatform.googleapis.com",
    },
    ```
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/plugin-sdk/provider-http.ts
Line: 14-21

Comment:
**`ProviderAttributionPolicy` missing from exported types**

`ProviderRequestPolicyResolution` contains a `policy?: ProviderAttributionPolicy` field, but `ProviderAttributionPolicy` is not included in the re-exports. This creates an incomplete type surface at the SDK boundary: external consumers who receive the resolution object can access `result.policy` through inference, but cannot explicitly name `ProviderAttributionPolicy` without reaching into the internal module path.

Consider adding it to the re-export list:

```suggestion
export type {
  ProviderAttributionPolicy,
  ProviderEndpointClass,
  ProviderEndpointResolution,
  ProviderRequestCapability,
  ProviderRequestPolicyInput,
  ProviderRequestPolicyResolution,
  ProviderRequestTransport,
} from "../agents/provider-attribution.js";
```

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: 170-179

Comment:
**Unusual bare block scope**

Using a bare `{ }` block purely to scope the `const googleVertexHost` is uncommon in TypeScript codebases and can be confusing to readers who might wonder if the block is meaningful (a loop body, condition, etc.). A simple `const` at the same scope level works fine since the variable is only used once and checked immediately after, or alternatively an early-return inline `if`:

```suggestion
  const googleVertexHost = /^([a-z0-9-]+)-aiplatform\.googleapis\.com$/.exec(host);
  if (googleVertexHost) {
    return {
      endpointClass: "google-vertex",
      hostname: host,
      googleVertexRegion: googleVertexHost[1],
    };
  }
```

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/infra/google-api-base-url.ts
Line: 1-28

Comment:
**Vertex URL pass-through not covered in this module's test file**

The PR description lists `src/infra/google-api-base-url.test.ts` as a target test file for this change, and `extensions/google/api.test.ts` correctly gains a new assertion verifying that a Vertex host (`https://aiplatform.googleapis.com`) is passed through unchanged. However, `src/infra/google-api-base-url.test.ts` has no equivalent test case covering the same scenario for this parallel implementation.

Since both files implement `normalizeGoogleApiBaseUrl` identically but independently, adding the same assertion here would pin the behavior and guard against future divergence:

```ts
{
  value: "https://aiplatform.googleapis.com",
  expected: "https://aiplatform.googleapis.com",
},
```

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

Reviews (1): Last reviewed commit: "fix(providers): centralize Google endpoi..." | Re-trigger Greptile

Comment thread src/plugin-sdk/provider-http.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: 4788e90f65

ℹ️ 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

@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: aebd3b24af

ℹ️ 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 0e9a9da into main Apr 2, 2026
41 of 44 checks passed
@vincentkoc
vincentkoc deleted the fix/google-provider-endpoint-classification branch April 2, 2026 10:21
ngutman pushed a commit that referenced this pull request Apr 3, 2026
* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…9556)

* fix(providers): centralize Google endpoint classification

* fix(providers): tighten Google endpoint fallback parsing

* fix(security): harden provider endpoint fallback parsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant