Skip to content

fix(anthropic): pair native beta schemas with effective headers - #7132

Merged
lidge-jun merged 2 commits into
devfrom
fix/7102-anthropic-beta-pairing
Oct 15, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/7102-anthropic-beta-pairing

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Fixes native Messages requests that retained thinking.block_binding while PF-10 dropped its required beta, causing Anthropic's Extra inputs are not permitted 400. Closes Native Messages lane forwards thinking.block_binding but drops its beta → 400 Extra inputs are not permitted #7102.
  • One schema-pairing table now drives generic/native-client beta admission and copy-on-write body reconciliation after the final header merge. First-party Anthropic key and OAuth requests may forward thinking-binding controls; missing betas, incompatible thinking modes, Bedrock/Vertex endpoints, and third-party compatible destinations strip the nested field. Context management keeps its native-client caller policy and OAuth tool-name rewriting; trusted operator betas participate in pairing on first-party destinations.
  • Header-only thinking controls remain valid for diagnostics. Responses translation builds its own thinking configuration and cannot copy the native controls. Updated public and structure documentation; no provider presets, credentials, configuration, dependencies, or CI policy changed.
  • Primary contract: Anthropic preserved thinking requires the beta for block_binding, accepts adaptive/enabled thinking, and permits header-only transformation diagnostics. Platform-specific beta transport is documented in beta headers. First-party OAuth uses the existing Messages schema allowance; no paid live credential probe was performed.

Verification

  • Regression proof: bun test tests/adapters/anthropic/anthropic-beta-body-pairs.test.ts before implementation: 2 pass / 14 fail. After implementation, the new file and existing allowlist file: 33 pass / 0 fail.
  • bun run typecheck — passed.
  • bun test tests/adapters/anthropic/anthropic-beta-body-pairs.test.ts tests/adapters/anthropic/anthropic-beta-allowlist.test.ts tests/adapters/anthropic/anthropic-messages-passthrough.test.ts tests/adapters/anthropic/anthropic-messages-passthrough-oauth.test.ts tests/claude-integration/messages-native.test.ts — 172 pass / 0 fail.
  • bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts — 36 pass / 0 fail.
  • bun run structure:check — passed (both affected structure documents remain within their 600-line budgets).
  • bun run privacy:scan — passed.
  • cd docs-site && bun install --frozen-lockfile && bun run build — passed; 577 pages, 81,200 internal links checked.
  • bun run test:changed — 4,242 pass / 30 skip / 0 fail, across 187 files (exit 0). The shared-machine queue cleared; suite execution took 75.9 seconds.
  • Full bun run test intentionally omitted: multiple triage worktrees share one 16-core machine, as required by this task's resource exception. The focused files exercise final serialized bodies/headers, key/OAuth, compatible/cloud destinations, beta diagnostics, source immutability, context-tool rewrites, and translated-lane isolation. Broader coverage remains with Ubuntu PR CI; no macOS/Windows workflow dispatched.

