Skip to content

fix(openai): honor native prompt cache settings - #140853

Merged
steipete merged 2 commits into
mainfrom
kv/openai-native-prompt-cache-config
Sep 7, 2026
Merged

steipete merged 2 commits into
mainfrom
kv/openai-native-prompt-cache-config

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users selecting cacheRetention: "long" or "none" on native OpenAI routes would have that setting silently dropped. Managed Chat Completions also omitted the session cache-routing key by default, and Responses could send an unsupported legacy lifetime field to newer models.

Why This Change Was Made

One parsed-endpoint policy now supplies cache-key eligibility to the runner and compatibility resolver, with explicit opt-outs honored and proxies remaining opt-in. Both managed and SDK builders share the documented lifetime mapping: GPT-5.6 and later use prompt_cache_options.ttl: "30m"; supported earlier native models use prompt_cache_retention: "24h". Unknown earlier native models receive no lifetime field. The obsolete builder-specific URL checks and lifetime branches are removed.

Native ChatGPT-backed Responses routes retain their cache key, forward explicit retention choices, and omit both OpenAI lifetime fields, including fields injected by payload hooks. Their existing endpoint predicate now lives beside the shared compatibility policy.

The xAI plugin explicitly declares its existing native Responses cache-key capability, with lifetime fields disabled by default, so shared proxy opt-in enforcement preserves xAI cache routing. Custom xAI proxies remain opt-in.

This follows the official OpenAI cache-lifetime contract. No configuration options, persisted stores, schemas, or changelog entries are added.

User Impact

Direct OpenAI Responses and Chat Completions sessions receive stable cache-routing keys automatically. Explicit retention settings now reach the transport: short sends the key only, none removes both the key and lifetime fields, and long uses the field supported by the model. none does not disable OpenAI's automatic caching. Proxy operators retain explicit capability control.

Updated docs/reference/prompt-caching.md describes the exact wire behavior.

Evidence

  • Before the fix: 20 failing regression cases across retention resolution, stream-option forwarding, managed request construction, and SDK serialization reproduced the defects.
  • Full directory/transport command: node scripts/run-vitest.mjs packages/ai extensions/xai src/agents/openai-transport-stream*.test.ts src/agents/embedded-agent-runner/prompt-cache-retention.test.ts src/agents/embedded-agent-runner/extra-params*.test.ts — 186 files, 3,457 tests passed across six lanes after reconciliation with main and frozen-lockfile dependency sync. A separate Vitest cache was used while changed-file checks ran.
  • The xAI preservation regression failed four native-route cases before the capability declaration. Expanded ChatGPT regressions failed seven cases before repair (retention forwarding, key identity, and lifetime stripping after payload hooks); all now pass.
  • node scripts/check-changed.mjs: stops only at the authorized nested-checkout environmental boundary: Declaration input escapes checkout ... qrcode while preparing extension lint declarations. Core and extension typechecks (production and tests), core lint, formatting, dead-export scans, and all preceding guards passed. All eight remaining guards passed when run separately after that environmental stop. The exact-head CI extension lint lane is required proof; no ancestor checkout or boundary guard was modified.
  • pnpm build: all compilation phases and all six declaration groups completed; the full command was stopped with exit 130 after declaration publication stalled in a local filesystem rename. This is an incomplete full-build proof, not a passing build. No build guards or locks were bypassed.
  • Final Codex autoreview against the merge base, local mode, P1 threshold: scoped-clean, zero accepted/actionable P0/P1 findings; overall verdict: patch is correct.
  • Live contract proof: all 12 synthetic requests returned HTTP 200, covering Responses and Chat Completions, GPT-5.4 and GPT-5.6 Sol, and none / short / long. This proves request-field acceptance, not a cache-hit or cost benchmark.

The SDK compatibility fixture uses its canonical model type without a redundant intersection/return annotation; all 69 tests and targeted lint passed after that simplification. No test cases or assertions were removed.

Two existing native compatibility expectations were updated from cache-key support false to true; no snapshots or baselines were changed. The runner test helper gained the existing openai-chatgpt-responses API in its type constraint; its mock behavior and assertions are unchanged.

The initial CI run caught three ChatGPT transport/proxy fixture failures; the follow-up restores native identity and explicitly opts the custom proxy fixture into its asserted capability. Its key assertion is retained. The branch also incorporates current main transport changes without reverting their endpoint path, marker-policy, or tool-conversion behavior.

@clawsweeper

clawsweeper Bot commented Sep 7, 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.

@steipete
steipete marked this pull request as ready for review September 7, 2026 05:18
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: xai size: M maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 2:12 AM ET / 06:12 UTC.

ClawSweeper review

What this changes

Makes existing prompt-cache settings reach OpenAI request builders consistently, preserves native ChatGPT and xAI cache routing, and updates regression coverage and documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful repair: current main and the latest release still drop native OpenAI retention settings. The reviewed patch addresses that gap without an identified blocking correctness or security defect.

