Skip to content

fix(bedrock): resolve model name from config for app inference profile cache detection - #63606

Closed
zxkane wants to merge 4 commits into
openclaw:mainfrom
zxkane:fix/bedrock-app-inference-profile-cache
Closed

zxkane wants to merge 4 commits into
openclaw:mainfrom
zxkane:fix/bedrock-app-inference-profile-cache

Conversation

@zxkane

@zxkane zxkane commented Apr 9, 2026

Copy link
Copy Markdown

Summary

Application inference profiles with random IDs (e.g., 7g9cumu1wd7v) are not recognized as Claude models by isAnthropicBedrockModel(), disabling prompt caching. This PR adds model name resolution from provider config as a fallback.

Problem

When using Bedrock application inference profiles for cost tracking, the profile ARN contains a random ID like arn:aws:bedrock:ap-northeast-1:123456:application-inference-profile/7g9cumu1wd7v. The current isAnthropicBedrockModel() checks profileId.includes("claude") which fails, causing:

  1. createBedrockNoCacheWrapper wraps the stream with cacheRetention: "none"
  2. resolveAnthropicCacheRetentionFamily returns undefined
  3. Prompt caching is completely disabled despite the underlying model being Claude

This was noted in the source as a known limitation:

"resolving this would require a GetInferenceProfile call, which is too expensive for a per-request check"

Solution

Instead of calling the Bedrock API, we use the already-available model name from the provider config. The gateway's openclaw.json contains the model definition with a display name (e.g., "Claude Sonnet 4.6 via Inference Profile"), which is accessible via the config parameter in wrapStreamFn.

Changes:

  • isAnthropicBedrockModel() gains optional modelName parameter for name-based fallback
  • resolveModelName() helper looks up display name from provider config (canonical key first, then aliases)
  • baseWrapStreamFn passes config through the chain to enable model name resolution

Changes

File Change
src/agents/pi-embedded-runner/anthropic-family-cache-semantics.ts Add optional modelName param
extensions/amazon-bedrock/register.sync.runtime.ts Add resolveModelName(), pass config through chain
src/agents/pi-embedded-runner/anthropic-family-cache-semantics.test.ts 10 new unit tests
extensions/amazon-bedrock/index.test.ts 4 new integration tests

AI Assistance

This PR was developed with AI assistance (Claude Code). All changes tested locally — 37 tests pass (27 existing + 14 new). The pnpm check has pre-existing failures in unrelated extensions; our 4 files pass oxlint/oxfmt cleanly.

Test plan

  • isAnthropicBedrockModel with direct model IDs (existing behavior preserved)
  • ARN containing "claude" in profile ID (existing behavior)
  • Random profile ID + modelName containing "claude" (new)
  • Random profile ID + no modelName (returns false)
  • Random profile ID + non-Claude modelName (returns false)
  • wrapStreamFn enables caching when config has Claude model name
  • wrapStreamFn disables caching when no config provided
  • Provider alias key resolution
  • GovCloud and China partition ARNs

Fixes #5290

…e cache detection

Application inference profiles with random IDs (e.g., 7g9cumu1wd7v) are not
recognized as Claude models by isAnthropicBedrockModel(), disabling prompt
caching. This adds an optional modelName parameter that the Bedrock extension
populates from the provider config's model list, enabling name-based detection
as a fallback when the profile ID doesn't contain 'claude'.

Fixes the limitation noted in the source:
'resolving this would require a GetInferenceProfile call, which is too
expensive for a per-request check'

Instead, we use the already-available model name from the provider config,
which is populated during gateway provisioning and typically contains the
model name (e.g., 'Claude Sonnet 4.6 via Inference Profile').
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Apr 9, 2026
@greptile-apps

