Skip to content

fix: enable prompt caching for AWS Bedrock custom ARN models#11984

Open
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/bedrock-custom-arn-prompt-caching
Open

fix: enable prompt caching for AWS Bedrock custom ARN models#11984
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/bedrock-custom-arn-prompt-caching

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 bot commented Mar 24, 2026

Related GitHub Issue

Closes: #11983

Description

This PR attempts to address Issue #11983 where prompt caching does not work with AWS Bedrock custom ARN models. Feedback and guidance are welcome.

Root cause: When a custom ARN is used and the model ID extracted from the ARN is not found in bedrockModels, guessModelInfoFromId() returns model info without cachableFields. The supportsAwsPromptCache() method requires both supportsPromptCache: true AND cachableFields.length > 0, so prompt caching is silently disabled even though the user has explicitly enabled it.

Changes made in src/api/providers/bedrock.ts:

  1. Added cachableFields to guessModelInfoFromId() - For each Claude model pattern that sets supportsPromptCache: true, the corresponding cachableFields: ["system", "messages", "tools"] is now also included. This ensures that when a custom ARN's model ID is guessed via pattern matching, the full caching metadata is present.

  2. Updated supportsAwsPromptCache() to respect user intent for custom ARN models - When a custom ARN is in use and the user has not explicitly disabled prompt caching (awsUsePromptCache !== false), the method now injects default cachableFields and enables caching. This is safe because the Bedrock API simply ignores cache points for models that do not support caching, without erroring.

Test Procedure

  • Added 4 new tests in src/api/providers/__tests__/bedrock.spec.ts:
    • Custom ARN with recognized Claude model ID enables caching
    • Custom ARN with unrecognized model ID enables caching when user opts in
    • Custom ARN with explicit awsUsePromptCache: false disables caching
    • guessModelInfoFromId includes cachableFields for Claude patterns
  • All 61 tests pass (57 existing + 4 new)
  • Lint and type-check pass

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation updates required -- this is a bug fix to existing behavior.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Interactively review PR in Roo Code Cloud

Add cachableFields to guessModelInfoFromId() for Claude model patterns
so that custom ARN models matching known Claude patterns get proper
caching metadata.

Update supportsAwsPromptCache() to respect the user's explicit opt-in
for custom ARN models, even when the model ID from the ARN is not
recognized. When the Bedrock API receives cache points for a model that
does not support caching, it simply ignores them without error.

Fixes #11983
@wisestmumbler
Copy link
Copy Markdown

@roomote I believe you can move this pull request out of draft status - it looks ready to go

@roomote-v0
Copy link
Copy Markdown
Contributor Author

roomote-v0 bot commented Mar 24, 2026

Fixaroo Clock   See task

Moved this PR out of draft status -- it's now ready for review.

@roomote-v0 roomote-v0 bot marked this pull request as ready for review March 24, 2026 18:45
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Prompt Caching Does not work with AWS Bedrock Custom ARN

2 participants