Independent review round 1 (head 49c7773e7f328fdfa3e9454831eeae244cc94288):

  • Reviewed Native Messages lane forwards thinking.block_binding but drops its beta → 400 Extra inputs are not permitted #7102, all nine changed files, owning structure contracts, credential-destination isolation, logging, translated-lane isolation, registration, size budgets, public docs, and PR-template completeness. No actionable code defects found; no source changes or review commits. PR draft state preserved.
  • Independently reproduced regression sensitivity: temporarily restored src/adapters/anthropic/beta-allowlist.ts and src/adapters/anthropic/passthrough.ts to the parent commit, then ran bun test tests/adapters/anthropic/anthropic-beta-body-pairs.test.ts: 2 pass / 14 fail. Restored HEAD and reran the same file: 16 pass / 0 fail. Working tree is clean.
  • bun test tests/adapters/anthropic/anthropic-beta-body-pairs.test.ts tests/adapters/anthropic/anthropic-beta-allowlist.test.ts tests/adapters/anthropic/anthropic-messages-passthrough.test.ts tests/adapters/anthropic/anthropic-messages-passthrough-oauth.test.ts tests/claude-integration/messages-native.test.ts — 172 pass / 0 fail.
  • bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/lab/core-lab-boundary.test.ts — 61 pass / 0 fail.
  • bun run typecheck, bun run structure:check, and bun run privacy:scan — passed. Initial typecheck/setup attempt could not run because Bun's package postinstall had been skipped; ran node node_modules/bun/install.js and then successfully executed the required commands. No dependency files changed.
  • Investigated the existing Codex counting comment at src/adapters/anthropic/passthrough.ts:318-319. The count helper's configuration shape differs, but estimateClaudeRequestTokens (src/server/claude-messages.ts:1653-1697) reads only system/messages/tools; neither paired configuration field contributes. Scratch probe bun /tmp/review-7132-count.ts compared actual builder bodies with nativeMessagesCountBody across 32 key/OAuth, caller-beta, oversized-beta, and operator-beta combinations: all estimates equal. No user-visible count defect reproduced; avoided unrelated count-path refactoring.
  • Verified the external API contract directly from Anthropic's preserved-thinking and beta-headers documentation, including enabled/adaptive acceptance, header-only diagnostics, and separate cloud beta transport contracts. No paid/live-credential probe.
  • This round did not run the full suite or test:changed, per the explicit shared-machine constraint. Docs build was not repeated; this review changed no documentation source. Broader suite/docs-build verification remains with PR CI.
  • Exact-head CI inspection (gh pr checks 7132 --repo lidge-jun/opencodex): no failed checks; required Ubuntu test shards and other required jobs remain queued. Some metadata runs were cancelled with queued replacements. Review verdict: needs-more until required CI completes successfully; code review itself found no blockers.

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. Credential/auth placement and destination classification are unchanged; only existing first-party classification is consumed. No unreleased security finding was discovered.

Summary by CodeRabbit

  • New Features
    • Managed native Messages requests to first-party Anthropic endpoints can now use beta-gated thinking-binding controls when the required beta is present and thinking is adaptive or enabled.
    • Beta-gated context-management and thinking-binding fields are filtered according to endpoint support and beta settings, while other thinking configuration is preserved.
  • Documentation
    • Clarified beta handling across first-party, compatible, and translated endpoints, including how configured beta headers affect field admission.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 247230c6-02c9-4757-b5fb-6ce973439bed
📥 Commits

Reviewing files that changed from the base of the PR and between 49c7773 and f0dd3b2.

📒 Files selected for processing: 1
  • tests/fixtures/test-layout-expected.json
+------------------------------------------------------------------------------------------------------------------------+
| Don't worry if it doesn't work right. If everything did, you'd be out of a job. - Mosher's Law of Software Engineering |
+------------------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5b2a9498-f52a-48ad-8f14-d087b4b59f05
📥 Commits

Reviewing files that changed from the base of the PR and between 7640a94 and 49c7773.

📒 Files selected for processing: 9
  • docs-site/src/content/docs/guides/protocol-paths.md
  • scripts/test-layout/layout.json
  • src/adapters/anthropic/beta-allowlist.ts
  • src/adapters/anthropic/beta-body-pairs.ts
  • src/adapters/anthropic/passthrough.ts
  • structure/data-planes/protocol-paths.md
  • structure/providers-and-adapters.md
  • tests/adapters/anthropic/anthropic-beta-body-pairs.test.ts
  • tests/fixtures/test-layout-expected.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

📝 Walkthrough

Managed Anthropic Messages requests now pair supported beta headers with their body fields. The passthrough builder removes unsupported or unpaired fields, and tests and documentation cover the behavior.

Changes: Managed Anthropic beta/body pairing

Layer / File(s) Summary
Paired field rules and beta admission
src/adapters/anthropic/beta-body-pairs.ts, src/adapters/anthropic/beta-allowlist.ts
A shared table defines the context_management and thinking.block_binding pairs. The allowlists use the table to admit paired betas. Context-edit tool names are translated for the wire, and binding requires adaptive or enabled thinking.
Passthrough reconciliation and validation
src/adapters/anthropic/passthrough.ts, tests/adapters/anthropic/anthropic-beta-body-pairs.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
The passthrough builder reconciles paired fields against the final beta header and destination. Tests cover key and OAuth requests, compatible destinations, operator-configured betas, and translated Responses requests. The new test is assigned to the Anthropic adapter shard.
Protocol behavior documentation
structure/data-planes/protocol-paths.md, structure/providers-and-adapters.md, docs-site/src/content/docs/guides/protocol-paths.md
The documentation describes beta admission, paired fields, destination restrictions, and the managed Messages contract.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant buildAnthropicMessagesPassthroughRequest
  participant pairAnthropicBetaBody
  Caller->>buildAnthropicMessagesPassthroughRequest: Request body and caller beta
  buildAnthropicMessagesPassthroughRequest->>pairAnthropicBetaBody: Wire body and final beta header
  pairAnthropicBetaBody-->>buildAnthropicMessagesPassthroughRequest: Reconciled wire body
