fix(agents): add supportsPromptCache compat opt-in for third-party OpenAI proxies#52017
fix(agents): add supportsPromptCache compat opt-in for third-party OpenAI proxies#52017lanyasheng wants to merge 2 commits into
Conversation
Greptile SummaryThis PR adds a Confidence Score: 5/5Safe 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 |
There was a problem hiding this comment.
💡 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> { | |||
There was a problem hiding this comment.
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.
1d4d525 to
2dc7318
Compare
|
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 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 |
|
April version can see details at https://blog.deepfal.cn/index.php/archives/959/ |
|
@greptile-apps[bot] — The analysis identifies critical issues that need fixing: Priority 1 - Build Breaking:
Priority 2 - Code Consistency:
Recommended Action: |
|
@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:
Is there a specific MolTrust integration question I can help with? |
|
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 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 |
|
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. |
Summary
PR #49877 introduced
shouldStripResponsesPromptCache()to stripprompt_cache_keyandprompt_cache_retentionfrom Responses API payloads when thebaseUrlis 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
supportsPromptCachetoModelCompatConfigtype and Zod schemacompat.supportsPromptCache === trueinshouldStripResponsesPromptCache()before strippingConfiguration 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