fix(google): omit systemInstruction/tools/toolConfig when cachedContent is used#71441
fix(google): omit systemInstruction/tools/toolConfig when cachedContent is used#71441toshskyline996 wants to merge 1 commit into
Conversation
Greptile SummaryThis PR fixes a Google Generative AI API conflict where Confidence Score: 5/5Safe 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 |
There was a problem hiding this comment.
💡 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".
|
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. |
Problem
When the Google Generative AI transport layer sends a request with
cachedContent, it also sendssystemInstruction,tools, andtoolConfigin the same request body. The Google API rejects this becausecachedContentalready 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 whencachedContentis present and skip settingsystemInstruction,tools, andtoolConfig:src/agents/google-transport-stream.ts: AddusesCachedContentguard before settingsystemInstructionandtools/toolConfigsrc/agents/pi-embedded-runner/google-prompt-cache.ts: Same guard for prompt cache builderTest Changes
systemInstruction,tools,toolConfigshould beundefinedwhencachedContentis presentgoogle-prompt-cache.tsensuring cached content path skips system prompt injectionFiles Changed
src/agents/google-transport-stream.ts— guardsystemInstructionandtoolsbehind!usesCachedContentsrc/agents/google-transport-stream.test.ts— update expectations + new testsrc/agents/pi-embedded-runner/google-prompt-cache.ts— guard system prompt injectionsrc/agents/pi-embedded-runner/google-prompt-cache.test.ts— new test