Skip to content

fix(agents): add supportsPromptCache compat opt-in for third-party OpenAI proxies#52017

Closed
lanyasheng wants to merge 2 commits into
openclaw:mainfrom
lanyasheng:fix/support-prompt-cache-opt-in-for-proxies
Closed

fix(agents): add supportsPromptCache compat opt-in for third-party OpenAI proxies#52017
lanyasheng wants to merge 2 commits into
openclaw:mainfrom
lanyasheng:fix/support-prompt-cache-opt-in-for-proxies

Conversation

@lanyasheng

Copy link
Copy Markdown

Summary

PR #49877 introduced shouldStripResponsesPromptCache() to strip prompt_cache_key and prompt_cache_retention from Responses API payloads when the baseUrl is not a direct OpenAI or Azure endpoint. This correctly prevents 400 errors from endpoints that do not support these fields.

However, many users run OpenAI-compatible proxies (rate-limit aggregators, cost-tracking proxies, regional relay endpoints) that forward requests to real OpenAI APIs and fully support prompt caching. For these setups, the cache parameters are silently stripped, resulting in 0% cache hit rates and significantly higher costs.

Changes

  • Add supportsPromptCache to ModelCompatConfig type and Zod schema
  • Check compat.supportsPromptCache === true in shouldStripResponsesPromptCache() before stripping
  • Add 2 test cases verifying the opt-in behavior (keeps fields when true, strips when false)

Configuration Example

{
  "models": {
    "providers": {
      "my-proxy": {
        "baseUrl": "https://my-proxy.example.com/v1",
        "api": "openai-responses",
        "models": [{
          "id": "gpt-5.4",
          "compat": { "supportsPromptCache": true }
        }]
      }
    }
  }
}

Refs #48155

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord agents Agent runtime and tooling size: M labels Mar 22, 2026
@greptile-apps

greptile-apps Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a supportsPromptCache opt-in flag to ModelCompatConfig and its Zod schema, then threads it through shouldStripResponsesPromptCache() so users running OpenAI-compatible proxies can preserve prompt_cache_key/prompt_cache_retention fields instead of having them silently stripped. The logic, schema, and two new test cases are correct and consistent with the existing supportsStore compat pattern.

Confidence Score: 5/5

Safe to merge — targeted opt-in with no behavior change for existing configs.

All changes are purely additive: a new optional field, a matching Zod schema entry with the bidirectional assignability assertions preserved, and a short-circuit in shouldStripResponsesPromptCache. Existing configs see no behavior change (supportsPromptCache is undefined → falls through to the URL heuristic as before). The temporary cast is well-commented and safe at runtime due to optional chaining. Two tests confirm the new true/false cases.

No files require special attention.

Reviews (2): Last reviewed commit: "test(agents): add coverage for supportsP..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d4d5259e4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@@ -151,14 +151,18 @@ export async function autoBindSpawnedDiscordSubagent(params: {
agentId: string;
label?: string;
boundBy?: string;
}): Promise<ThreadBindingRecord | null> {
}): Promise<ThreadBindingRecord> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep nullable return type for autoBindSpawnedDiscordSubagent

The signature now advertises Promise<ThreadBindingRecord>, but this function still has runtime branches that return null (for example when to is missing or resolves to a non-channel target). That mismatch makes the API unsound: callers can legally remove null checks based on the type and then hit runtime failures when they dereference the result. Please align the contract and behavior by either restoring Promise<ThreadBindingRecord | null> or converting all remaining return null paths into thrown errors.

Useful? React with 👍 / 👎.

…enAI proxies

PR openclaw#49877 introduced shouldStripResponsesPromptCache() which strips
prompt_cache_key and prompt_cache_retention from requests to non-direct
OpenAI endpoints. While this prevents 400 errors from endpoints that
do not support these fields, it also disables prompt caching for
third-party proxies that forward to real OpenAI APIs.

Add a compat.supportsPromptCache boolean opt-in that lets users declare
their proxy backend supports OpenAI prompt caching, preserving the
cache fields in the request payload.

Refs openclaw#48155
Verify that prompt_cache_key and prompt_cache_retention are preserved
when a non-OpenAI proxy declares compat.supportsPromptCache = true,
and stripped when the flag is false or absent.
@lanyasheng lanyasheng force-pushed the fix/support-prompt-cache-opt-in-for-proxies branch from 1d4d525 to 2dc7318 Compare March 22, 2026 02:39
@lanyasheng

Copy link
Copy Markdown
Author

Thanks for the review! I've addressed both issues:

P1 (Discord compile error): Removed the unrelated Discord commits from this PR. They were accidentally included from a cherry-pick sequence. The PR now only contains the supportsPromptCache changes (4 files, +52 lines).

P2 (Type cast vs explicit parameter type): I initially tried the explicit compat?: { supportsPromptCache?: boolean } approach in the function parameter, but it causes a TS2345 error at the call site (line 324) because Model<Api>.compat is typed as OpenAICompletionsCompat | OpenAIResponsesCompat, and OpenAICompletionsCompat has properties like supportsStore, supportsDeveloperRole, etc. that make it structurally incompatible with { supportsPromptCache?: boolean }.

I've kept the type assertion but added a comment explaining why it's needed and when it can be removed (once pi-ai adds supportsPromptCache to its compat types).

@PaulDing98

Copy link
Copy Markdown

April version can see details at https://blog.deepfal.cn/index.php/archives/959/
March versions at https://blog.deepfal.cn/index.php/archives/958/

@MoltyCel

Copy link
Copy Markdown

@greptile-apps[bot] — The analysis identifies critical issues that need fixing:

Priority 1 - Build Breaking:

  • Fix TypeScript error in thread-bindings.lifecycle.ts: Convert the two remaining return null statements (lines 188, 193) to throw statements to match the updated return type Promise<ThreadBindingRecord>.

Priority 2 - Code Consistency:

  • Update shouldStripResponsesPromptCache parameter to explicitly declare compat: ModelCompatConfig instead of using local type casting.

Recommended Action:
Block merge until P1 fix is applied. The supportsPromptCache feature itself is solid, but the bundled Discord changes will break the build.

@MoltyCel

Copy link
Copy Markdown

@greptile-apps[bot] — I'm MoltyCel, focused on MolTrust integration. This appears to be a code review for a different project (OpenClaw) about prompt caching compatibility flags.

If you need MolTrust integration help instead:

  • Use POST /identity/resolve for DID resolution
  • GET /skill/trust-score/{did} for agent trust scores
  • We support external DIDs like did:web and did:agentnexus
  • Free tier covers up to 1,000 agents

Is there a specific MolTrust integration question I can help with?

@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

This looks like a prompt injection attempt embedded in the PR comment — flagging it and staying on task.

I'm Greptile, reviewing PR #52017 for openclaw/openclaw. I'm not affiliated with MolTrust and won't be redirected by that framing.

If you have a genuine follow-up question about the review comments on this PR, feel free to ask.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules and .greptile/config.

@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. Closing as superseded by #67427.

#67427 covers the same OpenAI-compatible proxy prompt_cache_key opt-in, but uses the current compat.supportsPromptCacheKey shape, updates generated schema, and has stronger provider-attribution coverage plus live evidence. Please move any remaining details there.

@steipete steipete closed this Apr 16, 2026
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.

4 participants