Priority: P2
Reviewed head: 37a067f681a0d5b219a0d169a24153a3fdb6ed76

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with relevant live contract observations and regression coverage, with no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports successful live Responses and Chat Completions requests across all retention modes and both lifetime formats, supporting the shared builders' request-field acceptance. Runner forwarding and native ChatGPT filtering have supplemental regression coverage; cache-hit performance is not claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports successful live Responses and Chat Completions requests across all retention modes and both lifetime formats, supporting the shared builders' request-field acceptance. Runner forwarding and native ChatGPT filtering have supplemental regression coverage; cache-hit performance is not claimed.
Evidence reviewed 9 items Current-main defect remains: The current-main retention resolver returns undefined unless the model belongs to an eligible provider family or explicitly declares cache compatibility; native OpenAI endpoint eligibility is absent.
Latest-release check: The same missing native OpenAI eligibility is present in the supplied latest release, v2026.9.2; this is not already-shipped cleanup.
Shared policy and explicit overrides: The introduced policy honors explicit cache-key opt-outs, recognizes native endpoints by parsed hostname, and shares lifetime selection across managed and SDK request builders. Regression cases cover native routes, opted-in proxies, misleading endpoint strings, and disabled lifetime support.
Findings None None.
Security None None.

How this fits together

The agent runner passes model settings and session identity to the AI transport layer. That layer converts them into provider-specific cache keys and lifetime fields before sending model requests.

flowchart TD
  A[Model settings and session identity] --> B[Agent runner]
  B --> C[Endpoint and capability policy]
  C --> D[Cache key and lifetime selection]
  D --> E[Responses and Chat Completions builders]
  E --> F[Native ChatGPT field filtering]
  E --> G[Provider request]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +70, Tests +297, Docs +3. Total +370 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 12 172 102 +70
Tests 10 360 63 +297
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 537 167 +370

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +70 net lines; tests and test support +297 Production growth consolidates endpoint eligibility and model lifetime selection; regression coverage exercises the separate runner, SDK, and managed transport boundaries.

Technical review

Best possible solution:

Keep cache capability and lifetime decisions centralized while preserving explicit settings, proxy opt-in, and native backend field restrictions.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: native OpenAI models without explicit cache compatibility lose configured retention in the current-main runner. The added regression cases target that path; this review did not execute them.

Is this the best way to solve the issue?

Yes. Reusing one endpoint policy and lifetime selector repairs the existing setting across request builders, with explicit backend exceptions and no additional configuration surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9230180f699e.

Labels

Label justifications:

  • P2: Repairs silently ignored cache settings and inconsistent request metadata without evidence of an urgent core outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports successful live Responses and Chat Completions requests across all retention modes and both lifetime formats, supporting the shared builders' request-field acceptance. Runner forwarding and native ChatGPT filtering have supplemental regression coverage; cache-hit performance is not claimed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports successful live Responses and Chat Completions requests across all retention modes and both lifetime formats, supporting the shared builders' request-field acceptance. Runner forwarding and native ChatGPT filtering have supplemental regression coverage; cache-hit performance is not claimed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-07T05:26:37.370Z sha 1664e8a :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the kv/openai-native-prompt-cache-config branch from 1664e8a to 37a067f Compare September 7, 2026 06:06
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 7, 2026
@steipete
steipete merged commit 8e3f572 into main Sep 7, 2026
181 of 182 checks passed
@steipete
steipete deleted the kv/openai-native-prompt-cache-config branch September 7, 2026 06:20
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 7, 2026
Preserve direct reasoning and managed replay, strict tools, proxy omission,
and output budgeting. Integrate shared cache policies from #140781 and #140853.

Apply maintainer-approved shrink-only assertion baseline maintenance:
provider 9 to 6 (main already reduced 10 to 9), params 9 to 7.

Proof: focused provider, transport, cache and wrapper suites pass
(30 files, 575 tests), and core typecheck passes;
Codex autoreview found no actionable P0-P2 issues.
steipete added a commit that referenced this pull request Sep 7, 2026
* refactor(ai): share Chat Completions request assembly

Preserve direct reasoning and managed replay, strict tools, proxy omission,
and output budgeting. Integrate shared cache policies from #140781 and #140853.

Apply maintainer-approved shrink-only assertion baseline maintenance:
provider 9 to 6 (main already reduced 10 to 9), params 9 to 7.

Proof: focused provider, transport, cache and wrapper suites pass
(30 files, 575 tests), and core typecheck passes;
Codex autoreview found no actionable P0-P2 issues.

* style(ai): flatten completions tool-history condition

Preserve the same empty-tool history fallback while satisfying no-lonely-if. The focused compat/tool-choice suite passes all 9 tests; Codex autoreview reports no actionable P0-P2 findings.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
* fix(openai): honor native prompt cache settings

* fix(openai): preserve ChatGPT prompt cache identity
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
* refactor(ai): share Chat Completions request assembly

Preserve direct reasoning and managed replay, strict tools, proxy omission,
and output budgeting. Integrate shared cache policies from openclaw#140781 and openclaw#140853.

Apply maintainer-approved shrink-only assertion baseline maintenance:
provider 9 to 6 (main already reduced 10 to 9), params 9 to 7.

Proof: focused provider, transport, cache and wrapper suites pass
(30 files, 575 tests), and core typecheck passes;
Codex autoreview found no actionable P0-P2 issues.

* style(ai): flatten completions tool-history condition

Preserve the same empty-tool history fallback while satisfying no-lonely-if. The focused compat/tool-choice suite passes all 9 tests; Codex autoreview reports no actionable P0-P2 findings.
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 extensions: xai maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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