mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2266] Marker-shaped text truncates agent turns (EOS sampling + semantic priming) #907
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#907
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @nashcap on GitHub (Oct 13, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2266
Marker-shaped text truncates agent turns (EOS sampling + semantic priming)
Environment: Strata 0.1.42, commit
61b3fb5d, model Qwen3.8-Flash-Next IQ3_S, Linux, single CUDA GPU, default run config, loopback.Summary
The chat end-of-turn marker (
<|im_end|>) is the model's EOS token (id 248046,tokenizer.ggml.eos_token_id). Two consequences for agentic use:Special tokens in the input are not tokenized as special ids (verified below) — that defense works. The problem is the model's own sampling, which no input sanitizing can prevent.
Finding 1 — generating marker-shaped text stops the engine
The end-of-turn marker is one token in the vocabulary, and it is the EOS token:
Repro (the marker is built from hex so the command itself contains no literal marker):
Observed (marker shown escaped): every run →
finish: stop | content: '<~im_end~>'.The model samples id 248046; the engine treats it as end-of-turn and stops. In a longer message the cut happens mid-sentence: any agent reasoning about chat formats (explaining this very bug, processing a dataset of chat templates, quoting a prompt-injection corpus) is silently truncated.
It is probabilistic: with reasoning enabled, the model sometimes spells the marker out with ordinary character tokens and generation continues (observed
finish_reason: lengthwith the marker intact inreasoning_content). So the truncation is intermittent and hard for users to reproduce or understand.Note also: the decoded marker text is published in
contentwithfinish_reason: stop— downstream clients see the literal marker in the answer.Finding 2 — marker-shaped plain text in the input primes an immediate EOS
Input sanitizing works: a user message containing the literal marker is tokenized as plain text, not as the special id — identical
prompt_tokensfor the marker and for the marker with a space inserted (20 vs 20).But the plain text still has a strong effect: in a live agent session, a tool result that echoed the marker (a
grepover the chat template) was followed by the model emitting EOS immediately — the turn ended with no output, repeatedly, until the tool output was masked (tr '[|]' '~').Impact: any file, web page, or pasted transcript containing marker-shaped text can silently end an agent turn early. For a coding agent this is an availability problem reachable by ordinary repository content. (It also means a webpage author can deliberately stall an agent, though they cannot forge a turn, thanks to the working input defense.)
Suggested mitigations
content/reasoning_contentbefore publishing to clients, so the literal marker never leaves the server.serve/logit_bias.pyalready has the plumbing).tr '[|]' '~') when a session may discuss chat formats.What is NOT broken
@qiuzan2001 commented on GitHub (Oct 15, 2026):
Same mechanism as #2236 (open): the maintainer's answer there is that the engine and the server stop on token ids only (248044
<|endoftext|>, 248046<|im_end|>, plus--eos-ids), never on text, and the cut comes from the model sampling the real id 248046 when it writes the marker. Your output-side case is that one; the input-side priming (marker-shaped text in tool output making the model end its turn) and the mitigations are the new parts here, so it may be easiest to follow both in one thread.@nashcap commented on GitHub (Oct 15, 2026):
Measured on 0.1.44.1: both questions answered, and one of my own claims does not survive
I re-ran this properly after @qiuzan2001 pointed at #2236, because @Niko1221 asked two direct questions in
that thread and one of them is about my case. Short version: his reading of the mechanism is confirmed, my
Finding 1 was stated too broadly, and my Finding 2 does not survive a control.
Environment: engine v0.1.44.1, model Qwen3.8-Flash-Next IQ3_S (a different quant from @tspine's
UD-Q4_K_XL, same failure), single CUDA GPU, loopback,
temperature: 0,reasoning_effort: noneunlessstated. One harness, ten arms, one run of each; the script is at the bottom and the raw output is a paste
of that run.
A useful observation first: the engine never prints the stop token
Arm G below stops with no marker text in
content. So when the marker text does appear incontent,it was spelled out with ordinary character tokens, not emitted as the id. That is what makes the next two
sections separable at all.
Q1: does the model emit the marker in the answer itself? Yes
finish: stop, 7 tokens,content= the markerreasoning_effort: mediumstop, 46-49 tokens; the marker appears inreasoning_contentand incontentIt is published in the answer, spelled out. So a client sees the literal marker either way.
Q2: the
logit_bias {"248046": -100}check — his reading is confirmed, but the bias is not a fixfinish: length, 200 tokens:<marker>then blank line, over and over<marker>HELLO, 9 tokens, HELLO survives — so without any bias the model spelled the marker out and then ended its turn normally<marker>HELLO<marker>HELLO…Arm I is the one I would have wanted earlier: it separates "the id was sampled" from "the marker was
written as text and the model then ended its turn properly". Here the word after the marker survives, so
arm A's
stopis a normal end-of-turn, not a cut.And the bias does not recover the task, it only removes the stop and the output degenerates into
repetition until
max_tokens. Mitigation 2 in my body ("retry the continuation with a small logit bias")does not work as written. I was wrong about that.
What actually breaks: the model using the marker as a boundary in what it writes
stop. 4/5 after 3 tokens,content= `<This is the failure, it is deterministic, and it runs with
reasoning_effort: none, so no<think>blockis open when the id is sampled — a rule of the form "do not stop on the id while a think block is open"
would not cover it.
What the model does with the marker depends on what you ask for:
content, mid-sentence, and generation continues past itSo this sentence in my body is too broad: "when the model generates marker-shaped text, it often samples
that single token id". Measured: quoting the marker is spelled out with ordinary tokens and the turn
continues; using it as a boundary in what it is writing samples the id. The second is the failure, and
it is reachable by ordinary work — editing a chat template, a prompt file, a tokenizer config, or a dataset
of chat formats.
My Finding 2 (input-side priming) does not survive a control
<~im_end~>prompt_tokensis 109 in both arms, so the input defense is doing its job: the literal marker is notencoded as the special id. And the priming effect is not there in this shape.
I wrote "reliably primes" from one live agent session on 0.1.42 and I should not have. The likely
explanation is @Niko1221's: the model copied the marker out of the context as the id, which is the case
above, not plain text priming. I am dropping that claim unless I can reproduce it under a control. If
anyone has a turn that ended with an empty answer and
finish_reason: stopright after a tool resultcontaining marker-shaped text, the thing that would settle it is the
raw:token dump from #2236, becausethat separates the two mechanisms.
What this changes in my suggested mitigations
contentstill protects downstream clients, but ithas a measurable cost: in arm F the answer legitimately discusses the marker, and in arm D nine of ten
runs quote it in a sentence the user asked for. Stripping would mangle correct answers. The engine
already knows which case happened — it is the difference between arm G (stop, no marker text) and arm F
(marker text, turn continues) — so if anything is filtered, that is the signal to use, not the text.
the model to print raw chat-template text; ask it to write a placeholder and substitute the markers in
the tool. Arm G is what that mistake costs: three tokens and a
stop.One suggestion that follows from the data rather than from my earlier guess: an opt-in, per request, of "for
this request do not treat 248046 as end-of-turn, publish its text and keep going". That differs from the
logit bias because it leaves the model's distribution alone and changes only what the server does with the
id. Arm G would then produce the template instead of three tokens. The loop in arms B, H and J is the risk,
so it would need a token cap, and it would start opt-in.
the harness (ten arms, one command per arm; the marker is built from escapes so the file contains no literal marker)
raw output of that run (engine 0.1.44.1, one run per arm, nothing edited)
@Niko1221 commented on GitHub (Oct 19, 2026):
Thanks for taking the time to report this.
We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.
To reopen it takes about two minutes:
/reopen. A check runs and either reopens the issue or lists what is still missing.The rules are in CONTRIBUTING.md.