Repository navigation
fix(amazon-bedrock): inject cache points for application inference profile ARNs - #69953
Conversation
6a09a14 to
6f605ce
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a09a14f57
ℹ️ 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".
Greptile SummaryThis PR fixes prompt caching for Bedrock application inference profile ARNs by injecting Confidence Score: 5/5Safe to merge — only P2 findings remain, and prior P1 concerns from the thread have been addressed with a clarifying comment. Both findings are P2 quality/maintenance concerns (duplicated logic and error-caching behavior). Correctness is protected by the hasCachePoint double-injection guard, cacheRetention: none is respected, and the 7 new test cases cover the key scenarios. No files require special attention — the implementation is self-contained in register.sync.runtime.ts. Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/amazon-bedrock/register.sync.runtime.ts
Line: 146-161
Comment:
**Duplicated caching model patterns risk silent drift**
`resolvedModelSupportsCaching` (lines 146–161) contains identical pattern-matching logic to `piAiWouldInjectCachePoints` (lines 74–92). They're used on different inputs (resolved model ARN vs profile ARN), but because they're separate, an update to one (e.g., adding `claude-3-5-sonnet`) won't automatically apply to the other. This means the slow API-resolution path and the heuristic fast path could silently make different caching decisions for the same underlying model.
Consider extracting the shared patterns into a single private helper (`matchesCacheableClaude(id: string): boolean`) and having both functions delegate to it.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: extensions/amazon-bedrock/register.sync.runtime.ts
Line: 193-198
Comment:
**Transient API errors are permanently cached**
When `GetInferenceProfile` fails, the catch block stores the heuristic result (`isAnthropicBedrockModel(modelId)`) in `appProfileCacheEligibleCache` with `appProfileCacheEligibleCache.set(modelId, fallback)`. For a truly opaque non-Anthropic profile ARN, `isAnthropicBedrockModel` returns `false`, so this negative result is cached for the entire session — a transient network blip on the first call silently disables cache injection for that ARN until the process restarts.
Consider skipping the cache write on error (so the next request retries), or at minimum logging a warning so the failure isn't invisible.
How can I resolve this? If you propose a fix, please make it concise.Reviews (3): Last reviewed commit: "fix(amazon-bedrock): inject cache points..." | Re-trigger Greptile |
6f605ce to
ed20293
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed2029308a
ℹ️ 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".
ed20293 to
fd84704
Compare
|
LGTM |
|
Addressed the review feedback — |
ac1746d to
e0cff7b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0cff7b17a
ℹ️ 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".
e0cff7b to
eb17301
Compare
eb17301 to
3f85f86
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb173011ff
ℹ️ 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".
3f85f86 to
1904f71
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1904f71d9e
ℹ️ 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".
1904f71 to
0f49706
Compare
0f49706 to
cda7be8
Compare
|
The parity preflight failure ( |
cda7be8 to
16194d4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16194d4bfc
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b786f1478b
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| onPayload: async (payload: unknown, payloadModel: unknown) => { | ||
| const eligible = await resolveAppProfileCacheEligible(modelId, region); | ||
| if (eligible && payload && typeof payload === "object") { |
There was a problem hiding this comment.
Skip profile lookup when cacheRetention is none
When an opaque application inference profile is used with cacheRetention: "none", this async onPayload path still calls resolveAppProfileCacheEligible(...) on every request before deciding whether to inject cache points. Because injection is disabled anyway for none, these control-plane lookups are unnecessary and can add avoidable latency (and repeated failed calls when GetInferenceProfile is throttled/unauthorized, since catch-path failures are intentionally not cached). Short-circuiting before the lookup when retention is none would preserve the new behavior without the extra request cost.
Useful? React with 👍 / 👎.
…ofile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925
b786f14 to
ba85b03
Compare
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…ofile ARNs (openclaw#69953) * fix(amazon-bedrock): inject cache points for application inference profile ARNs pi-ai's internal supportsPromptCaching checks model.id for specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles. Work around this by detecting when pi-ai would miss cache point injection (via piAiWouldInjectCachePoints mirror) and patching the Converse API payload via onPayload to add cachePoint blocks to the system prompt and last user message — matching the same format pi-ai uses natively. The fix is safe: - Checks for existing cache points to avoid double-injection - Respects cacheRetention: "none" - Defaults to "short" retention (matching pi-ai default) - Becomes a no-op once upstream pi-mono#2925 is fixed Fixes openclaw#19279 Upstream: earendil-works/pi#2925 * fix(amazon-bedrock): tighten app-profile cache injection --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
Summary
Fixes #19279
Upstream: earendil-works/pi#2925
pi-ai's internal
supportsPromptCachingchecksmodel.idfor specific Claude model name patterns (e.g. "-4-", "claude-3-7-sonnet"), which fails for application inference profile ARNs that don't contain the model name. This causes prompt caching to silently break for Bedrock users with application inference profiles.Changes
extensions/amazon-bedrock/register.sync.runtime.tspiAiWouldInjectCachePoints()— mirrors pi-ai's detection logic to know when the upstream library handles caching on its ownneedsCachePointInjection()— identifies the gap: models that OpenClaw'sisAnthropicBedrockModel()recognizes as Anthropic but pi-ai won'tinjectBedrockCachePoints()— patches the Converse API payload viaonPayloadto addcachePointblocks to the system prompt and last user message, matching the same format pi-ai uses nativelywrapStreamFnto usestreamWithPayloadPatchfor these modelsextensions/amazon-bedrock/index.test.tsSafety
cacheRetention: "none"piAiWouldInjectCachePointscheck will match, soneedsCachePointInjectionreturns false)