fix(google-vertex): strip "<authenticated>" ADC sentinel before provider call#952
Open
BingqingLyu wants to merge 1 commit into
Open
fix(google-vertex): strip "<authenticated>" ADC sentinel before provider call#952BingqingLyu wants to merge 1 commit into
BingqingLyu wants to merge 1 commit into
Conversation
…der call
pi-ai's getEnvApiKey("google-vertex") returns "<authenticated>" sentinel
when ADC env vars are configured. This sentinel flows into the provider
as a literal API key (x-goog-api-key header) → Vertex AI 401.
Fix:
- Wrap registered google-vertex API provider to strip the sentinel
- Return empty apiKey + mode "oauth" from resolveEnvApiKey for ADC
- Allow oauth mode alongside aws-sdk in auth-controller and compact
Closes openclaw#49191
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
b04c838c15e+ pi-ai 0.36.0 upgrade inbce62f8c0fgetEnvApiKey("google-vertex")returns"<authenticated>"sentinel when ADC env vars are configured; this sentinel was being passed as a literal API key (x-goog-api-key: <authenticated>) → Vertex AI 401GoogleAuth→ real OAuth Bearer token)Changes
Core fix: API provider wrapper (
src/agents/custom-api-registry.ts)installGoogleVertexAdcFix()wraps pi-ai's registeredgoogle-vertexAPI provider (bothstreamandstreamSimple) to strip the"<authenticated>"sentinel fromoptions.apiKey. This covers all code paths — stream, streamSimple, compact, branch-summary — because the interception happens at the provider registry level.Called from
discoverModels()insrc/agents/pi-model-discovery.tsso it's applied once before any model is used.Defense-in-depth: openclaw auth resolution (
src/agents/model-auth.ts)resolveEnvApiKey: WhengetEnvApiKey("google-vertex")returns"<authenticated>", return emptyapiKeyinstead of the sentinelresolveApiKeyForProvider: Returnmode: "oauth"for"gcloud adc"source (ADC is OAuth-based, not API-key-based)Skip
setRuntimeApiKeyfor ADC mode (run.ts,compact.ts)Allow
mode === "oauth"(alongside existing"aws-sdk") to skip thesetRuntimeApiKeycall when no literal API key is available — same pattern already used for Amazon Bedrock.Node 25 gaxios compat (
src/infra/gaxios-fetch-compat.ts)Add
globalThis.windowshim to cover both CJS and ESM gaxios builds. The previous prototype-only patch didn't cover the CJS build used bygoogle-auth-library, causingCannot convert undefined or null to objecton Node 25.Why this fix is correct
The
"<authenticated>"sentinel was introduced in pi-ai 0.36.0 as a detection marker for model discovery ("is google-vertex auth configured?"). It was never meant to be used as a literal API key. The ideal fix is upstream in@mariozechner/pi-ai, but until then openclaw needs to intercept the sentinel.The API provider wrapper is the correct interception point because:
AuthStorageTest plan
GOOGLE_APPLICATION_CREDENTIALSSA key generates validya29.c...OAuth token via ADCnode dist/index.js agent --local --message "say hello" --agent greg-privatereturns successful response (was 401 before fix)completeSimplewith same apiKey flow)Closes openclaw#49191
🤖 Generated with Claude Code