Loading

Suggested reviewers: luvs01

Merge Risk: ⚪ Minimal · up to 49c77

The reviewed pairing change has no identified merge-blocking issue. Live Anthropic acceptance remains untested.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Out of Scope Changes check Warning The beta-pairing implementation, related tests, and native protocol documentation are in scope for #7102. However, structure/providers-and-adapters.md also changes documentation for `reasoningOutput… Remove the unrelated reasoningOutputTokens/reasoning_tokens documentation change from this pull request, or move it to a separate pull request. Keep the native beta-pairing documentation in structure/providers-and-adapters.md if requi…
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (5 skipped: 5… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Linked Issues check Passed Issue #7102 requires the beta and thinking.block_binding to stay paired. src/adapters/anthropic/beta-body-pairs.ts defines THINKING_BINDING_BETA and pairs it with thinking.block_binding. `pair…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: pairing Anthropic native beta schemas with the effective request headers. It matches the body reconciliation and beta-admission changes.
Full details: Out of Scope Changes check

Explanation

The beta-pairing implementation, related tests, and native protocol documentation are in scope for #7102. However, structure/providers-and-adapters.md also changes documentation for reasoningOutputTokens and reasoning_tokens. That change is unrelated to Anthropic beta admission or thinking.block_binding pairing. It is a concrete out-of-scope documentation change.

Resolution

Remove the unrelated reasoningOutputTokens/reasoning_tokens documentation change from this pull request, or move it to a separate pull request. Keep the native beta-pairing documentation in structure/providers-and-adapters.md if required.

Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (5 skipped: 5 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@lidge-jun
lidge-jun marked this pull request as ready for review October 15, 2026 07:30
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 15, 2026 07:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-10-15T07:34:23.976850Z 49c7773 Draft marked ready
ℹ️ 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.

@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: 49c7773e7f

ℹ️ 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 on lines +318 to +319
const sentBody = pairAnthropicBetaBody(wireBody, body, headers["anthropic-beta"],
domain?.firstPartyAnthropic === true, oauthToolNames);

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 Apply beta pairing to the count body

For a managed native route, this pairing is applied only while building the real /v1/messages request, while nativeMessagesCountBody still returns anthropicMessagesNativeWireBody(...).wireBody at src/server/messages-native.ts:1011 without the caller or effective beta header. Consequently, /count_tokens includes thinking.block_binding when the real request strips it because the beta is absent or rejected; conversely, an operator-configured context-management beta makes the real request restore context_management while counting omits it. Pass the effective beta inputs into the count path and apply the same reconciliation so token estimates describe the body that is actually sent.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 15, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration into dev (MAINTAINERS.md dev maintainer-integration policy; batch integration authorized by @lidge-jun on 2026-10-15).

  • Head: f0dd3b22cb390435a097a438b0ff6a47a6fcb476 (tree ba5a2fa49118fa3bbf59a0c3b31477587f117533) = this branch merged with origin/dev 8066328f9b.
  • Exact-head evidence: GitHub-hosted Actions for this account have not been assigning runners since 2026-10-15 13:30 UTC, so by owner decision the evidence is a full bun run test (Bun 1.4.3 test runner, root and GUI dependencies installed, GUI built) of this exact tree on a maintainer host (macOS arm64): exit 1, 9 min, 4 failing test(s), each also failing in the same host's baseline run of dev 60bf4c7 (environment-only): a secondary ensure parent preserves shared Grok, Codex and Claude agent bytes, connected Desktop uses hub IDs across a cold restart (stored profile=false), live audio readiness and bounded closure > native open and non-readiness events cannot cla, update stops the running proxy before replacing files > npm launcher restarts the stopped .
  • Local gates on the same tree: bun run typecheck, file-size ratchet, test-layout and structure:check.
  • Hosted CI checks for this head may still be queued; they are not claimed as evidence.

@lidge-jun
lidge-jun merged commit c410b77 into dev Oct 15, 2026
7 checks passed
@lidge-jun
lidge-jun deleted the fix/7102-anthropic-beta-pairing branch October 15, 2026 15:39
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