Repository navigation
feat(bedrock): add inference profile discovery and region injection - #61299
Conversation
Greptile SummaryThis PR adds inference profile discovery (cross-region and application) to the Amazon Bedrock provider and injects the resolved AWS region into stream calls so the SDK client connects to the correct regional endpoint.
Confidence Score: 4/5Safe to merge after fixing the provider filter ARN parsing bug; all other logic is sound. The P1 bug in the inference profile provider filter causes all inference profiles to be dropped when providerFilter is configured, directly breaking the primary use-case for users with filtered Bedrock deployments. All other changes (region injection, capability inheritance, graceful degradation, cache handling) are correct. extensions/amazon-bedrock/discovery.ts line 246 — the ARN split index must change from [0] to [1]. Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/amazon-bedrock/discovery.ts
Line: 245-247
Comment:
**Provider filter always evaluates `"foundation-model"` for inference profiles**
The ARN is split at `"/"` and index `[0]` is taken — the prefix segment `"arn:aws:bedrock:us-east-1::foundation-model"`. Calling `.split(":").pop()` on that prefix yields `"foundation-model"`, not the actual provider. This means `matchesFilter` is always `false` when a `providerFilter` like `["anthropic"]` is set, so **every inference profile is silently dropped**.
The fix is to index into segment `[1]` (the part after the `/`), which contains `"anthropic.claude-sonnet-4-6"`, and split on `.` to extract the provider:
```suggestion
const provider = m.modelArn?.split("/")?.[1]?.split(".")?.[0];
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/anthropic-family-cache-semantics.ts
Line: 24-29
Comment:
**Application inference profile Claude detection is name-heuristic only**
`isAnthropicBedrockModel` returns `true` for any application inference profile whose user-supplied name contains `"claude"`, and `false` for any profile whose name does not — even if it routes to a Claude model. A profile named `"my-prod-assistant"` over Claude would bypass prompt-caching semantics, while a non-Claude profile named `"my-claude-compat-llama"` would incorrectly get them. Consider documenting this limitation in a code comment so future maintainers know the constraint is intentional.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(bedrock): add inference profile dis..." | Re-trigger Greptile |
7e124b2 to
b4a996b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5357525cbe
ℹ️ 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".
b4a996b to
e5f7710
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5f7710d35
ℹ️ 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".
Inference profiles (cross-region and application) work with ConverseStream
but require the SDK client region to match the profile region. Without
this, users get "The provided model identifier is invalid" errors when
using cross-region profiles like us.anthropic.claude-sonnet-4-6.
Changes:
1. Inference profile discovery (discovery.ts):
- Call ListInferenceProfiles alongside ListFoundationModels (parallel)
- Inference profiles INHERIT capabilities from their underlying
foundation model (modalities, reasoning, context window, cost)
- resolveBaseModelId() maps profile → foundation model:
"us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6"
Application ARNs → extract model ID from models[].modelArn
- Graceful degradation if IAM lacks bedrock:ListInferenceProfiles
- Provider filter applies to profiles via underlying model ARNs
2. Region injection (register.sync.runtime.ts):
- Extract region from provider baseUrl or bedrockDiscovery.region
- Pass through to pi-ai options.region in wrapStreamFn
- Ensures SDK client connects to correct regional endpoint
3. Inference profile model detection (anthropic-family-cache-semantics.ts):
- isAnthropicBedrockModel() now recognizes application inference
profile ARNs (arn:aws:bedrock:...:application-inference-profile/*)
4. Tests (discovery.test.ts):
- New: inference profile inheritance test (4 models: 1 foundation +
3 profiles, verifies capability inheritance, inactive filtering)
- New: graceful AccessDeniedException handling test
- Updated: all existing tests for dual-API discovery pattern
Fixes openclaw#55642
e5f7710 to
e1b0db1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1b0db140b
ℹ️ 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".
| const exact = (providers[providerId] as { baseUrl?: string } | undefined)?.baseUrl; | ||
| if (exact) { | ||
| const region = extractRegionFromBaseUrl(exact); | ||
| if (region) return region; |
There was a problem hiding this comment.
Use active provider config when resolving Bedrock region
The region injector ignores the provider key from wrapStreamFn context and always reads models.providers["amazon-bedrock"] first. In configs that keep both legacy and canonical keys (for example bedrock and amazon-bedrock) with different baseUrl regions, calls made through the alias can be forced to the wrong region and fail with Bedrock "invalid model identifier" errors for inference profiles. Resolve region from the currently selected provider key first, then fall back to normalized aliases.
Useful? React with 👍 / 👎.
| } catch (error) { | ||
| log.debug?.("Skipping inference profile discovery", { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| }); | ||
| return []; | ||
| } |
There was a problem hiding this comment.
Re-throw non-permission inference-profile discovery errors
fetchInferenceProfileSummaries swallows all exceptions and returns an empty list, but the caller treats that as a successful discovery and caches it for the full refresh interval. A transient Bedrock/API failure (throttling, network, endpoint issues) will therefore silently remove all inference profiles from discovery for up to an hour instead of surfacing an error. This should only suppress expected authorization failures (as the comment describes) and re-throw other error classes.
Useful? React with 👍 / 👎.
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
Prompt caching broken for application inference profiles with random IDsHi @wirjo — thanks for landing this PR! It fixed the region injection and basic inference profile support, but we've found that prompt caching is still completely disabled for application inference profiles with random IDs (e.g., Root Cause
The net result: 0% cache hit rate, even though Bedrock Converse API fully supports prompt caching for Sonnet 4.6 via application inference profiles. We verified this with Bedrock invocation logs — ImpactFor our deployment (~2,800 invocations/day across 4 stacks), this means ~$150-300/day in avoidable input token costs. With caching enabled we measured 99% cache hit rate and ~50% cost reduction. Fix PRWe've submitted #63606 which:
The approach uses the model display name from Workaround (current)For anyone hitting this before the fix lands:
|
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
…penclaw#61299) * feat(bedrock): add inference profile discovery and region injection Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6. Changes: 1. Inference profile discovery (discovery.ts): - Call ListInferenceProfiles alongside ListFoundationModels (parallel) - Inference profiles INHERIT capabilities from their underlying foundation model (modalities, reasoning, context window, cost) - resolveBaseModelId() maps profile → foundation model: "us.anthropic.claude-sonnet-4-6" → "anthropic.claude-sonnet-4-6" Application ARNs → extract model ID from models[].modelArn - Graceful degradation if IAM lacks bedrock:ListInferenceProfiles - Provider filter applies to profiles via underlying model ARNs 2. Region injection (register.sync.runtime.ts): - Extract region from provider baseUrl or bedrockDiscovery.region - Pass through to pi-ai options.region in wrapStreamFn - Ensures SDK client connects to correct regional endpoint 3. Inference profile model detection (anthropic-family-cache-semantics.ts): - isAnthropicBedrockModel() now recognizes application inference profile ARNs (arn:aws:bedrock:...:application-inference-profile/*) 4. Tests (discovery.test.ts): - New: inference profile inheritance test (4 models: 1 foundation + 3 profiles, verifies capability inheritance, inactive filtering) - New: graceful AccessDeniedException handling test - Updated: all existing tests for dual-API discovery pattern Fixes openclaw#55642 * fix(bedrock): preserve inference profile model lookup --------- Co-authored-by: Vincent Koc <[email protected]>
Inference profiles (cross-region and application) work with ConverseStream but require the SDK client region to match the profile region. Without this, users get "The provided model identifier is invalid" errors when using cross-region profiles like us.anthropic.claude-sonnet-4-6.
Changes:
Inference profile discovery (discovery.ts):
Region injection (register.sync.runtime.ts):
Inference profile model detection (anthropic-family-cache-semantics.ts):
Tests (discovery.test.ts):
Fixes #55642