Skip to content

fix(anthropic): apply the live sampling and tool-choice contract to every Claude family - #6217

Merged
lidge-jun merged 3 commits into
devfrom
codex/claude-contract-hardening
Sep 28, 2026
Merged

lidge-jun merged 3 commits into
devfrom
codex/claude-contract-hardening

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

A live probe of api.anthropic.com (2026-09-29, one field per request) showed the Claude request rules added with Sonnet 5.5 in #6210 were narrower than what Anthropic enforces. Requests the adapter builds today fail with 400 on current models:

Request Families Before After
temperature/top_p with no reasoning Opus 4.7+, Sonnet 5+, every Fable forwarded → 400 "temperature is deprecated" dropped → 200
temperature + top_p together Haiku 4.5, Sonnet 4.5/4.6, Opus 4.5/4.6 both → 400 "cannot both be specified" top_p dropped → 200
tool choice required / named Fable 5.1 any → 400 auto → 200 (same downgrade as Opus 5.5 / Sonnet 5.5)
web-search / vision sidecar pointed at the model Opus 5.5, Fable thinking: disabled → 400 output_config.effort: low, no thinking → 200

Both off switches (disabled and between_tools) are rejected by Opus 5.5 and Fable; with a low effort they still ended their turn with visible text inside the vision sidecar's 1,024-token budget. The rules stay in src/adapters/anthropic-model-contract.ts. Older ids that were not measured (claude-3-7-sonnet, claude-opus-4-20250514) keep both sampling fields.

Not changed, and why: the Messages-native passthrough keeps forwarding caller fields (its contract, structure/data-planes/protocol-paths.md); dotted Bedrock ids still do not parse, but no direct Bedrock adapter reaches anthropic.ts. Plan, audit and evidence: devlog/_plan/260929_dev_next_hardening_carry/.

Verification

  • Live, adapter-built requests after the change: temperature+top_p, required tool choice and the sidecar off switch return 200 on Opus 5.5, Fable 5.1, Fable 5, Opus 5, Sonnet 5, Sonnet 5.5, Opus 4.8 and Haiku 4.5.
  • bun test on the contract, reasoning, tool-choice, passthrough, web-search, vision, file-size ratchet and test-layout files: 152 pass / 0 fail. Every file in tests/adapters/anthropic, tests/web-search, tests/vision and the two Claude Messages endpoint files passes when run on its own.
  • bun run typecheck, bun run structure:check, bun run privacy:scan: pass.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

…very Claude family

A live probe of api.anthropic.com on 2026-09-29 showed the Sonnet 5.5 rules
from #6210 were narrower than the upstream contract:

- Opus 4.7+, Sonnet 5+ and every Fable return 400 on any non-default
  temperature/top_p, with or without thinking. The adapter only dropped them
  when it sent thinking, so a no-reasoning request with temperature failed.
- Haiku 4.5, Sonnet 4.5/4.6 and Opus 4.5/4.6 take either field alone but 400
  when both are sent; top_p is now dropped when both are present.
- Fable 5.1 rejects forced tool_choice like Opus 5.5; it now degrades to auto.
- Opus 5.5 and Fable reject both thinking disabled and between_tools, so the
  web-search and vision sidecars send a low effort and no thinking field for
  them (verified to end_turn with text inside a 1,024-token budget).

Plan, audit and evidence: devlog/_plan/260929_dev_next_hardening_carry/.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 28, 2026 23:23
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun
lidge-jun merged commit 08a8517 into dev Sep 28, 2026
8 of 9 checks passed
@lidge-jun
lidge-jun deleted the codex/claude-contract-hardening branch September 28, 2026 23:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T23:26:19.022451Z 70c8c3f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the bug Something isn't working label Sep 28, 2026
@coderabbitai

coderabbitai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 5d848652-3b2f-4a16-ab50-8dc0b26329bf

📥 Commits

Reviewing files that changed from the base of the PR and between a118fcc and 70c8c3f.

📒 Files selected for processing (10)
  • devlog/_plan/260929_dev_next_hardening_carry/010_plan.md
  • devlog/_plan/260929_dev_next_hardening_carry/030_done_wp2.md
  • src/adapters/anthropic-model-contract.ts
  • src/adapters/anthropic.ts
  • src/vision/anthropic-describe.ts
  • src/web-search/anthropic-executor.ts
  • structure/providers-and-adapters.md
  • structure/providers/chat-compat.md
  • tests/adapters/anthropic/anthropic-reasoning.test.ts
  • tests/adapters/anthropic/anthropic-sonnet-5-5-contract.test.ts
 _____________________
< I've git the power! >
 ---------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Copy link
Copy Markdown

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: 70c8c3f695

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

Comment thread src/adapters/anthropic.ts
Comment on lines +1068 to +1070
} else if (body.temperature !== undefined && body.top_p !== undefined && rejectsCombinedSampling(parsed.modelId)) {
// The 4.5/4.6 families take either field alone but 400 on both; temperature is the one kept.
delete body.top_p;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the non-default sampler when resolving conflicts

When a 4.5/4.6-family request explicitly carries the default temperature: 1 together with a non-default top_p (for example, 0.9), this branch always deletes top_p, silently discarding the caller's only effective sampling adjustment. Since these models accept either field alone, omit temperature when it is the default and preserve top_p; conversely, keep the current behavior when top_p is the default or both values are non-default.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant