Repository navigation
fix(providers): preserve prompt-cache accounting and affinity - #168145
Conversation
Recognize documented cache counters, preserve unavailable telemetry, bind Gemini cached resources to effective credentials, and apply native affinity and billing contracts.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR corrects cache accounting, diagnostics, provider affinity, Gemini credential scoping, Bedrock checkpoints, and cached-token pricing. Example: A Completions response reports prompt_tokens=100, completion_tokens=20, and top-level cached_tokens=25.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR repairs current provider-cache defects through existing owners, and no introduced correctness defect was identified. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherProvider plugins prepare request policy, transports exchange provider payloads, and shared usage accounting feeds session summaries and cache diagnostics; Gemini separately manages provider cache resources through persisted session metadata. flowchart TD
A[Agent request] --> B[Provider plugin policy]
B --> C[Provider transport]
C --> D[Provider API]
D --> E[Shared usage accounting]
E --> F[Cache diagnostics]
B --> G[Gemini cache lifecycle]
G --> C
G --> H[Session metadata]
Technical reviewBest possible solution: Keep provider policy in plugins and repair accounting and cache lifecycle through their existing shared owners. Do we have a high-confidence way to reproduce the issue? Current-main source establishes omitted top-level cached counts, unavailable telemetry updating the measured baseline, credential-independent Gemini cache identity, and unsupported long TTLs; no target code was executed during this review. Is this the best way to solve the issue? The patch uses existing owners, preserves explicit overrides and native-endpoint boundaries, retains provider-billed totals, and keeps optional Gemini cache failures recoverable. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against db74f466dcbe. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +167, Tests +755, Docs +79, Other 0. Total +1001 across 43 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 10, 2026, 1:45 AM ET / 05:45 UTC (Revision 3). |
…aw#168145) * fix(providers): preserve prompt-cache accounting and affinity Recognize documented cache counters, preserve unavailable telemetry, bind Gemini cached resources to effective credentials, and apply native affinity and billing contracts. * fix(providers): satisfy cache boundary type and lint checks
openclaw#168145 (b348c67) added cacheTelemetry to usage, but the successful-trace parity fixture was never refreshed, so provider-transport-parity fails on main.
What Problem This Solves
Provider cache hits can disappear from accounting, absent telemetry can look like a real cache drop, and several native endpoints receive no supported session-affinity hint. Gemini cached-content handles can survive credential/project changes, while older Bedrock Claude models receive unsupported one-hour checkpoints.
User Impact
Cache diagnostics distinguish unavailable telemetry from measured misses. Native Together, Cerebras, DeepInfra, Venice, Fireworks, and Baseten requests carry supported affinity hints while preserving caller overrides and opt-outs. Gemini cache creation and inference share the owning credential scope; older Bedrock Claude keeps valid five-minute checkpoints. Cerebras cached input and Moonshot K3 cache writes use documented tariffs.
No new configuration, dependency, schema, paid retention default, or migration is required. Server hit rates remain provider-dependent.
Why This Change Was Made
Existing owners absorb the corrections: the shared Completions parser accepts documented top-level cached counts; the observer retains its measured baseline when telemetry is unavailable; plugins declare native-endpoint capability; Gemini includes effective request headers in its existing cache identity. Fireworks uses validated dedicated-deployment headers only when body cache telemetry is absent, preserving explicit zero and provider-billed totals. The existing SDK stream transform consumes typed message events and skips absent sparse snapshots.
Production delta: +167 net lines (258 added / 91 removed, excluding tests, test support, and docs). Distinct wire and billing contracts require this growth, principally native affinity declarations and Fireworks header accounting. Existing cache owners are reused, redundant casts are removed, and serialized Gemini tool configuration becomes a fixed digest.
Evidence
Synthetic before/after: a 100-prompt/25-cached Completions response changes from 0 recognized cached tokens to 25; a Fireworks 100-prompt/80-cached header fixture changes from 0 to 80. Missing telemetry no longer produces a measured drop. Original-source regressions also reproduce credential/project reuse, unsupported TTLs, omitted affinity, and tariff errors.
Direct Gemini 2.5 Flash-Lite controls: three immediate implicit-cache generations reported 0/19,659 cached prompt tokens (910/1,048/1,643 ms); explicit caching reused 6,533/6,543 prompt tokens (99.847%, 466 ms). The resource was deleted. These are mechanism controls, not before/after Gateway benchmarks. Total: six API calls, 26,202 prompt tokens including 6,533 cached, five output tokens, approximately $0.002034 generation cost or $0.00323 with conservative storage/creation allowance. Other providers remain live-unmeasured; their proof uses documented contracts and synthetic request/usage boundaries.
Remote validation, with no local builds, suites, or typechecks:
cbx_f44deb8e681d,run_c8131a256da91e880cb2151905083f4b: original-source replays and 336 focused tests passed.node scripts/run-vitest.mjs <14 files> --maxWorkers=1took 69.93 s; the whole command with baseline replays took 160.028 s.cbx_37c1e4a40558,run_2fc8f9fca50201ca99bd9474d5caa017: export collision guard passed (32 s), eager-import/pr-wrapper closure and publisher tests passed (86 tests, 35 s), all non-live siblings in eight touched provider directories plus Completions/cache/usage siblings passed (six shards, 161.19 s), and full build passed (328 s).cbx_4d1b72933eff,run_3eef979c5168b3934588e1a56417f1c4: full build including the typed SDK implementation passed (461 s). Later fixture/style corrections are covered by the final tests, types, and lint.cbx_5abb1b986311,run_b481ee4c26d7d0bbd23cdda52752d899: hashes verified for all 43 changed paths; corrected Baseten/Fireworks/Moonshot tests passed in 80.40 s, complete extension-test typecheck passed (31 s), full core lint passed (497 s, zero errors), full extension lint passed (377 s, zero warnings/errors). Whole command: 989.183 s; source transfer: 364.243 s. This dedicated lease resolved the shared rig's lint OOM and declaration-preparation timeout.Rebased for overlapping SDK/publisher changes: the production patch was preserved and only an expectation in a test main removed was dropped. The configured Blacksmith lease did not acquire a runner; AWS/Hetzner and the authorized rig supplied actual proof. Final-head CI run 38027351241 passed in 499 s wall time; its 21 successful Node test jobs totaled 2659 job-seconds (longest 256 s). Long-lived eviction, replica affinity, local-engine residency, and authenticated Bedrock/Vertex behavior remain unmeasured.