Skip to content

tokenizer: linear sentinel scan; keep GLM turn tokens literal in prompts - #294

Merged
AzeezIsh merged 2 commits into
Atlas-Inf:mainfrom
Enntity:fix/request-input-hardening-v2
Oct 31, 2026
Merged

AzeezIsh merged 2 commits into
Atlas-Inf:mainfrom
Enntity:fix/request-input-hardening-v2

Conversation

@data-angel

Copy link
Copy Markdown
Contributor

Summary

Two request-input fixes in prompt encoding. Neither changes prompts that don't contain the affected strings, apart from the Qwen note below.

  • Sentinel scan is linear. encode_with_sentinel_families searched each family's opener over the whole remaining prompt on every iteration. A message full of literal <tool_call> on GLM or Qwen4_exp scanned quadratically, and a bare U+FDD0 reached the same cost on any model by searching the rest of the prompt for its close. This ran in spawn_blocking before admission, and 32 MiB fits the default body limit.
  • GLM turn tokens stay literal. <|system|>, <|user|>, <|assistant|> and <|observation|> were outside the escape list, so a fetched page in a tool result could open a real user turn. Argument names were skipped, and tool schemas never reached the escape. The SparkGLM profiles set ATLAS_USE_HF_REF_JSON_DUMPS=1, whose tojson leaves < raw, so schemas and nested arguments forge there. Default-mode tojson encodes < and hides this.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --tests, with the ci.yml env, no warnings. The template's --all-features form stops on objc2 on Linux.
  • bash scripts/check-license-headers.sh: not run, no new files.
  • Real model / hardware: not run. The role tokens were checked on the production GLM tokenizer.json: each encodes as plain text and reads back unchanged.
  • Added tests, each seen failing first:
    • many_sentinels_do_not_rescan_a_family_with_none, unclosed_openers_do_not_rescan_for_a_close, a_body_too_long_for_an_index_stays_text
    • role_tokens_in_results_arguments_and_schemas_stay_text (six cases, both tojson modes)
    • qwen_tool_markers_in_schemas_stay_text
  • spark-server filters tokenizer:: 96, api::chat:: 112, literal_xml 13, all passing. The workspace suite was not run locally.

The scan's encoder calls matched the old code on 1.2M random sentinel strings across three family sets (26,906 spelled markers). The only difference is a garbage body over 20 characters, which this code never writes, now staying text.

Preliminary, single run, debug test build in a container: 15.9 s for 2.6 MiB and 18.3 s for 1.5 MiB before the fix; 2.9 s and 12.5 s for full 32 MiB inputs after.

Notes for reviewers

These are security-relevant and SECURITY.md asks for private reports. The commits were already public on Enntity/atlas when that was noticed, so this comes as a normal PR.

Authorship

AI-authored (Claude Code). No human-written code.

🤖 Generated with Claude Code

data-angel and others added 2 commits October 31, 2026 10:21
encode_with_sentinel_families searched every family's opener over the
whole remaining prompt on each iteration, so a message full of literal
<tool_call> on GLM or Qwen4_exp scanned quadratically while the other
family had no openers. A bare U+FDD0 reached the same cost on any model:
each one searched the rest of the prompt for its close. Both ran in
spawn_blocking before admission, and 32 MiB fits the default body limit.

Keep each family's next opener between iterations and stop the close
search at the longest index a sentinel can hold. Encoder calls match the
old code on 1.2M random sentinel strings; only a garbage body over 20
characters, which this code never writes, now stays text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
<|system|>, <|user|>, <|assistant|> and <|observation|> were outside the
escape list, so a fetched page in a tool result could open a real user
turn. Argument names were skipped too, and tool schemas never reached the
escape at all. The SparkGLM profiles set ATLAS_USE_HF_REF_JSON_DUMPS=1,
whose tojson leaves `<` raw, so schemas and nested arguments forge there.

Escape the four tokens, every argument key, and tool schemas. Schemas
follow SparkQwen 0.4.0, which already escapes them on both models. Qwen4_exp
has none of the turn tokens; beyond 0.4.0 its prompts change only for an
argument name carrying a tool marker.

This departs from SparkGLM 0.2.0 for prompts containing those strings.
</think> and <|endoftext|> stay native: the template splits assistant
text on the first, and neither opens a turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@data-angel
data-angel requested a review from AzeezIsh as a code owner October 31, 2026 17:30
@AzeezIsh
AzeezIsh merged commit 8e91751 into Atlas-Inf:main Oct 31, 2026
1 check passed
@AzeezIsh

Copy link
Copy Markdown
Contributor

Merged after a pair gate on reiner + spark2 against its parent, #283's head. Receipts are in reiner's ~/code/night1027/out/dap294-c5fcb14b8/.

  • rc16: C1 and C8 greedy 8/8 identical, tools 21/21.
  • 0.4.0 spark config: union_check 16/16 and api_parity 26/26, both identical to the parent.
  • Live prompt tokens for requests containing tool markup are unchanged: 326 / 310 / 306.

I'm merging it into the SparkQwen stack, taking #293's side in template.rs as you suggested.

@AzeezIsh

AzeezIsh commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

GB10 single-Spark confirmation (sparky, post-merge): this PR was gated as part of integ/train-2026-10-31 (#285 + #284 + #287 + #290 + #293 + #294 + #286 on main 170c3ed) against main at the same base, FP4-Local default recipe profile:

  • controls: FP4-Local byte-identical, Flash-Next NVFP4 byte-identical.
  • BFCL ST-995: train 87.54 / 85.94 (run-1793488879414911145) = base 87.54 / 85.94 (run-1793503255896245487); all 15 subsets identical.
  • agentic-webserver 50: train 47/50, 10.80 s/turn (run-1793478986972058487) vs base 47/50, 10.67 s/turn (run-1793493326878881549). The same 3 iterations (0, 18, 27) fail on both arms ("no Cargo.toml was written"), so that comes from main, not this train. Investigating separately.
  • spark-server tests 3002/0; 0 serve errors.
    Campaign log: docs: FP4-Local post-merge campaign log (2026-10, sparky) #211.

AzeezIsh pushed a commit that referenced this pull request Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@data-angel
data-angel deleted the fix/request-input-hardening-v2 branch November 3, 2026 05:07
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