-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Bug: Gemini Context Caching Conflicts with systemInstruction and tools (PR #71441 closed without merge) #84919
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Bug: Gemini Context Caching Conflicts with systemInstruction and tools
Problem
When
cacheRetention: "long"is configured for a Gemini model with tools, the OpenClaw gateway sendscachedContent,systemInstruction, ANDtools/toolConfigin the same request. The Google Gemini API rejects this combination with error 400:Root Cause
The code in
transport-stream-DyvRcab3.js(functionbuildGoogleGenerativeAiParams) sends all fields unconditionally:According to Google's API documentation, when
cachedContentis used, thesystemInstruction,tools, andtoolConfigmust NOT be sent separately — they should already be embedded in the cached content.Previous Work
PR #71441 implemented the correct fix:
usesCachedContentguard before settingsystemInstructionandtools/toolConfigThis means the fix exists but was never applied to the codebase.
Impact
Workaround: Remove
cacheRetentionfrom all Gemini model configs:Cost Impact: Without context caching, users pay 100% of input token costs instead of ~25% (cache read rate). For agents with large system prompts (~35KB), this represents significant cost overhead.
Reproduction
cacheRetention: "long"and toolsEnvironment
cacheRetention: "long"+ agent with toolsRelated
Suggested Fix
Re-open and merge PR #71441, or apply equivalent fix: