Repository navigation
fix(openai): honor native prompt cache settings - #140853
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. |
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 2:12 AM ET / 06:12 UTC. ClawSweeper reviewWhat this changesMakes 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 Review scores
Verification
How this fits togetherThe 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
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +70, Tests +297, Docs +3. Total +370 across 23 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
1664e8a to
37a067f
Compare
|
Merged via squash.
|
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.
* 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.
* fix(openai): honor native prompt cache settings * fix(openai): preserve ChatGPT prompt cache identity
* 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.
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 useprompt_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:
shortsends the key only,noneremoves both the key and lifetime fields, andlonguses the field supported by the model.nonedoes not disable OpenAI's automatic caching. Proxy operators retain explicit capability control.Updated
docs/reference/prompt-caching.mddescribes the exact wire behavior.Evidence
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.node scripts/check-changed.mjs: stops only at the authorized nested-checkout environmental boundary:Declaration input escapes checkout ... qrcodewhile 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.scoped-clean, zero accepted/actionable P0/P1 findings; overall verdict: patch is correct.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
falsetotrue; no snapshots or baselines were changed. The runner test helper gained the existingopenai-chatgpt-responsesAPI 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
maintransport changes without reverting their endpoint path, marker-policy, or tool-conversion behavior.