Skip to content

spark-server: send GLM native calls to undeclared tools to the client - #322

Merged
AzeezIsh merged 3 commits into
Atlas-Inf:mainfrom
Enntity:fix/glm-undeclared-native-call
Nov 3, 2026
Merged

AzeezIsh merged 3 commits into
Atlas-Inf:mainfrom
Enntity:fix/glm-undeclared-native-call

Conversation

@data-angel

Copy link
Copy Markdown
Contributor

Summary

GLM calls to tools the request did not declare were lost. When GLM-5.3-Flash opened a call with its native <tool_call> token and named a tool missing from tools, Atlas treated the envelope as prose:

  • Streaming: the raw envelope went out as content with finish_reason: "stop".
  • Blocking: the envelope was cut and the response came back with empty content and no tool call.

A ZCode agent hit this live. It called mcp__accord__accord_sent, a tool it had read about in source but was never offered, and the user saw <tool_call>mcp__accord__accord_sent<arg_key>id</arg_key>… as the reply. The agent's turn ended there.

This PR has two commits:

  • Send the call to the client (c2f5fed97). A native opener outside a quote or code span is a call, so its envelope now reaches the client as a tool call under the name the model wrote. The client answers with its own unknown-tool result (ZCode: Tool not found), and the agent's turn continues, as with a reference server.
    • The name is never repaired onto a declared tool. Blocking routes these calls around the fuzzy validator, and streaming passes them only from a native envelope.
    • The tool guard still inspects their arguments.
    • Markup the model spells as text, or writes inside a quote or code span, stays prose: the literal-XML rule is unchanged for it.
  • Finish tool_calls only when a call was sent (4ca502214). The stream's finish reason counted calls the detector parsed, so a call that validation rejected ended with finish_reason: "tool_calls" and no tool call in the response. It now counts the calls actually sent (tool_calls_emitted_count).

Test plan

  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --locked -p spark-server --tests (pinned 1.93.1 toolchain): clean
  • SPDX headers present on every changed file (no new files)
  • cargo test -p spark-server: 3,044 passed. 3 fail identically without a git checkout (bench_selfstart serve pin, two tui::bench_variants): they call repo_root().
  • New tests, each failing first on main:
    • glm_native_call_to_undeclared_tool_reaches_the_client: stream and blocking deliver unknown_tool unchanged with finish_reason: tool_calls; the same envelope spelled without the native token stays prose.
    • a_call_that_validation_rejects_finishes_stop: a declared write that validation rejects finishes stop.
    • glm_native_tool_boundary_keeps_request_model_and_name_guards and the explicit-close case in glm_boundary_case_tests now assert the undeclared name is kept, not repaired onto get_weather.
  • Tested on hardware: GLM-5.3-Flash at TP=4, four Sparks on the ring, Spark mode, the same commits on the deployed SparkGLM tree.
    • The live repro (accord_sent described in the system prompt but not declared) now returns a tool call on both paths; declared calls are unchanged.
    • Against the prior image: greedy 8/8 identical, logprobs identical, qualification suite 105/109 with the same 4 known failures, tool probes, spelled-markup probes and vision unchanged.
    • Speed level: prose decode 58.5 vs 58.1 tok/s, code 105.1 vs 104.5, C4 102.2 vs 101.2, prefill identical.

Notes for reviewers

  • BFCL hallucination. A model call to an undeclared tool now counts as a call, where it used to disappear. That matches what a reference server returns, but the hallucination category can move. The bfcl-subset leg has not been rerun on this change.
  • Policy change. glm_native_tool_boundary_keeps_request_model_and_name_guards encoded "a native boundary does not authorize an unregistered name". Authority still doesn't widen: Atlas executes nothing and the name is never mapped onto a declared tool. Only delivery changes, so the client can answer.
  • Counting native openers. The token handler tells the detector when the native opener token arrives outside a literal span (note_native_opener); the detector marks the next envelope it opens. A text-spelled opener processed in the same chunk before a pending native one could take its mark. I found no way to produce that ordering, and the cost would be one envelope delivered instead of kept as prose.
  • The blocking path's literal check moves into a shared native_opener_opens_call helper.

🤖 Generated with Claude Code

data-angel and others added 2 commits November 2, 2026 12:12
A GLM call opened by the native <tool_call> token whose name the request
did not declare was treated as prose. Streaming returned the raw envelope
as content (finish "stop"); blocking cut it and returned empty content. A
ZCode agent saw `<tool_call>mcp__accord__accord_sent<arg_key>id…` as the
assistant's reply after calling a tool it had read about in source but
was never offered, and its turn ended there.

The literal-XML rule exists for markup the model writes as text. The
native opener outside a quote or code span is a call, so its envelope now
reaches the client as a tool call under the name the model wrote. It is
never repaired onto a declared tool: blocking routes it around the fuzzy
validator, and the tool guard still inspects its arguments. The client
answers with its own unknown-tool result (ZCode: "Tool not found"), so
the agent's turn continues, as with a reference server. Markup spelled
without the native token, or inside a quote or code span, stays prose.

The blocking path's literal check moves into a shared
native_opener_opens_call helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The stream's finish reason counted calls the detector parsed, so a call
that validation rejected (unparseable arguments, a write path carrying
shell metacharacters) ended with finish_reason "tool_calls" and no tool
call in the response. An agent treats that as a tool turn with nothing
to run. Count the calls actually sent instead
(`tool_calls_emitted_count`, bumped wherever a ToolCallStart goes out);
salvaged calls keep their existing rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fixture path '/tmp/a b' was rejected only because it holds a space.
Atlas-Inf#323 accepts spaces in write paths, so with both changes the call
reaches the client and the finish-reason test fails. '/tmp/a; b' carries
a command separator, which the check rejects before and after Atlas-Inf#323.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
data-angel added a commit to Enntity/atlas that referenced this pull request Nov 3, 2026
@AzeezIsh

AzeezIsh commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Gated this head (55f7efd47) on reiner + spark2 against its base, both built fresh. Receipts are in reiner's ~/code/night1027/out/dap-322-55f7efd47/.

  • Qwen KL logit drift: exactly 0 (34,245 of 34,245 positions in each of 2 spark-config boots).
  • rc16: greedy C1 and C8 8/8 identical; tools 21/21.
  • BFCL ST-995: 87.54 / 86.85 (run-1793666524551147825), the same as main.
  • Bench: every cell is inside the base's run-to-run range.

Merging on green CI.

@AzeezIsh
AzeezIsh merged commit b07d46b into Atlas-Inf:main Nov 3, 2026
26 of 27 checks passed
@AzeezIsh

AzeezIsh commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Correction to which head each result came from:

  • KL 0 and the bench were measured on the merged head 55f7efd47 itself.
  • BFCL 87.54 / 86.85, greedy 8/8 and tools 21/21 come from the previous head 4ca502214. The two heads differ only in two test files (glm_boundary_case_tests.rs, glm_tool_boundary_tests.rs), so the production code those runs exercised is the same.

I stopped the redundant BFCL rerun on 55f7efd47.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants