Repository navigation
fix(core): spell Claude variants for Bedrock application inference profile ARNs - #65472
JamieJ5926 wants to merge 3 commits into
Conversation
…ofile ARNs A Bedrock application inference profile ARN (arn:aws:bedrock:...:application-inference-profile/...) carries no Anthropic marker and no Claude version, so bedrockConverse fell through to the Amazon Nova reasoningConfig spelling for Claude models. claudeInfo also parsed only the model ID, ignoring model.family, which names the Claude model an ARN points at. - claudeInfo now falls back to matching model.family when the model ID carries no Claude family/version, so ARNs resolve manual vs adaptive thinking from the family. - bedrockConverse detects Claude when the ID mentions anthropic, when claudeInfo extracted a family, or when model.family names Claude. Source: none (new code) Co-authored-by: Jo Hughes <284454611+JamieJ5926@users.noreply.github.com>
There was a problem hiding this comment.
This fixes the main bug. With an ARN modelID and a Claude family, Bedrock variants now use Claude's thinking/output_config instead of Nova's reasoningConfig. I checked this by resolving variants for an ARN model with family claude-sonnet/claude-opus on the base and on this branch, and by running the new test against the base (it fails there) and on this branch (all 19 tests pass). tsc -b passes. I could not send a real Bedrock request.
Public API: unchanged. family is an existing model field. This only changes how it is read.
Concerns:
- The
claudeInfofallback only helps iffamilyincludes a version such asclaude-sonnet-4-5. Catalog families never do (claude-sonnet,claude-opus, ...). The issue's own setup (an ARN for Sonnet 4.5 withfamily: "claude-sonnet") still gets adaptive thinking, which that model needs replaced by a budget. The issue reporter noted the same thing in #53756. Either drop the fallback and keep the fix to the Claude check, or document that a versionedfamilyis the way to pick budget thinking for a profile ARN. See the inline comment. - The new test can be trimmed. See the inline comment.
Related: #53751
| // model.family, which names the Claude model an ARN points at. | ||
| const idMatch = match(id) | ||
| const { familyFirst, versionFirst } = | ||
| idMatch.familyFirst ?? idMatch.versionFirst ? idMatch : match(model.family ?? "") |
There was a problem hiding this comment.
This fallback only matches a family that includes a version (claude-sonnet-4-5). Catalog and models.dev families never include one (claude-sonnet, claude-opus, claude-haiku). For the setup in #53756 (an ARN for Sonnet 4.5 with family: "claude-sonnet"), major is still NaN, so manual is false and Bedrock gets adaptive thinking for a 4.5 model. It also now applies to every caller of claudeInfo (Anthropic Messages, GitLab), not just Bedrock. I'd either drop it and keep the PR to the Claude check in bedrockConverse, or make the versioned-family convention explicit, e.g. documented with a test that uses the catalog-style claude-sonnet and shows what it produces.
There was a problem hiding this comment.
Dropping the fallback — the first option. Reproduced the concern first on 96beccd, with the issue's own setup (the #53756 ARN for Sonnet 4.5, catalog-style family: "claude-sonnet"):
$ bun test test/variant-arn-repro.test.ts # packages/core
(fail) repro: ARN with versionless family claude-sonnet still gets adaptive thinking [0.93ms]
- Expected - 0
+ Received + 4
"body": {
"additionalModelRequestFields": {
"output_config": {
"effort": "low",
},
+ "thinking": {
+ "display": "summarized",
+ "type": "adaptive",
+ },
As you said: the regexes need a version, so major stays NaN, manual is false, and Bedrock got adaptive thinking for a 4.5 model.
4b0e6d0 removes the fallback: claudeInfo is back to parsing the model ID only (so Anthropic Messages and GitLab callers are unaffected), and the fix stays scoped to the Claude check in bedrockConverse, where model.family now only detects Claude — a comment there states that the family's version is never parsed. Stated plainly, the resulting behavior for a profile ARN: the family switches the spelling from Nova's reasoningConfig to Claude's, and with a versionless family that spelling is adaptive effort, never budget thinking.
| { id: "low", body: { additionalModelRequestFields: { output_config: { effort: "low" } } } }, | ||
| ]) | ||
|
|
||
| expect(resolve(arnModel("claude"), [{ type: "toggle" }])).toEqual([ |
There was a problem hiding this comment.
The test can be shorter. The claude toggle and budget cases only exercise branches that already follow from claude being true. The Nova check below is already covered by the existing "spells Bedrock Converse effort for Grok and Nova" test. One effort assertion with the catalog-style family (claude-sonnet) would test what users actually configure, plus a versioned one if you keep the fallback.
There was a problem hiding this comment.
Shortened to one effort assertion with the catalog-style family, per your note (3bfa08a):
test("spells Claude variants for a Bedrock application inference profile ARN", () => {
const arn = "arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123"
// The ARN carries no Anthropic marker, so model.family detects Claude; the ARN carries no
// Claude version either, so the effort spelling is adaptive rather than budget thinking.
expect(
resolve(model("@opencode/ai/providers/amazon-bedrock", arn, undefined, "test", "claude-sonnet"), [
{ type: "effort", values: ["low"] },
]),
).toEqual([
{
id: "low",
body: {
additionalModelRequestFields: {
thinking: { type: "adaptive", display: "summarized" },
output_config: { effort: "low" },
},
},
},
])
})The claude toggle and budget cases are gone, and the Nova contrast is dropped — it is already covered by "spells Bedrock Converse effort for Grok and Nova". 53 lines → 20.
$ bun test test/variant.test.ts # packages/core
19 pass
0 fail
71 expect() calls
Ran 19 tests across 1 file. [162.00ms]
There was a problem hiding this comment.
Thanks. I checked the trimmed test at 3bfa08a: it fails on the base (Nova reasoningConfig) and passes here, and it's a clear check of the fixed behaviour. Nothing more needed on the test from my side.
Review 6008486374 on PR 65472: the family fallback in claudeInfo only matches versioned families, so the issue's own setup - a Bedrock application inference profile ARN for Sonnet 4.5 with the versionless family "claude-sonnet" - still spelled adaptive thinking for a model that takes budget thinking. Drop the fallback: claudeInfo parses the model ID only, and the PR's fix stays scoped to the Claude check in bedrockConverse, where model.family only detects Claude and never resolves manual vs adaptive thinking. The ARN test keeps the issue's setup (adaptive Claude spelling, not Nova reasoningConfig) plus the Nova contrast, and drops the three assertions that only pinned the fallback. Source: none (new code) Co-authored-by: Jo Hughes <284454611+JamieJ5926@users.noreply.github.com>
…mily case Review 4655210470: the Nova contrast is already covered by the existing "spells Bedrock Converse effort for Grok and Nova" test. One effort assertion with the catalog-style family "claude-sonnet" is what users actually configure. Source: none (new code) Co-authored-by: Jo Hughes <284454611+JamieJ5926@users.noreply.github.com>
There was a problem hiding this comment.
My earlier concerns are resolved. The claudeInfo fallback is gone, so it is identical to the base again and the Anthropic Messages and GitLab callers are unaffected. The test is now one clear catalog-style case. I checked that the new test fails on the base (Nova reasoningConfig) and passes here, the whole variant test file passes (19 tests), and tsc -b is clean. I could not send a real Bedrock request.
Public API: unchanged. The existing family model field is only read here to detect Claude.
The remaining limitation is the one now stated in the code comment, and I don't think it blocks this fix. With a versionless family, a Claude 4.5-or-older model behind an ARN gets adaptive thinking instead of a token budget. For that case, the workarounds in #53756 still apply: use the catalog id as the model key, or declare variants explicitly.
Related: #53751
Issue for this PR
Closes #53756
Type of change
What does this PR do?
For Bedrock,
bedrockConversedecided Claude vs. Nova purely fromid.includes("anthropic"). Whenmodel.modelIDis an AWS application inference profile ARN (arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123) — the shape Bedrock returns for inference profiles — that check is false, so a Claude model got the Amazon Nova Converse spelling (reasoningConfig: { type: "enabled", maxReasoningEffort }) instead of Claude'sthinking+output_config: { effort }. On top of that,claudeInfoonly parsedmodelID, so it could not recover the Claude family/version frommodel.family, which is where the ARN's target model is actually named (e.g.claude-sonnet-4-5needs manual budget thinking;claude-opus-4-6uses adaptive thinking).Two changes in
packages/core/src/variant.ts:claudeInfomatches the family/version regexes against the model ID first and falls back tomodel.familywhen the ID carries no Claude version, so an ARN resolves manual vs. adaptive thinking from its family.bedrockConversetreats a model as Claude when the ID mentionsanthropic, whenclaudeInfoextracted a family, or whenmodel.familynames Claude.Non-ARN IDs (e.g.
us.anthropic.claude-...) take the same path as before because the ID match still wins; Nova IDs match nothing and keepreasoningConfig.How did you verify your code works?
Added
packages/core/test/variant.test.tscase "spells Claude variants for a Bedrock application inference profile ARN" covering effort, toggle andbudget_tokensfor familiesclaude-opus-4-6,claude-sonnet-4-5andclaude, plus a Nova regression check.Failing before the fix (ARN +
claude-opus-4-6):Passing after:
cd packages/core && bun test test/variant.test.ts:bun run typecheckinpackages/core:✓ No type errors in 1,968 files across 2 projects.Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #53751