Skip to content

[None][fix] Responses: resolve namespace::tool calls and restore a dropped namespace on replay - #21056

Merged
JunyiXu-nv merged 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-fix-responses-tool-name-spellings
Oct 27, 2026
Merged

JunyiXu-nv merged 1 commit into
NVIDIA:mainfrom
JunyiXu-nv:dev-junyix-fix-responses-tool-name-spellings

Conversation

@JunyiXu-nv

@JunyiXu-nv JunyiXu-nv commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The Codex CLI declares its tools under namespaces. exec is a custom (freeform) tool in the
functions namespace, and spawn_agent is a function in the collaboration namespace. A chat
template can only show a flat list of functions, so the Responses endpoint offers these tools as
functions.exec and collaboration.spawn_agent. It reports each call back to the client as a
bare name plus a namespace.

Models write a namespaced tool's name in three ways:

  • functions.exec, the name in the tool list;
  • exec, the name the client's own instructions use;
  • functions::exec, the separator DeepSeek-V4.1-Flash uses for namespaced tools in its tool
    schema and in its calls.

_tool_resolution already resolves the first two. The third matched no declared tool, so the
call went out as a function_call named functions::exec with no namespace. The client answers
such a call with "unsupported call". For exec, the call also lost its custom-tool shape
(custom_tool_call with input).

There is a second, related problem. The client sometimes echoes a call back in the next request
without its namespace field. The history was then rendered with the bare name exec. That name
is not in the tool list the model was given, so the history no longer matched the tools.

This PR changes tensorrt_llm/serve/responses_utils.py:

  1. namespace::tool now resolves exactly like namespace.tool. A custom tool still comes out as
    custom_tool_call with input. The streamed items and the final snapshot use the same
    resolution, so they agree. This spelling never displaces a name that a tool was declared
    under. The bare-name rule is unchanged: a bare name resolves only when exactly one declared
    tool has it.
  2. When the request input is converted to chat messages, a function_call or
    custom_tool_call that arrives without a namespace is replayed under its qualified name, if
    exactly one namespaced tool and no top-level tool has that bare name. Any other name is
    replayed as received. A call that keeps its namespace is replayed as before. The same
    conversion feeds the router's prompt rendering, so the router sees the same history.

Not changed:

  • What the DeepSeek-V4.1 renderer shows in the tool schema. It still shows functions.exec.
    Showing the :: spelling there is a separate decision.
  • The tool parsers. A parser that only accepts dotted names (the GLM parsers) still treats a
    :: name as text.
  • The spelling a call is replayed under. A replayed call always uses the dotted name, even when
    the model wrote functions::exec or exec. After such a call, the next prompt therefore
    differs from the tokens the model generated, so prefix-cache reuse stops at that call.
    Main already behaves this way for calls echoed with their namespace.

Test Coverage

All new tests are CPU tests in files that l0_cpu.yml already lists.

  • tests/unittest/llmapi/apps/test_responses_custom_tools.py
    • Each spelling (dotted, bare, ::) of a namespaced custom tool and of a namespaced function.
    • Names that match no declared tool, such as functions:exec, ::exec and functions::.
      They are reported as written.
    • A bare name that two namespaces share. It resolves to neither, while both qualified
      spellings still resolve.
    • A declared name wins over another tool's alternative spelling, in either declaration order.
    • The replay rule: restored without a namespace, unchanged with one, and left as received
      for an ambiguous name, a top-level owner, no tools, and a name that is not bare.
  • tests/unittest/llmapi/apps/test_responses_input_preprocess.py: a whole request shaped like
    the Codex CLI's (tools in an additional_tools item) with two calls echoed without their
    namespaces.
  • tests/unittest/llmapi/apps/test_responses_streaming_tool_calls.py: all three spellings
    through the DeepSeek-V4.1 and Qwen3 tool parsers at several chunk sizes. The streamed items,
    the snapshot of the streamed response and a snapshot built without streaming all agree.
  • tests/unittest/llmapi/apps/test_responses_stream_final_consistency.py: a functions::exec
    call through the streaming processor with a namespace declared in the request. The streamed
    custom_tool_call equals the one in the terminal snapshot.

On a build of current main, the four files pass: 187 tests, 31 of them new, against 156 before.

The resolution and the replay rule were also checked as properties over generated tool sets,
with a mutation gate that plants bugs in both. That check is not part of this PR.

