Skip to content

fix(google): guard vertex payload wrapper and patch gaxios fetch fallback#33428

Open
smartchainark wants to merge 2 commits intoopenclaw:mainfrom
smartchainark:fix/issue-33392-google-vertex-streamfn-crash
Open

fix(google): guard vertex payload wrapper and patch gaxios fetch fallback#33428
smartchainark wants to merge 2 commits intoopenclaw:mainfrom
smartchainark:fix/issue-33392-google-vertex-streamfn-crash

Conversation

@smartchainark
Copy link

@smartchainark smartchainark commented Mar 3, 2026

Summary

  • Problem: (1) createGoogleThinkingPayloadWrapper applied unconditionally to all providers but only guarded for google-generative-ai, causing Cannot convert undefined or null to object crashes when google-vertex models were used via embedded runner. (2) The gaxios library dynamically imports node-fetch on Node 22+/24+/25 where native globalThis.fetch is available, causing auth-stack crashes in the Google Vertex pipeline.
  • Why it matters: Both issues independently cause hard crashes for any user running google-vertex models, making the Vertex integration unusable on modern Node versions.
  • What changed: (1) The thinking payload wrapper now short-circuits for non-Google API types and applies sanitization to both google-generative-ai and google-vertex. (2) Added a postinstall script (scripts/patch-gaxios-fetch.mjs) that patches gaxios to prefer globalThis.fetch before falling back to node-fetch. (3) Added regression tests for both fixes.
  • What did NOT change (scope boundary): Transient error handling, retry logic, other provider streamFn chains, and the sanitization logic itself are unchanged.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Skills / tool execution
  • Integrations

Linked Issue/PR

User-visible / Behavior Changes

  • Google Vertex models no longer crash with Cannot convert undefined or null to object when used via the embedded runner.
  • The gaxios auth stack no longer fails on Node 22+/24+/25 due to broken node-fetch dynamic import.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22+
  • Model/provider: google-vertex / Gemini 3.1
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Configure a google-vertex model (e.g. gemini-3.1-pro-preview)
  2. Send a message through the embedded runner
  3. Observe the crash in the thinking payload wrapper and/or gaxios auth stack

Expected

Message processes without errors; thinking payload is sanitized correctly for google-vertex.

Actual (before fix)

Cannot convert undefined or null to object crash from either the payload wrapper (spreading undefined options) or the gaxios auth stack (node-fetch import failure).

Evidence

  • Failing test/log before + passing after
 ✓ src/agents/pi-embedded-runner-extraparams.test.ts (49 tests) 6ms
 ✓ src/infra/gaxios-fetch-regression.test.ts (1 test) 9ms

 Test Files  2 passed (2)
      Tests  50 passed (50)

Full suite: 6484+ tests passed.

Human Verification (required)

  • Verified scenarios: Local test suite passes (pnpm build && pnpm check && pnpm test)
  • Edge cases checked: google-vertex with negative thinkingBudget, non-Google API passthrough, gaxios fetch fallback on native-fetch Node
  • What you did not verify: Live integration testing with real Google Vertex API credentials

Note: This PR was created with AI assistance (Claude Code). The code changes have been reviewed and understood.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: git revert <commit-hash>
  • Files/config to restore: src/agents/pi-embedded-runner/extra-params.ts, package.json, remove scripts/patch-gaxios-fetch.mjs
  • Known bad symptoms reviewers should watch for: If the postinstall patch fails silently, gaxios would remain unpatched — symptom is the original auth crash on Node 22+.

Risks and Mitigations

  • Risk: The gaxios postinstall patch modifies built artifacts inside node_modules; future gaxios updates may change the patched code patterns.
  • Mitigation: The patch script detects if the pattern is already fixed or missing and logs the outcome. If gaxios ships a native fix, the patch becomes a no-op.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR fixes a crash in the google-vertex provider by adding a runtime API-type guard inside createGoogleThinkingPayloadWrapper. Previously, the wrapper unconditionally spread options and replaced onPayload for every provider, which could interfere with provider-specific streamFn chains (causing a Cannot convert undefined or null to object crash for google-vertex). The fix makes the wrapper a passthrough for all non-Google API types, and extends the existing sanitizeGoogleThinkingPayload call to cover google-vertex in addition to google-generative-ai, resolving negative thinkingBudget issues for Gemini 3.1 on Vertex AI.

  • The guard (model.api !== "google-generative-ai" && model.api !== "google-vertex") is evaluated at call time, so proxy providers that route to a Google API type are handled correctly.
  • Two targeted tests cover both the new google-vertex sanitization path and the non-Google passthrough.
  • Change scope is minimal: single function in one file, no regressions to google-generative-ai behavior, no changes to sanitizeGoogleThinkingPayload itself.

Confidence Score: 5/5

  • This PR is safe to merge — a focused, well-tested bug fix with minimal scope and no regressions.
  • The change is minimal (a single early-return guard in one function), directly addresses a confirmed crash with google-vertex, preserves all existing google-generative-ai behavior, and is backed by two unit tests covering both the new google-vertex sanitization path and non-Google passthrough. No security, network, or data access patterns are affected. The guard is evaluated at runtime, so proxy providers routing to Google APIs are handled correctly.
  • No files require special attention.

Last reviewed commit: 2ca178a

@cgdusek

This comment was marked as spam.

@smartchainark smartchainark force-pushed the fix/issue-33392-google-vertex-streamfn-crash branch from 2ca178a to d69f2f8 Compare March 4, 2026 07:39
@openclaw-barnacle openclaw-barnacle bot added the scripts Repository scripts label Mar 4, 2026
@smartchainark smartchainark changed the title fix(agents): guard Google thinking payload wrapper for google-vertex API type fix(google): guard vertex payload wrapper and patch gaxios fetch fallback Mar 4, 2026
@smartchainark smartchainark force-pushed the fix/issue-33392-google-vertex-streamfn-crash branch from d69f2f8 to 0557add Compare March 4, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling scripts Repository scripts size: S

Projects

None yet

2 participants