-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Bug] Bound flattened tool wire names to 64 characters for strict gateways (Command Code) #4715
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
Closed
HulianBuligon
wants to merge
6
commits into
lidge-jun:dev
from
HulianBuligon:fix/bounded-tool-wire-names
+222
−4
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
96c6e56
fix: bound flattened tool wire names to 64 characters (#4679)
HulianBuligon 8f6fa49
fix: collapse duplicate tool choice alias for bounded names (#4715)
HulianBuligon eaf5bdb
fix: two-way wire-name claims and registry cap for bounded aliases
HulianBuligon 098684f
test: assert bounded aliases are stable across fresh processes
HulianBuligon 5fdc16d
test: keep all bounded-name tests inside the describe block
HulianBuligon b6fd8c9
fix: reserve the whole catalog's wire names before bounded aliases
HulianBuligon 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { spawnSync } from "node:child_process"; | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { repoPath } from "../helpers/repo-root"; | ||
| import { dottedToolName, namespacedToolName, reserveToolWireNames, toolChoiceAliases } from "../../src/types/tools"; | ||
|
|
||
| describe("bounded tool wire names (#4679)", () => { | ||
| test("keeps flat names at or under the 64-char wire limit unchanged", () => { | ||
| expect(namespacedToolName(undefined, "exec_command")).toBe("exec_command"); | ||
| expect(namespacedToolName("collaboration", "spawn_agent")).toBe("collaboration__spawn_agent"); | ||
| expect(dottedToolName("collaboration", "spawn_agent")).toBe("collaboration.spawn_agent"); | ||
| }); | ||
|
|
||
| test("aliases flattened names past the 64-char gateway bound deterministically", () => { | ||
| const namespace = "mcp__codex_apps__safety_settings"; | ||
| const name = "prepare_parental_control_update"; | ||
| expect(`${namespace}__${name}`.length).toBe(65); | ||
| const first = namespacedToolName(namespace, name); | ||
| expect(first.length).toBeLessThanOrEqual(64); | ||
| expect(first.startsWith("mcp__codex_apps__safety_settings__")).toBe(true); | ||
| // Same identity, same alias — stable across calls and process restarts. | ||
| expect(namespacedToolName(namespace, name)).toBe(first); | ||
| expect(dottedToolName(namespace, name)).toBe(first); | ||
| }); | ||
|
|
||
| test("distinct identities keep distinct bounded wire names within one namespace", () => { | ||
| const namespace = "mcp__codex_apps__codex_document_control"; | ||
| const a = namespacedToolName(namespace, "get_document_tool_schemas"); | ||
| const b = namespacedToolName(namespace, "execute_document_command"); | ||
| expect(a.length).toBeLessThanOrEqual(64); | ||
| expect(b.length).toBeLessThanOrEqual(64); | ||
| expect(a).not.toBe(b); | ||
| }); | ||
|
|
||
| test("bare names past the bound are aliased too", () => { | ||
| const name = "a_very_long_client_declared_function_name_exceeding_the_gateway_limit"; | ||
| expect(name.length).toBeGreaterThan(64); | ||
| const wire = namespacedToolName(undefined, name); | ||
| expect(wire.length).toBeLessThanOrEqual(64); | ||
| expect(namespacedToolName(undefined, name)).toBe(wire); | ||
| }); | ||
|
|
||
| test("tool choice aliases collapse to a single entry for a bounded alias", () => { | ||
| const identity = { namespace: "mcp__codex_apps__safety_settings", name: "prepare_parental_control_update" }; | ||
| const aliases = toolChoiceAliases(identity); | ||
| expect(aliases.length).toBe(1); | ||
| expect(aliases[0].length).toBeLessThanOrEqual(64); | ||
| }); | ||
|
|
||
| test("bounded aliases are stable across fresh processes (restart contract)", () => { | ||
| const identity = { namespace: "mcp__codex_apps__safety_settings", name: "prepare_parental_control_update" }; | ||
| const script = | ||
| "(async () => {" + | ||
| `const m = await import(new URL(${JSON.stringify("file://" + repoPath("src", "types", "tools.ts"))}).href);` + | ||
| `console.log(m.namespacedToolName(${JSON.stringify(identity.namespace)}, ${JSON.stringify(identity.name)}));` + | ||
| "})();"; | ||
| const run = () => spawnSync(process.execPath, ["-e", script], { encoding: "utf8" }); | ||
| const first = run(); | ||
| const second = run(); | ||
| expect(first.status).toBe(0); | ||
| expect(second.status).toBe(0); | ||
| const alias = first.stdout.trim(); | ||
| expect(alias.length).toBeLessThanOrEqual(64); | ||
| // A fresh process derives the same alias for the same identity: no process-local state | ||
| // participates in the derivation, so the restart contract holds. | ||
| expect(second.stdout.trim()).toBe(alias); | ||
| expect(namespacedToolName(identity.namespace, identity.name)).toBe(alias); | ||
| }); | ||
| }); | ||
|
|
||
| test("alias mapping is independent of declaration order (catalog reservation)", () => { | ||
| const catalog = [ | ||
| { namespace: "mcp__codex_apps__safety_settings", name: "prepare_parental_control_update" }, | ||
| { namespace: "mcp__codex_apps__safety_settings", name: "update_parental_controls" }, | ||
| { namespace: "mcp__codex_apps__codex_document_control", name: "get_document_tool_schemas" }, | ||
| ]; | ||
| const runOrder = (order: number[]) => { | ||
| const tools = JSON.stringify(order.map(i => catalog[i])); | ||
| const script = | ||
| "(async () => {" + | ||
| `const m = await import(new URL(${JSON.stringify("file://" + repoPath("src", "types", "tools.ts"))}).href);` + | ||
| `const tools = ${tools};` + | ||
| "m.reserveToolWireNames(tools);" + | ||
| "console.log(JSON.stringify(tools.map(t => m.namespacedToolName(t.namespace, t.name))));" + | ||
| "})();"; | ||
| const r = spawnSync(process.execPath, ["-e", script], { encoding: "utf8" }); | ||
| expect(r.status).toBe(0); | ||
| return Object.fromEntries(JSON.parse(r.stdout.trim()).map((wire: string, i: number) => [`${catalog[order[i]].namespace}__${catalog[order[i]].name}`, wire])); | ||
| }; | ||
| const forward = runOrder([0, 1, 2]); | ||
| const reversed = runOrder([2, 1, 0]); | ||
| expect(reversed).toEqual(forward); | ||
| for (const wire of Object.values(forward)) expect(wire.length).toBeLessThanOrEqual(64); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.