Repository navigation
fix(agents): continue uncached when Google prompt-cache responses fail - #124479
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:48 AM ET / 12:48 UTC. ClawSweeper reviewWhat this changesThe PR makes automatic Google prompt-cache create and refresh failures continue through normal uncached generation, with validation and lifecycle regression coverage. Merge readinessThis PR remains necessary and appears correct: current main still lets a malformed successful cache response abort before generation, while the introduced cache-owner path degrades to uncached generation and preserves cancellation and transcript authority failures. Priority: P1 Review scores
Verification
How this fits togetherGoogle prompt caching is an optional embedded-agent optimization that prepares a cache reference before a Gemini generation request. A valid reference lets the Google transport omit duplicated prompt/tool payloads; an unavailable reference must leave the original generation request intact. flowchart LR
A[Embedded Gemini run] --> B[Prompt cache lifecycle]
B --> C[Create or refresh cache]
C --> D{Valid cache metadata?}
D -->|Yes| E[Generation with cached prompt]
D -->|No| F[Generation with original prompt and tools]
E --> G[Visible model output]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +176, Tests +494, Other 0. Total +670 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep the cache failure policy at this lifecycle owner: validate metadata before suppressing the live prompt and tools, then merge once the exact-head required checks complete. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main awaits successful cache-response parsing before the uncached branch, so malformed metadata prevents the original stream from running; the introduced owner suite directly exercises that path. Is this the best way to solve the issue? Yes. The repair handles failure at the optional cache lifecycle owner and preserves the downstream transport's existing invariant that prompt/tools are omitted only with a validated cache reference. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f15d42998254. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
1b77c6f to
7fd8c4b
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
7fd8c4b to
ebd3b91
Compare
Co-authored-by: coaiMax <[email protected]>
ebd3b91 to
d911810
Compare
|
ClawSweeper disposition for the August 30 review on
Contract basis: Google publishes the resource shape as
Production is +101/-99 (net +2); tests/support are +849/-182. Exact-commit Codex and independent Claude autoreviews found no P0/P1 issue, and native review artifacts are |
|
Merged via squash.
|
…w#124479) Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: coaiMax <[email protected]>
Related: #123632
Related: #95417
Related: #109754
What Problem This Solves
Fixes an issue where eligible Gemini runs could stop before primary generation when Google prompt-cache creation or refresh returned an invalid successful response, a transport error, or unusable cache metadata.
Prompt caching is an optional optimization. Provider-side cache failures must leave the system prompt, tools, and visible generation path intact unless the caller itself cancelled the run or another authoritative operation failed.
Why This Change Was Made
The repair lives in the Google prompt-cache lifecycle owner. It removes the duplicate JSON reader and uses the shared provider response parser for the existing 1 MiB bound, fatal UTF-8 decoding, JSON parsing, top-level object validation, and credential-safe causes.
Request URL, authentication headers, sentinel resolution, and body serialization are completed before the optional-operation boundary, so construction failures remain fatal. Only fetch, non-2xx handling, response consumption, and automatic response validation degrade to uncached generation. Caller cancellation, transcript-writer authority loss, and primary stream failures remain fatal.
Automatic and persisted cache names share one transport-stability validator. It requires the
cachedContents/prefix, a nonempty id other than.or.., and a throw-safeencodeURIComponent(id) === idresult. This follows Google's publishedcachedContents/{id}contract while ensuring the maintained SDK's raw resource-name interpolation cannot alter the request URL. Ready state requires a parseable future expiry. Invalid ready entries rebuild, valid existing caches survive malformed refresh responses, and the existing failed-create backoff remains best effort.This cache state is transient. There is no migration, configuration, schema, protocol, public API, or security-contract change. Explicit operator-provided
cachedContentremains untouched.The contributor's original approach was discarded because wrapping the local
JSON.parsestill left a duplicate parser and allowed optional cache failures to abort the primary stream.User Impact
Gemini users continue receiving normal uncached output when automatic prompt-cache creation or refresh fails or returns malformed metadata. Valid caches and explicit operator cache references continue working as before.
Contributor credit is preserved with the public noreply coauthor trailer for @coaiMax.
Evidence
innerCalls=0and no visible generation output.files/cache-idpreviously bypassed creation with zero cache fetches. It now triggers one rebuild and injectscachedContents/rebuilt.20260829) describesCachedContent.nameascachedContents/{id}and constrains get/update path parameters with^cachedContents/[^/]+$: https://generativelanguage.googleapis.com/$discovery/rest?version=v1beta@google/genaiv2.18.0source calls the name server-generated, then performs raw path substitution beforenew URL(): https://github.com/googleapis/js-genai/blob/128781fdfec5d33f24d8305d90964f3b75b0774f/src/types.ts#L6227-L6229, https://github.com/googleapis/js-genai/blob/128781fdfec5d33f24d8305d90964f3b75b0774f/src/_common.ts#L9-L21, https://github.com/googleapis/js-genai/blob/128781fdfec5d33f24d8305d90964f3b75b0774f/src/caches.ts#L332-L386, and https://github.com/googleapis/js-genai/blob/128781fdfec5d33f24d8305d90964f3b75b0774f/src/_api_client.ts#L443-L455.cachedContent, and records the existing 10-minute backoff.encodeURIComponentuses the exact PATCH URL. An otherwise-invalid explicit operator reference still bypasses automatic validation unchanged.buildGuardedModelFetch: a controlled loopback server returns malformed cache-creation JSON, then a valid generation stream. The generation endpoint is reached and emitsvisible-generation-output.+101/-99(net+2). The small positive delta is the required prefix/id validation plus the throw-safe URI stability check; the duplicate parser and old lifecycle paths remain deleted.+849/-182(net+667), covering the requested malformed-response, transport-stability, and lifecycle matrix.pakoenvironment state:ui:buildsees its CommonJS named-export mismatch, and the core-test type graph reports the missing declaration atui/vite.config.ts:9. The changed core typecheck and focused tests pass; no dependency installation or unrelated repair was included.