Repository navigation
feat(openai): opt into 12-hour prompt caching - #178695
Conversation
|
🦞👀 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. |
Include existing main fix 4453edc for the missing worker-permission file reported by CI run 39481201843, checks-node-changed-10. The prompt-cache feature patch is unchanged. Co-authored-by: steipete <[email protected]>
|
Codex review: needs maintainer review before merge. What this changesThis PR adds an optional OpenAI Responses cache lifetime parameter and accounts for 12-hour cache-write prices. Example: Configure openai/gpt-6.1-sol with params.promptCacheTtl set to "12h".
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored PR open: it provides a useful opt-in capability, resolves the previous pricing finding, and has no remaining actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherModel and agent parameters enter the stream-option adapters, the shared OpenAI cache policy selects eligible request fields, and terminal Responses usage becomes token and cost accounting. flowchart TD
A[Model and agent parameters] --> B[Stream options]
B --> C[Shared cache policy]
C --> D[Responses transports]
D --> E[OpenAI API]
E --> F[Shared terminal accounting]
F --> G[Usage and cost]
Technical reviewBest possible solution: Retain the optional TTL in the existing policy owner and the reported-lifetime pricing at the shared terminal boundary. Do we have a high-confidence way to reproduce the issue? This is a feature addition; source confirms current main does not forward promptCacheTtl, and the prior pricing defect is addressed by the revised shared accounting. Is this the best way to solve the issue? The change extends existing option adapters, lifetime policy, and terminal accounting without introducing competing state or cache machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 05ade6d2df13. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +62, Tests +137, Docs +46. Total +245 across 21 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 HistoryReview history (1 earlier review cycle)
Reviewed October 20, 2026, 4:30 PM ET / 20:30 UTC (Revision 2). |
Preserve the SDK request shape while the canonical wire contract owns the optional 30m/12h lifetime field. Reproduces and fixes the package test-type TS2353 failure without casts or runtime changes; package types and 122 focused caller/request tests pass. Co-authored-by: steipete <[email protected]>
Prefer coherent 30m/12h usage counters over the request default so breakpoint overrides are priced correctly. Preserve request-default fallback for compatible endpoints that omit the breakdown. Six mixed-lifetime cases were red before the fix and pass through both Responses paths; package test types and focused suites pass. Co-authored-by: steipete <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Picks up the main-side mock-exports ratchet repair (2466488) that failed checks-fast-baseline-ratchets on eeb556b. Co-authored-by: jalehman <[email protected]>
|
Merged via squash.
|
Merge pinned main 45f9aed to resolve the actual conflict with #178695. Preserve its API request policy and pricing. Share the model predicate and lifetime resolver, forward prepared TTL policy to settlement, and schedule qualified 12-hour windows at 11h55m. Keep 30m, one-hour, short-window exclusion and the separate built-in OAuth heuristic unchanged. Co-authored-by: VACInc <[email protected]>
* feat(openai): opt into 12-hour prompt caching * fix(openai): accept complete Responses request parameters Preserve the SDK request shape while the canonical wire contract owns the optional 30m/12h lifetime field. Reproduces and fixes the package test-type TS2353 failure without casts or runtime changes; package types and 122 focused caller/request tests pass. Co-authored-by: steipete <[email protected]> * fix(openai): price cache writes by reported lifetime Prefer coherent 30m/12h usage counters over the request default so breakpoint overrides are priced correctly. Preserve request-default fallback for compatible endpoints that omit the breakdown. Six mixed-lifetime cases were red before the fix and pass through both Responses paths; package test types and focused suites pass. Co-authored-by: steipete <[email protected]> --------- Co-authored-by: steipete <[email protected]> Co-authored-by: jalehman <[email protected]>
What Problem This Solves
Persistent OpenAI API agents need an opt-in way to reuse stable prompt prefixes across gaps longer than the default cache lifetime.
User Impact
Users can set
params.promptCacheTtl: "12h"(or"30m") per model, globally, or per agent for GPT-5.6+ Responses requests. Unset configuration, older models' retention behavior, Chat Completions, and ChatGPT/Codex behavior are unchanged. This requests a minimum cache lifetime, not guaranteed cache hits or a deletion deadline. 12h writes cost more: 2.5× ordinary input versus 1.25× for 30m writes; reads retain the same rate.Why This Change Was Made
OpenAI's current caching guide specifies
prompt_cache_options.ttlfor the Responses API, distinct from older models'prompt_cache_retention. The request-level value also applies to implicit breakpoints; this change does not add explicit breakpoints or change caching mode. Current pricing confirms total write rates, not additive surcharges. Upgrading valid 30m coverage to 12h charges a new 12h write without credit for the earlier write.Reuse the existing cache-parameter owner and compatibility gates across provider and managed transports. Preserve
cacheRetention: "none"precedence, validate invalid TTLs without logging authored values, and account for the higher write rate in local estimates. Existing open-ended provider-parameter schemas already accept the option, so no new top-level config field, schema migration, dependency bump, or parallel cache implementation is needed. The wire contract handles the API's new value without patching or casting around the pinned SDK.Simplification review retained one lifetime decision owner; production growth is option plumbing and write-cost selection, not new state or infrastructure.
Evidence
gpt-5.6-luna: unset,30m, and12h. These prove API acceptance and completed streamed replies, not 12-hour elapsed retention or realized billing savings.tsconfig.core.jsontypecheck, changed-file format check, documentation config-example validation, andgit diff --checkpassed.pnpm buildpassed (3m 33.6s); changed-file typed lint passed with 0 warnings/errors. An isolated, authenticated Gateway started on its own profile, state, workspace, and port. Its real-agent CLI probe was refused by the agent-exec inter-session attribution guard before inference, so full Gateway-to-model proof remains incomplete. No alternate CLI/RPC route or guard bypass was attempted.Live-proof limitation: full Gateway-to-model proof remains unexecuted because the agent-exec attribution guard refused its CLI invocation. Direct provider API acceptance is proven; this does not claim that missing Gateway boundary. @steipete instructed landing with the documented evidence and limitations; enforced GitHub review, security, and CI gates still apply.
Known verification limits: the changed-test typecheck wrapper failed its existing global test-root budget preflight and was stopped while waiting for generated artifacts (plugins-platform 727 > 720; no test roots are added here). One additional native-worker environment probe failed with
502 Secret egress proxy refused the request; its other cases passed. No egress guard was bypassed. PR CI is the broad-check owner; CI timing is pending. Local focused suites took 99.5s total (most time in compiled agent-worker setup); test execution stayed below 5s per changed non-live file. Live cases took 24.2s wall time.Settlement-baseline repair: 5aedeae integrates existing main settlement fix 4453edc via baseline 1c4b270 for the launch-wire missing-file failure in run 39481201843. The complete feature diff is byte-identical to the original reviewed patch. All 117 focused feature tests passed again on the integrated head (32.72s). The local full launch-wire attempt hit a synthetic-provider ECONNRESET during baseline inference before the original settlement assertion, so no local full-file pass is claimed. Fresh current-head GitHub CI is required; original build/live evidence above remains prior-head evidence.
Current repaired head: eeb556b. The CI package-type error was reproduced and fixed by retaining the complete SDK request shape and the API-optional TTL field; the exact package test-type graph now passes. The review finding about mixed cache lifetimes is also fixed: coherent reported 30m/12h buckets override the request default, with compatibility fallback when absent. Six new pricing cases were red before the repair and now pass through both Responses paths, including zero 12h writes. Current accounting/lifecycle suites: 78 passed; type-repair caller/request suites: 122 passed. Typed lint/format/diff checks and fresh independent P0–P2 review passed. Prior settlement-failure job checks-node-changed-10 is green on the integrated baseline. Fresh CI on this head remains required; previous full-build/live evidence and the stated Gateway/host limitations are not relabeled as current-head proof.
Requested by @steipete.
Work sessions