Skip to content

agents: forward prompt_cache_key on openai-completions when compat.supportsPromptCacheKey is set#69411

Closed
sk7n4k3d wants to merge 1 commit into
openclaw:mainfrom
sk7n4k3d:feat/prompt-cache-key-completions
Closed

agents: forward prompt_cache_key on openai-completions when compat.supportsPromptCacheKey is set#69411
sk7n4k3d wants to merge 1 commit into
openclaw:mainfrom
sk7n4k3d:feat/prompt-cache-key-completions

Conversation

@sk7n4k3d

Copy link
Copy Markdown
Contributor

Summary

Fixes #69272.

buildOpenAICompletionsParams never emitted prompt_cache_key on the
Completions path, so operators running OpenAI-compatible proxies (vLLM,
SGLang, Chutes, etc.) could not opt into stable prompt caching per session
the way buildOpenAIResponsesParams already does for the Responses API.

This change forwards options.sessionId as prompt_cache_key on the
Completions path under all three of the following conditions:

  1. model.compat.supportsPromptCacheKey === true (explicit opt-in, defaults
    to the existing behavior — nothing emitted — when unset or false).
  2. resolveCacheRetention(options?.cacheRetention) !== "none" (mirrors the
    Responses API gate at src/agents/openai-transport-stream.ts:794).
  3. options?.sessionId is present.

Conservative default preserves #49877 / #48155 (Volcano Engine DeepSeek
rejects unknown fields) and the scope maintainers set in #67427.

Why not covered by #67427

#67427 added compat.supportsPromptCacheKey to gate the Responses API
strip. That is the right mechanism, but it only affected Responses API
payloads. The Completions builder had no knob at all. This PR wires the
same flag through the second code path.

Changes

  • src/agents/openai-transport-stream.ts — added the conditional emit in
    buildOpenAICompletionsParams with an explanatory comment matching the
    Responses API emission.
  • src/agents/openai-transport-stream.test.ts — 5 new tests covering:
    1. Default off (no compat.supportsPromptCacheKey, sessionId present) → not emitted
    2. compat.supportsPromptCacheKey=true + sessionId → emitted
    3. compat.supportsPromptCacheKey=true + cacheRetention: "none" → suppressed
    4. compat.supportsPromptCacheKey=true + no sessionId → suppressed
    5. compat.supportsPromptCacheKey=false → suppressed

Scope

Nothing else touched:

  • No new provider surface, no new compat field, no schema changes.
  • No change to Responses API, Anthropic cacheRetention, or Gemini
    cachedContents.
  • No change to tool assembly, system prompt shaping, or usage parsing.

Test plan

  • pnpm test src/agents/openai-transport-stream.test.ts — 70/70 passed
  • pnpm tsgo:core — clean
  • pnpm tsgo:core:test — clean
  • pnpm lint — clean (via committer check:changed)
  • pnpm format — clean
  • Import cycle checks — 0 cycles

AI-assisted: yes (Claude, under sk7n4k3d supervision).

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Apr 20, 2026
@greptile-apps

greptile-apps Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR wires prompt_cache_key forwarding into buildOpenAICompletionsParams for OpenAI-compatible providers (vLLM, SGLang, etc.) that support it, matching the existing Responses API behavior. The change is guarded by three conditions — compat.supportsPromptCacheKey === true, cacheRetention !== "none", and a non-empty sessionId — preserving the conservative default that protects providers that reject unknown fields.

Confidence Score: 5/5

Safe to merge — the change is well-scoped, default-off, and thoroughly tested.

The implementation mirrors the existing Responses API pattern precisely, the three-condition gate preserves backward compatibility, all five new test cases correctly exercise the branches, and no existing behaviour is altered when supportsPromptCacheKey is absent or false.

No files require special attention.

Reviews (1): Last reviewed commit: "agents: forward prompt_cache_key on open..." | Re-trigger Greptile

@steipete

Copy link
Copy Markdown
Contributor

Closing this as implemented after Codex review.

Current main already forwards prompt_cache_key on the OpenAI Completions path behind the same opt-in/cache/session guards described in this PR, and current tests cover the forwarded and omitted cases, so the PR is redundant.

What I checked:

  • Completions path already forwards prompt_cache_key on main: buildOpenAICompletionsParams resolves cache retention, then sets params.prompt_cache_key = options.sessionId only when compat.supportsPromptCacheKey is true, caching is not disabled, and sessionId is present. (src/agents/openai-transport-stream.ts:1725, 2cd2732ab669)
  • Current tests cover the same behavior: Current main includes tests asserting prompt-cache-key forwarding for opted-in OpenAI-compatible completions providers and omission when caching is disabled or the provider is not opted in. (src/agents/openai-transport-stream.test.ts:1661, 2cd2732ab669)
  • Responses-path parity already exists in the same file: The Responses builder already forwards prompt_cache_key based on cache retention, which matches the parity goal described in the PR body. (src/agents/openai-transport-stream.ts:846, 2cd2732ab669)

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Codex Review notes: reviewed against 2cd2732ab669; fix evidence: commit 2cd2732ab669.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(agents): forward prompt_cache_key on openai-completions transport when compat.supportsPromptCacheKey is set

2 participants