greptile-apps Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a modelName fallback to isAnthropicBedrockModel() so that Bedrock application inference profiles with opaque random IDs (e.g. 7g9cumu1wd7v) are still recognized as Claude models when the provider config supplies a human-readable name. resolveModelName() is added to the Bedrock plugin and config is threaded through the wrapStreamFn chain, preventing createBedrockNoCacheWrapper from being erroneously applied.

  • Incomplete fix: The PR description itself names resolveAnthropicCacheRetentionFamily returning undefined as one of the root causes, but neither resolveAnthropicCacheRetentionFamily (line 90) nor isAnthropicFamilyCacheTtlEligible (line 71) are updated to forward modelName. resolveCacheRetention in prompt-cache-retention.ts returns undefined early when resolveAnthropicCacheRetentionFamily returns undefined, silently discarding any explicit cacheRetention the user set in extraParams. The fix stops active cache-marker stripping but does not enable caching through the retention-family gate.

Confidence Score: 4/5

Safe to merge as a partial improvement, but prompt caching for random-ID inference profiles will still not be fully enabled due to the unpatched resolveAnthropicCacheRetentionFamily gate.

One P1 finding: the PR fixes the wrapStreamFn/createBedrockNoCacheWrapper layer but leaves resolveAnthropicCacheRetentionFamily and isAnthropicFamilyCacheTtlEligible calling isAnthropicBedrockModel without modelName. resolveCacheRetention returns undefined when resolveAnthropicCacheRetentionFamily returns undefined, so explicit user cache config is silently dropped for random-ID profiles — exactly the scenario the PR aims to fix. All other changes (the new parameter, resolveModelName, config threading, tests) are correct and well-tested.

src/agents/pi-embedded-runner/anthropic-family-cache-semantics.ts — the two internal call sites at lines 71 and 90 need modelName plumbed through to complete the fix.

Vulnerabilities

No security concerns identified. The model-name lookup reads only from the caller-supplied config object and performs no external calls or user-controlled code execution.

Comments Outside Diff (1)

  1. src/agents/pi-embedded-runner/anthropic-family-cache-semantics.ts, line 70-73 (link)

    P1 resolveAnthropicCacheRetentionFamily and isAnthropicFamilyCacheTtlEligible not updated with modelName

    Both call sites on lines 71 and 90 still invoke isAnthropicBedrockModel(params.modelId) without the new modelName parameter. The PR description explicitly lists resolveAnthropicCacheRetentionFamily returning undefined as one of the root causes of caching being disabled for random-ID inference profiles — but this path is left unpatched.

    In prompt-cache-retention.ts, resolveCacheRetention returns early with undefined when both family and googleEligible are false (lines 33-35). That means even if the user has an explicit cacheRetention value in extraParams, it is silently dropped for random-ID profiles. The createBedrockNoCacheWrapper fix prevents active stripping of cache markers, but resolveCacheRetention never reaches the user-supplied value check because the gate on resolveAnthropicCacheRetentionFamily still fails.

    To complete the fix, isAnthropicFamilyCacheTtlEligible and resolveAnthropicCacheRetentionFamily need to accept an optional modelName and pass it through to isAnthropicBedrockModel. The call sites in cache-ttl.ts and prompt-cache-retention.ts would then need to supply a resolved model name when one is available.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/pi-embedded-runner/anthropic-family-cache-semantics.ts
    Line: 70-73
    
    Comment:
    **`resolveAnthropicCacheRetentionFamily` and `isAnthropicFamilyCacheTtlEligible` not updated with `modelName`**
    
    Both call sites on lines 71 and 90 still invoke `isAnthropicBedrockModel(params.modelId)` without the new `modelName` parameter. The PR description explicitly lists `resolveAnthropicCacheRetentionFamily` returning `undefined` as one of the root causes of caching being disabled for random-ID inference profiles — but this path is left unpatched.
    
    In `prompt-cache-retention.ts`, `resolveCacheRetention` returns early with `undefined` when both `family` and `googleEligible` are false (lines 33-35). That means even if the user has an explicit `cacheRetention` value in `extraParams`, it is silently dropped for random-ID profiles. The `createBedrockNoCacheWrapper` fix prevents *active stripping* of cache markers, but `resolveCacheRetention` never reaches the user-supplied value check because the gate on `resolveAnthropicCacheRetentionFamily` still fails.
    
    To complete the fix, `isAnthropicFamilyCacheTtlEligible` and `resolveAnthropicCacheRetentionFamily` need to accept an optional `modelName` and pass it through to `isAnthropicBedrockModel`. The call sites in `cache-ttl.ts` and `prompt-cache-retention.ts` would then need to supply a resolved model name when one is available.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/anthropic-family-cache-semantics.ts
