Skip to content

fix(google): omit systemInstruction/tools/toolConfig when cachedContent is used#71441

Closed
toshskyline996 wants to merge 1 commit into
openclaw:mainfrom
toshskyline996:fix/google-cached-content-conflict
Closed

fix(google): omit systemInstruction/tools/toolConfig when cachedContent is used#71441
toshskyline996 wants to merge 1 commit into
openclaw:mainfrom
toshskyline996:fix/google-cached-content-conflict

Conversation

@toshskyline996

Copy link
Copy Markdown

Problem

When the Google Generative AI transport layer sends a request with cachedContent, it also sends systemInstruction, tools, and toolConfig in the same request body. The Google API rejects this because cachedContent already references a cached context that contains these fields — sending them again causes a conflict error.

This caused the Gemini-based cron job (openclaw cron run) to fail with Google API errors.

Fix

In buildGoogleGenerativeAiParams(), detect when cachedContent is present and skip setting systemInstruction, tools, and toolConfig:

  • src/agents/google-transport-stream.ts: Add usesCachedContent guard before setting systemInstruction and tools/toolConfig
  • src/agents/pi-embedded-runner/google-prompt-cache.ts: Same guard for prompt cache builder

Test Changes

  • Updated existing test expectations: systemInstruction, tools, toolConfig should be undefined when cachedContent is present
  • Added new test case: "omits prompt and tool request settings when cachedContent is used"
  • Added test for google-prompt-cache.ts ensuring cached content path skips system prompt injection

Files Changed

  • src/agents/google-transport-stream.ts — guard systemInstruction and tools behind !usesCachedContent
  • src/agents/google-transport-stream.test.ts — update expectations + new test
  • src/agents/pi-embedded-runner/google-prompt-cache.ts — guard system prompt injection
  • src/agents/pi-embedded-runner/google-prompt-cache.test.ts — new test

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 25, 2026
@greptile-apps

greptile-apps Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Google Generative AI API conflict where systemInstruction, tools, and toolConfig were being sent alongside cachedContent, which the API rejects because the cached context already contains those fields. The fix is applied at two layers: a guard in buildGoogleGenerativeAiParams (for the direct options.cachedContent path) and a payload-patch deletion in google-prompt-cache.ts (for the managed-cache path where cachedContent is injected after the params are built).

Confidence Score: 5/5

Safe to merge — targeted fix with good test coverage across both code paths.

The change is minimal and correctly handles both the direct-options path (guard in buildGoogleGenerativeAiParams) and the managed-cache path (payload-patch deletions in google-prompt-cache.ts). Tests cover the new behavior and verify the deletions explicitly.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(google): omit cached content request..." | Re-trigger Greptile

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

Copy link
Copy Markdown

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: c04c2b79ef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/pi-embedded-runner/google-prompt-cache.ts
@edvisage

Copy link
Copy Markdown

Good catch. Worth flagging the security implication beyond the API compliance fix: if systemInstruction is where a developer has placed access controls, content filters, or behavioral guardrails, silently omitting it when cachedContent is active means those guardrails don't fire for cached responses. A developer who assumes their system instruction applies universally would have no signal that cached sessions are running without it.The fix is correct — omitting incompatible fields rather than letting the API reject them. But the behavioral change deserves explicit documentation: cachedContent sessions run without systemInstruction, tools, and toolConfig. If any of those carry security-relevant logic, developers need to know that cached responses operate in a different trust context than non-cached ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants