Skip to content

fix(provider-utils): preserve prototype-named tools - #25355

Open
duoduohappy wants to merge 1 commit into
vercel:mainfrom
duoduohappy:fix/provider-tool-name-mapping
Open

duoduohappy wants to merge 1 commit into
vercel:mainfrom
duoduohappy:fix/provider-tool-name-mapping

Conversation

@duoduohappy

@duoduohappy duoduohappy commented Nov 22, 2026 •

Copy link
Copy Markdown

Background

Fixes #25354, which I reported after investigating tool-name mapping.

createToolNameMapping stores mappings in plain objects. Unmapped names such as constructor and toString resolve to inherited functions, while __proto__ resolves to an object. In the OpenAI Responses request serializer this omits the first two tool-call names and serializes the third as {}. Assigning a provider tool the custom alias __proto__ also fails to store the mapping.

Summary

  • Use Map<string, string> for both mapping directions, preserving the existing fallback and last-mapping-wins behavior.
  • Add regression coverage for inherited names in both directions and for an explicit __proto__ alias.
  • Add a patch changeset for @ai-sdk/provider-utils.

Prepared with Codex assistance. The account owner has reviewed the changes and confirmed understanding.

Validation

  • Before the fix: the mapping suite had 4 failing and 6 passing cases.
  • After the fix: all 10 mapping cases pass in Node and Edge.
  • The adjacent OpenAI Responses input-conversion and tool-preparation suites pass: 317 cases in Node and 317 in Edge.
  • Filtered builds succeeded. Scoped type checking for @ai-sdk/provider-utils, @ai-sdk/openai, and ai passed.
  • Formatting/linting and git diff --check passed. Modified-file guideline discovery and verifiers reported no applicable checks.
  • Full workspace pnpm type-check was attempted but did not complete: the selectively installed checkout lacks unrelated tools/konsistent-provider dependencies (@vercel/ai-tsconfig/ts-library.json and @konsistent/convention). This is not a claim that the full workspace checks passed.

End-to-End Verification

Prerequisites: Node.js 24 and pnpm 12.14.0; no API credentials are required. Tested on Windows. Baseline: d55f3cfc456d1b7bc7db3a4b70fbf602ddc8647d.

Save the following as ../vercel-tool-name-repro.mjs outside the checkout:

import { createOpenAI } from '@ai-sdk/openai';

console.log('provider package:', import.meta.resolve('@ai-sdk/openai'));
for (const name of ['lookup', 'constructor', 'toString', '__proto__']) {
  const provider = createOpenAI({
    apiKey: 'local-reproduction-not-a-real-key',
    fetch: async (_url, options) => {
      const body = JSON.parse(options.body);
      const call = body.input.find(item => item.type === 'function_call');
      console.log(JSON.stringify({ toolName: name, serializedCall: call }));
      throw new Error('Request captured locally; no external service was called.');
    },
  });
  try {
    await provider.responses('gpt-4.1').doGenerate({
      prompt: [{
        role: 'assistant',
        content: [{ type: 'tool-call', toolCallId: 'call-1', toolName: name, input: '{}' }],
      }],
      tools: [{ type: 'function', name, inputSchema: { type: 'object', properties: {} } }],
    });
  } catch (error) {
    console.log('capture:', error.message);
  }
}

From the checkout root, install dependencies and build the local packages:

pnpm install --filter @ai-sdk/provider-utils... --filter @ai-sdk/openai... --filter ai... --frozen-lockfile
pnpm exec turbo build --filter=ai... --filter=@ai-sdk/openai...

Run from packages/openai so the script resolves the locally built workspace package:

Get-Content -Raw -LiteralPath ../../../vercel-tool-name-repro.mjs | node --input-type=module

On a POSIX shell, the equivalent is:

node --input-type=module < ../../../vercel-tool-name-repro.mjs

I built and ran this script against the baseline, then rebuilt and reran the same script after the fix. Both runs printed the checkout's packages/openai/dist/index.js URL, rather than a registry installation.

Observed baseline calls:

