Skip to content

feat(openai): opt into 12-hour prompt caching - #178695

Merged
roboclaw-bot merged 5 commits into
mainfrom
openclaw/x-2112617911122788842-prompt-cache-config
Oct 21, 2026
Merged

roboclaw-bot merged 5 commits into
mainfrom
openclaw/x-2112617911122788842-prompt-cache-config

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

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.ttl for 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

  • Regression requests fail on the original implementation (missing TTL) and pass with the change.
  • 117 focused tests passed across Responses builders, write pricing, existing Chat Completions policy, config-to-stream precedence/validation, proxy forwarding, and prompt-prefix stability.
  • 3 live OpenAI Responses cases passed on gpt-5.6-luna: unset, 30m, and 12h. These prove API acceptance and completed streamed replies, not 12-hour elapsed retention or realized billing savings.
  • Production tsconfig.core.json typecheck, changed-file format check, documentation config-example validation, and git diff --check passed.
  • Independent Auto Review: no actionable P0–P2 findings in the supplied diff.
  • Full pnpm build passed (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

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Oct 20, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 20, 2026 19:10
@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) October 20, 2026 19:15
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 20, 2026
@roboclaw-bot
roboclaw-bot disabled auto-merge October 20, 2026 19:25
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]>
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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".

  • Before: The parameter is not forwarded into the Responses request.
  • After: Eligible requests send prompt_cache_options.ttl="12h", and reported lifetime buckets determine estimated write cost.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is coherent and the earlier pricing finding is resolved; inspected proof is strongest at in-process boundaries, with live acceptance reported for the earlier feature head.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored bot PR is outside the ordinary contributor proof gate; it reports prior-head live Responses acceptance for unset, 30m, and 12h, while current pricing repair has mocked-transport regressions and the Gateway limitation remains explicit. Source shows no persisted format, migration, default, or existing-value rewrite.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Persistent OpenAI API agents cannot explicitly request longer cache coverage for stable prefixes reused across longer gaps.
Reason: The maintainer-authored change provides an explicit, documented opt-in with disclosed higher write costs and unchanged defaults.

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
Reviewed head: eeb556b73cacea28c5078ff6beb8f96e931937c1

Before merge

None.

Findings

None.

Tests

  • Low-value test packages/ai/src/providers/openai-responses.test.ts: Remove the standalone simple-completions TTL preservation test: the new simple-path pricing cases already exercise that entry point and assert the serialized TTL.
  • Missing end-to-end proof: The supplied evidence does not exercise configured TTL selection through a complete Gateway-to-model run; the PR explicitly records that limitation.
Agent review details

How this fits together

Model 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]
Loading

Technical review

Best 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

  • Cache lifetime policy and compatibility gates keeps the original intent (8e3f572: Honor explicit retention settings through one shared policy while keeping proxies opt-in and ChatGPT lifetime fields suppressed.)
  • GPT-5.6-and-later lifetime selection changes intended behavior with a stated reason (eb72093: Use the supported Responses cache field instead of legacy retention fields; the new optional lifetime follows the updated provider contract.)
  • Shared terminal usage accounting keeps the original intent (9f7c752: Keep token buckets and terminal cost accounting consistent across package and managed Responses paths.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 8e3f572 adds packages/ai/src/providers/openai-prompt-cache.ts:21 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8e3f572ffa25; files: packages/ai/src/providers/openai-prompt-cache.ts)
  • Yiğit ERDOĞAN: Raw commit 9f7c752 adds packages/ai/src/providers/openai-responses-terminal-usage.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9f7c7521f198; files: packages/ai/src/providers/openai-responses-terminal-usage.ts)
  • Vincent Koc: Raw commit 9366d0a adds src/llm/providers/openai-responses-shared.ts:419 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9366d0a873e2; files: src/llm/providers/openai-responses-shared.ts)

PR surface

Source +62, Tests +137, Docs +46. Total +245 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 14 73 11 +62
Tests 5 142 5 +137
Docs 2 47 1 +46
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 262 17 +245

Review metrics

Metric Value Why it matters
Configuration surface 1 optional parameter, 2 supported values promptCacheTtl accepts 30m or 12h through existing parameter records; omitted settings retain prior behavior.

Labels

Label changes:

  • add P2: Useful opt-in improvement for persistent API agents, without an urgent broken default workflow.
  • add merge-risk: 🚨 compatibility: The optional parameter expands SDK-exported stream options; the maintainer-authored direction covers this additive contract, with existing callers and defaults preserved.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Useful opt-in improvement for persistent API agents, without an urgent broken default workflow.
  • merge-risk: 🚨 compatibility: The optional parameter expands SDK-exported stream options; the maintainer-authored direction covers this additive contract, with existing callers and defaults preserved.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-20T19:29:38.233Z sha 00dad7b :: needs changes before merge. :: [P2] Price cache writes using the reported lifetime breakdown

Reviewed October 20, 2026, 4:30 PM ET / 20:30 UTC (Revision 2).

roboclaw-bot and others added 2 commits October 20, 2026 20:09
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]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 20, 2026
Picks up the main-side mock-exports ratchet repair (2466488) that failed checks-fast-baseline-ratchets on eeb556b.

Co-authored-by: jalehman <[email protected]>
@roboclaw-bot
roboclaw-bot merged commit 4697b8e into main Oct 21, 2026
141 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/x-2112617911122788842-prompt-cache-config branch October 21, 2026 00:13
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

roboclaw-bot added a commit that referenced this pull request Oct 21, 2026
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant