Repository navigation
fix(claude): forward client tool-search-tool anthropic-beta on the Claude OAuth path (#3974) #3999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 1 commit into
release/v3.8.27
from
fix/3974-toolsearch-beta-passthrough
Jun 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * TDD regression for #3974: the client-negotiated `anthropic-beta: | ||
| * tool-search-tool-2025-10-19` is dropped on BOTH Claude code paths, so the | ||
| * claude.ai backend rejects deferred-tool requests with | ||
| * `400 Tool reference '<name>' not found in available tools`. | ||
| * | ||
| * - default executor (`claude` uses executor:"default"): buildHeaders set the | ||
| * beta from the static registry header (ANTHROPIC_BETA_CLAUDE_OAUTH, which | ||
| * lacks tool-search) and the client-header forward block is allowlist-only. | ||
| * - selectBetaFlags path (base.ts): rebuilds the beta from a fixed vocabulary | ||
| * and only reads the client beta to GATE thinking/effort, never to ADD. | ||
| * | ||
| * Fix: allowlist-merge the client beta on both paths (preserving #3415 — never | ||
| * force thinking/effort the client did not send). | ||
| */ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
|
|
||
| import { DefaultExecutor } from "../../open-sse/executors/default.ts"; | ||
| const { selectBetaFlags } = await import("../../open-sse/executors/claudeIdentity.ts"); | ||
| const { mergeClientAnthropicBeta, FORWARDABLE_CLIENT_BETAS } = await import( | ||
| "../../open-sse/config/anthropicHeaders.ts" | ||
| ); | ||
|
|
||
| const TOOL_SEARCH = "tool-search-tool-2025-10-19"; | ||
|
|
||
| function fullAgentBody(model: string) { | ||
| return { | ||
| model, | ||
| system: "You are a coding agent.", | ||
| tools: [{ name: "read_file", description: "x", input_schema: { type: "object" } }], | ||
| }; | ||
| } | ||
|
|
||
| function betaTokens(headers: Record<string, string>): string[] { | ||
| const key = Object.keys(headers).find((k) => k.toLowerCase() === "anthropic-beta"); | ||
| return key ? headers[key].split(",").map((s) => s.trim()) : []; | ||
| } | ||
|
|
||
| // ── helper unit (allowlist-merge) ──────────────────────────────────────────── | ||
|
|
||
| test("#3974 mergeClientAnthropicBeta appends an allowlisted client beta once, preserving base order", () => { | ||
| const out = mergeClientAnthropicBeta( | ||
| "claude-code-20250219,oauth-2025-04-20", | ||
| `oauth-2025-04-20,${TOOL_SEARCH}` | ||
| ); | ||
| const tokens = out.split(","); | ||
| assert.deepEqual(tokens.slice(0, 2), ["claude-code-20250219", "oauth-2025-04-20"]); | ||
| assert.equal(tokens.filter((t) => t === TOOL_SEARCH).length, 1, "appended once, no dup"); | ||
| }); | ||
|
|
||
| test("#3974 mergeClientAnthropicBeta ignores non-allowlisted client betas", () => { | ||
| const out = mergeClientAnthropicBeta("oauth-2025-04-20", "some-random-future-beta-2099-01-01"); | ||
| assert.equal(out, "oauth-2025-04-20", "only allowlisted betas are forwarded"); | ||
| assert.ok(FORWARDABLE_CLIENT_BETAS.includes(TOOL_SEARCH)); | ||
| }); | ||
|
|
||
| // ── selectBetaFlags path (base.ts) ─────────────────────────────────────────── | ||
|
|
||
| test("#3974 selectBetaFlags + merge preserves the client tool-search beta", () => { | ||
| const clientBeta = `claude-code-20250219,oauth-2025-04-20,${TOOL_SEARCH}`; | ||
| const out = mergeClientAnthropicBeta( | ||
| selectBetaFlags(fullAgentBody("claude-opus-4-8"), null, clientBeta), | ||
| clientBeta | ||
| ); | ||
| assert.ok(out.split(",").includes(TOOL_SEARCH)); | ||
| }); | ||
|
|
||
| test("#3974 merge does not force interleaved-thinking the client omitted (guards #3415)", () => { | ||
| const clientBeta = `oauth-2025-04-20,${TOOL_SEARCH}`; | ||
| const out = mergeClientAnthropicBeta( | ||
| selectBetaFlags(fullAgentBody("claude-opus-4-8"), null, clientBeta), | ||
| clientBeta | ||
| ); | ||
| assert.ok(out.split(",").includes(TOOL_SEARCH)); | ||
| assert.ok( | ||
| !out.split(",").includes("interleaved-thinking-2025-05-14"), | ||
| "must NOT force interleaved-thinking when the client did not request it" | ||
| ); | ||
| }); | ||
|
|
||
| // ── default executor path (default.ts buildHeaders) ────────────────────────── | ||
|
|
||
| test("#3974 DefaultExecutor('claude') merges the client tool-search beta into outbound headers", () => { | ||
| const executor = new DefaultExecutor("claude"); | ||
| const headers = executor.buildHeaders({ accessToken: "sk-ant-oat-x" }, true, { | ||
| "anthropic-beta": `oauth-2025-04-20,${TOOL_SEARCH}`, | ||
| }) as Record<string, string>; | ||
| const tokens = betaTokens(headers); | ||
| assert.ok(tokens.includes(TOOL_SEARCH), `outbound beta missing tool-search: ${tokens.join(",")}`); | ||
| assert.equal(tokens.filter((t) => t === TOOL_SEARCH).length, 1, "no duplicate"); | ||
| // The provider's own base betas are still present. | ||
| assert.ok(tokens.includes("claude-code-20250219")); | ||
| }); | ||
|
|
||
| test("#3974 DefaultExecutor('claude') without a client beta leaves the static set unchanged", () => { | ||
| const executor = new DefaultExecutor("claude"); | ||
| const headers = executor.buildHeaders({ accessToken: "sk-ant-oat-x" }, true, {}) as Record< | ||
| string, | ||
| string | ||
| >; | ||
| assert.ok(!betaTokens(headers).includes(TOOL_SEARCH), "must not invent tool-search unprompted"); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
clientHeadersisnullorundefined(which is possible as indicated by theclientHeaders || {}fallback on line 511), accessingclientHeaders["anthropic-beta"]directly will throw aTypeErrorand crash the server. Additionally, HTTP headers are case-insensitive, so we should perform a case-insensitive lookup onclientHeadersjust like we do forheadersto ensure we don't miss any client-negotiated betas.