{"type":"function_call","call_id":"call-1","name":"lookup","arguments":"{}"}
{"type":"function_call","call_id":"call-1","arguments":"{}"}
{"type":"function_call","call_id":"call-1","arguments":"{}"}
{"type":"function_call","call_id":"call-1","name":{},"arguments":"{}"}

After the fix:

{"type":"function_call","call_id":"call-1","name":"lookup","arguments":"{}"}
{"type":"function_call","call_id":"call-1","name":"constructor","arguments":"{}"}
{"type":"function_call","call_id":"call-1","name":"toString","arguments":"{}"}
{"type":"function_call","call_id":"call-1","name":"__proto__","arguments":"{}"}

Verification limit: this exercises the built OpenAI Responses provider's request-construction and serialization path, intercepted through its custom fetch hook. It deliberately stops before network I/O. No live OpenAI request, response, or model execution was verified; this is not full live-service end-to-end verification.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #25354

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@duoduohappy is attempting to run Vercel CI for a fork pull request of the Vercel Team on Vercel.

A member of the Team first needs to approve it.

@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@duoduohappy is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@duoduohappy
duoduohappy marked this pull request as ready for review November 22, 2026 05:50

@surlymochan surlymochan 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.

Verified the bug and the fix by reading the diff: with plain-object maps, looking up a prototype-named tool (e.g. __proto__/constructor/toString) reads an inherited property instead of a mapping — toCustomToolName('__proto__') would have returned Object.prototype rather than the name. Switching both maps to Map makes .get() return undefined for unmapped names so the ?? name fallback is correct. The tests cover both directions, including a provider tool literally named __proto__ mapped to web_search, and the changeset (patch for @ai-sdk/provider-utils) matches the scope.

One question: are there other plain-object name maps in provider-utils with the same prototype-key pattern, or is this the only one? Not a blocker — the fix itself is complete for this helper.

@duoduohappy

Copy link
Copy Markdown
Author

@surlymochan Thanks for checking! A focused search of provider-utils didn’t turn up another plain-object tool-name mapping with the same pattern. The streaming tool-call tracker already uses Map. This wasn’t an exhaustive audit of every object lookup, so I’ve kept this PR scoped to the two mappings in this helper.

@terrorgeek

Copy link
Copy Markdown

Verified locally (macOS, Node 22.22; provider-utils/openai/anthropic built from this branch merged onto current main; no live provider).

Repro, before/after. Ran the script from the PR description against packages/openai/dist/index.js. With main's create-tool-name-mapping.ts, constructor and toString serialize without name and __proto__ as "name": {}; with this PR all four names serialize as strings. Mapping tests: 4 failed / 6 passed on main's source, 10/10 with the fix. This matches the PR description.

On the open question about other plain-object name maps. I searched the packages for lookups keyed by tool names. Findings:

  • ai's validatedContexts uses createIdMap() (null prototype), so it's not affected.
  • @ai-sdk/anthropic is affected, and isn't covered by this PR: getAnthropicToolsetName (convert-to-anthropic-prompt.ts) reads toolsetNames[toolName] from a plain {} built in getAnthropicToolsetNames. For a tool named constructor or toString, the inherited function is non-null, so it shadows the providerOptions.anthropic.toolsetName fallback. Probe (tool-result for tool <name> with providerOptions.anthropic.toolsetName: 'computer'): lookup → "computer", constructor → undefined, toString → undefined. Impact is narrow (computer toolset + such a tool name), but it's the same pattern.
  • Not verified, only read: constant lookups like PUBLIC_TO_NATIVE[toolName] ?? toolName in harness-claude-code/src/bridge/tool-filtering.ts and TOOL_KIND[toolName] ?? 'bash' in harness-opencode.

Fine to keep this PR scoped to createToolNameMapping; I can open a follow-up issue for the Anthropic case with the probe if useful.

Not verified: Edge suite, live OpenAI. LGTM from a contributor's point of view (non-binding).

@duoduohappy

Copy link
Copy Markdown
Author

@terrorgeek Thanks for reproducing this and checking the other packages! A separate issue for the Anthropic case with your probe would be helpful. I'll keep this PR focused on createToolNameMapping. Thanks also for clearly documenting the validation scope.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI Responses drops tool-call names constructor and toString

3 participants