PR Checklist

  • PR description clearly explains what and why.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

🤖 Generated with Claude Code

Dev Engineer Review

The resolver uses the request’s declared tools to map dotted and namespace::tool spellings to namespaced tools. It qualifies a bare name only when exactly one namespaced tool matches and no top-level tool has that name. Function and custom-tool replay use this resolution. Test results and review severity counts are unavailable.

QA Engineer Review

Four test files changed. They cover namespaced tool resolution, input replay, and consistency between streamed calls and final snapshots. Cases include dotted, bare, and namespace::tool spellings, ambiguous names, exact top-level matches, and function and custom-tool payloads. All four files appear in tests/integration/test_lists/test-db/l0_cpu.yml. Coverage verdict: sufficient for the described resolution and replay behavior.

Per-File QA Perspective

  • tensorrt_llm/serve/responses_utils.py: Verify that declared namespaced tools resolve consistently for function and custom-tool input replay. Check that ambiguous bare names and exact top-level matches preserve the received spelling.
  • tests/unittest/llmapi/apps/test_responses_custom_tools.py: Covers dotted, bare, and :: resolution, unknown and ambiguous spellings, top-level precedence, and replay with a missing namespace. Listed in tests/integration/test_lists/test-db/l0_cpu.yml.
  • tests/unittest/llmapi/apps/test_responses_input_preprocess.py: Covers replay of unqualified namespaced custom-tool and function calls into chat tool calls. Listed in tests/integration/test_lists/test-db/l0_cpu.yml.
  • tests/unittest/llmapi/apps/test_responses_stream_final_consistency.py: Covers a DeepSeek-V4.1 namespace::tool call and checks the custom-tool shape in streamed output and the final response. Listed in tests/integration/test_lists/test-db/l0_cpu.yml.
  • tests/unittest/llmapi/apps/test_responses_streaming_tool_calls.py: Covers streaming and non-streaming parsing across model and spelling variants, with chunk-size comparisons. Listed in tests/integration/test_lists/test-db/l0_cpu.yml.

…opped namespace on replay

The Codex CLI declares its tools under namespaces, and the Responses endpoint
offers them to the model as "namespace.tool". Models also write the bare name
and, for DeepSeek-V4.1-Flash, "namespace::tool". The bare name already
resolved; "namespace::tool" did not, so the call reached the client as a
function call to an unknown tool, and a custom tool lost its custom_tool_call
shape.

- _tool_resolution maps "namespace::tool" to the same tool as
  "namespace.tool". The spelling never displaces a declared name, and the
  bare-name rule is unchanged. The stream and the final snapshot share the
  resolution, so they agree.
- When the input is converted to chat messages, a call echoed back without its
  namespace is replayed under its qualified name if exactly one namespaced
  tool and no top-level tool has that bare name, so the history matches the
  tool list. Any other name is replayed as received.

Signed-off-by: JunyiXu-nv <[email protected]>
@JunyiXu-nv
JunyiXu-nv requested a review from a team as a code owner October 27, 2026 01:00
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 38d2c3a and a5e1017.

Files selected for processing: 5
  • tensorrt_llm/serve/responses_utils.py
  • tests/unittest/llmapi/apps/test_responses_custom_tools.py
  • tests/unittest/llmapi/apps/test_responses_input_preprocess.py
  • tests/unittest/llmapi/apps/test_responses_stream_final_consistency.py
  • tests/unittest/llmapi/apps/test_responses_streaming_tool_calls.py

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

Walkthrough

Tool-call resolution now uses the request’s declared tools to interpret namespaced spellings and replay echoed calls. Tests cover custom and function tools, ambiguous names, and streamed and final responses.

Changes

Namespaced tool replay

Layer / File(s) Summary
Build declared-tool mappings
tensorrt_llm/serve/responses_utils.py, tests/unittest/llmapi/apps/test_responses_custom_tools.py
The mapping records exposed and namespace::tool spellings. Tests cover dotted, bare, and :: names, ambiguous bare names, and precedence for exact top-level declarations.
Apply resolution during input replay
tensorrt_llm/serve/responses_utils.py, tests/unittest/llmapi/apps/test_responses_custom_tools.py, tests/unittest/llmapi/apps/test_responses_input_preprocess.py
Input conversion passes the declared-tool mapping when replaying function and custom-tool calls. A bare name gains its namespace only when it has a unique namespaced owner; other names remain unchanged.
Check streaming and final call consistency
tests/unittest/llmapi/apps/test_responses_streaming_tool_calls.py, tests/unittest/llmapi/apps/test_responses_stream_final_consistency.py
Tests compare streamed calls with final snapshots across parsers, name spellings, and chunk sizes. They also check namespaced custom-tool output in streaming and final responses.