Line: 70-73

Comment:
**`resolveAnthropicCacheRetentionFamily` and `isAnthropicFamilyCacheTtlEligible` not updated with `modelName`**

Both call sites on lines 71 and 90 still invoke `isAnthropicBedrockModel(params.modelId)` without the new `modelName` parameter. The PR description explicitly lists `resolveAnthropicCacheRetentionFamily` returning `undefined` as one of the root causes of caching being disabled for random-ID inference profiles — but this path is left unpatched.

In `prompt-cache-retention.ts`, `resolveCacheRetention` returns early with `undefined` when both `family` and `googleEligible` are false (lines 33-35). That means even if the user has an explicit `cacheRetention` value in `extraParams`, it is silently dropped for random-ID profiles. The `createBedrockNoCacheWrapper` fix prevents *active stripping* of cache markers, but `resolveCacheRetention` never reaches the user-supplied value check because the gate on `resolveAnthropicCacheRetentionFamily` still fails.

To complete the fix, `isAnthropicFamilyCacheTtlEligible` and `resolveAnthropicCacheRetentionFamily` need to accept an optional `modelName` and pass it through to `isAnthropicBedrockModel`. The call sites in `cache-ttl.ts` and `prompt-cache-retention.ts` would then need to supply a resolved model name when one is available.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(bedrock): resolve model name from co..." | Re-trigger Greptile

Address review: isAnthropicFamilyCacheTtlEligible and
resolveAnthropicCacheRetentionFamily now accept optional modelName
and forward it to isAnthropicBedrockModel, completing the fix for
random-ID inference profiles through the cache retention pipeline.

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

Copy link
Copy Markdown
Contributor

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: b3539f3832

ℹ️ 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".

zxkane added 2 commits April 9, 2026 15:59
…etention

Address Codex review: pass model.name to resolveCacheRetention and
isCacheTtlEligibleProvider at all runtime call sites in extra-params.ts,
attempt.ts, extensions.ts, and attempt.thread-helpers.ts so that
random-ID inference profiles are correctly detected as Claude models
through the entire cache retention pipeline.
@zxkane

zxkane commented Apr 9, 2026

Copy link
Copy Markdown
Author

CI note: The checks-node-test failure is a pre-existing flaky test on main — src/gateway/server.cron.test.ts > returns from cron.run immediately while isolated work continues in background (timeout).

Main branch recent CI runs also fail with the exact same test:

  • 24180945435 (main, ab49afcd) — checks-node-test failed, same timeout
  • 24180594846 (main, 89acb920) — checks-node-test failed, same timeout
  • 24180440522 (main, 38100a09) — checks-node-test failed, same timeout

All 2203 other tests pass. Our changes only touch anthropic-family-cache-semantics.ts, prompt-cache-retention.ts, cache-ttl.ts, extra-params.ts, attempt.ts, extensions.ts, attempt.thread-helpers.ts, and the bedrock extension — none related to gateway server cron.

@clawsweeper

clawsweeper Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

This PR is superseded by the merged Bedrock prompt-caching implementation in #69953. Current main no longer relies on a configured display-name fallback for opaque application inference profile ARNs; it resolves the profile through Bedrock GetInferenceProfile, caches successful eligibility results, injects Bedrock cache points only when all routed targets support them, and preserves explicit cache-retention settings for opaque app-profile ARNs.

Best possible solution:

Close this PR as superseded by #69953 and keep the shipped GetInferenceProfile-based implementation. It is more reliable than a display-name fallback because it validates the actual routed Bedrock foundation model before injecting cache points; any remaining cache-ttl-only improvement should be tracked separately.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 2dba9e6a765a; fix evidence: release v2026.4.24, commit 24266af1ce1b.

@clawsweeper clawsweeper Bot closed this Apr 27, 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: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bedrock Auto Discovery fails to retrieve or support Inference Profile IDs of Models.

1 participant