Priority: Normal

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

Change: Bug fix

Suggested reviewers: qijune

Merge Risk: Minimal · up to a5e10

The namespaced tool-call changes have relevant replay and streaming tests, with no identified issue requiring a fix before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title follows the repository template: it has a [None] ticket tag, a [fix] type, and a summary. It names the two main changes: resolving namespace::tool calls and restoring a dropped namespace on …
Description check Passed The description follows the repository template. It has a Description section that explains the Codex namespace problem, the three spellings, the two fixes, and what is not changed. It has a Test Cove…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title follows the repository template: it has a [None] ticket tag, a [fix] type, and a summary. It names the two main changes: resolving namespace::tool calls and restoring a dropped namespace on replay. This matches the raw summary and the objectives, which describe namespaced tool resolution in responses_utils.py and the replay rule for calls without a namespace.

Full details: Description check

Explanation

The description follows the repository template. It has a Description section that explains the Codex namespace problem, the three spellings, the two fixes, and what is not changed. It has a Test Coverage section that lists the four test files, their cases, and the reported pass counts. The PR Checklist is reduced to a single checked item and does not include the other checklist items from the template. The template's title-format line is not repeated in the description, which is acceptable because the title itself follows the format.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 25 functions across 5 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80737 [ run ] triggered by Bot. Commit: a5e1017 Link to invocation

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80737 [ run ] completed with state SUCCESS. Commit: a5e1017
/LLM/main/L0_MergeRequest_PR pipeline #66480 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@github-actions

Copy link
Copy Markdown

👎 Promotion blocked, new vulnerability found

Vulnerability report

Component Vulnerability Description Severity
py-filelock CVE-2026-112906 filelock is a platform-independent file lock for Python. From 4.1.0 until 4.2.1, SoftFileLock versions from 4.1.0 can reuse a stale observation when an attacker pre-dates and removes its own marker, at least two lock-user processes are waiting, coarse or matching modification times preserve the observation, and an honest contender creates a fresh marker on the reused inode, causing that live marker to be removed as stale. This issue is fixed in version 4.2.1. MEDIUM
py-filelock CVE-2026-112914 filelock is a platform-independent file lock for Python. From 4.1.0 until 4.2.1, SoftFileLock can restore a stale marker by name after moving it aside, allowing another local user with rename access in a non-sticky lock directory to swap in a symbolic link and, on a runtime that follows the link and a same-filesystem target, make the lock user hard-link one of its files into the lock directory. This issue is fixed in version 4.2.1. MEDIUM
py-filelock CVE-2026-112937 filelock is a platform-independent file lock for Python. From 4.1.0 until 4.2.1, ReadWriteLock can remove a randomized .filelock-* private-hard-link directory during cleanup, allowing another local user with rename access in a non-sticky parent to observe a live name or forge a dead-owner sweep name and rename a sibling directory onto it for deletion. This issue is fixed in version 4.2.1. MEDIUM
py-filelock CVE-2026-112940 filelock is a platform-independent file lock for Python. From 3.20.4 until 4.2.1, ReadWriteLock let SQLite reopen the database and side files by name; on POSIX systems an attacker with rename access in a non-sticky parent can swap those names to cause overwrite or unlink operations, while a writable adjacent hot journal is additionally required for attacker-chosen content overwrites. This issue is fixed in version 4.2.1. HIGH

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80877 [ run ] triggered by Bot. Commit: a5e1017 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80877 [ run ] completed with state SUCCESS. Commit: a5e1017
/LLM/main/L0_MergeRequest_PR pipeline #66602 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@JunyiXu-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80895 [ run ] triggered by Bot. Commit: a5e1017 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80895 [ run ] completed with state SUCCESS. Commit: a5e1017
/LLM/main/L0_MergeRequest_PR pipeline #66621 completed with status: 'SUCCESS'

CI Report

Link to invocation

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.

4 participants