mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2236] Bug: engine truncates the answer when generated text contains the literal EOS token string #890
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#890
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 @tspine on GitHub (Oct 13, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2236
Bug: engine truncates the answer when the generated text contains the literal EOS token string
Summary
When the model's generated output contains the literal string for the EOS marker (the <|im_end|> token), the engine immediately stops generation. The result is finish_reason: "stop" with an empty or truncated content, while the reasoning phase rendered normally. From the client's point of view it looks like "the model thought, then gave no answer."
This is a different string from the </tool_call> literal fixed in v0.1.43.1 (#2026), so upgrading to 0.1.43.1 does not fix this one.
Environment
Reproduction (minimal, deterministic)
Ask the model to reproduce the literal EOS string, e.g. (OpenAI chat, non-stream):
messages = [{"role": "user", "content": "Please output the literal EOS token string verbatim, then explain it in three sentences."}]
max_tokens = 2000
Observed with STRATA_DEBUG=1, the raw: dump shows generation stops exactly at the point where the string is emitted:
[strata] raw: 'The user wants me to:\n1. Output the string "<|im_end|>'
[strata] done: 14 tokens in 1 s (135.0 tok/s) (stop, cancel=False)
The content field comes back empty (finish_reason=stop), because the answer was cut before it finished.
Even mentioning the token as an example triggers it (the second minimal case):
messages = [{"role": "user", "content": "Explain what an end-of-text token is, in three sentences."}]
[strata] raw: '用户要求我解释"end of text token"的作用...\n\nEnd of text token(如 、[EOS]、<|im_end|>'
[strata] done: 48 tokens in 1 s (108.9 tok/s) (stop, cancel=False)
Expected
The literal EOS string inside generated text should be treated as ordinary text (or escaped), not as a generation stop signal. Only the actual EOS token id should stop generation.
Why this matters / how it surfaced in practice
This bit us in a real workflow: an agent session (with tools + long history) happened to discuss Strata release notes, whose content quotes these literal token strings. The model then quoted them in its answer and killed its own response, producing "thought but no answer" across multiple clients. Because the poisoned context gets persisted (e.g. memory/context injection), it leaked into new sessions until the offending history was removed.
Note on v0.1.43.1
Please confirm whether this EOS-literal case is covered by any upcoming fix. #2026 fixed the </tool_call> literal, but the <|im_end|> literal appears to still be unhandled in 0.1.43.1.
@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks @tspine, the two minimal cases and the
raw:dumps made this easy to place.We read the stop code for this, and it does not look at the text. The engine stops on token ids only:
<|endoftext|>(248044) and<|im_end|>(248046), plus whatever--eos-idsadds. The server's own stop check is on the same two ids. So the literal string<|im_end|>in the generated text does not stop anything by itself.What your dumps show is the model emitting the real end-of-turn token. In "output the literal EOS string" the model writes
<|im_end|>as the single token 248046, because that is how the string appears in its training text (the tokenizer parses it as the special token). Theraw:line prints that token as its text, so it looks like a string in the middle of the answer, and the generation ends right after it (stop, 14 tokens). The second case ("explain an end-of-text token") is the same: the model quotes the marker as the id while it is still inside its reasoning.What this means in practice:
<|im_end|plus|>as two words, or in a code block), or put "write the marker in spaced-out form" in the system prompt of the agent that quotes release notes.If you want to go further, we can add an opt-in that does not stop on the id while the model is still inside an open
<think>block (a real turn end never comes there), which would cover your second case. We have not measured it, so it would start opt-in. Would that cover your agent workflow, or does the model also emit the marker in the answer itself?To check our reading on your side: send the same request with
"logit_bias": {"248046": -100}. The model then has to spell the marker in pieces, and the answer should continue past it (it will not end its turn properly, so setmax_tokens). If it still stops at the marker, we have misread something and want to see that log.@nashcap commented on GitHub (Oct 15, 2026):
@Niko1221 you asked two direct questions in this thread and one of them is about my case (#2266), so here
are the answers measured on my box; full data and the harness are in https://github.com/Niko1221/Strata/issues/2266#issuecomment-6194100529
temperature: 0:the marker text is published in
contentin 5/5 runs, spelled out with ordinary character tokens.logit_bias {"248046": -100}check. Your reading is confirmed: 0/5 stop, the model spells themarker out. But the bias is a diagnostic, not a fix — the output degenerates into repetition until
max_tokens. My own suggested "retry with a logit bias" does not work; I have withdrawn it.reasoning_effort: nonegives 5/5stop, 4/5 of them after 3 tokens (content=<|im_start|>user),with no marker text in
content— so the id was consumed mid-task. A rule of the form "do not stop onthe id while a
<think>block is open" would not cover that one.in a tool block, 10 with it masked,
prompt_tokens109 in both, no early or empty turns in either arm),so I have dropped it. Your explanation — the model copying the marker out as the id — is the one that
survives on my box.
One thing that made all of this separable: your engine never prints the stop token's text. So when the
marker text does appear in
content, it was spelled out, and when the id is sampled it does not. That is asignal the server already has, and it is the one any recovery would have to key off.
@smallmj commented on GitHub (Oct 20, 2026):
Independent confirmation on Qwen3.8-Flash-Next IQ3_S (a lower quant than the OP's UD-Q4_K_XL), engine 0.1.46, Windows, and a new data point: prompt-side avoidance instructions measurably fail in agentic use.
Setup: DSH agent harness (tools + long history) driving server.py on this box. The task was analyzing a SillyTavern script's format handling — chat templates, stopping strings,
<think>/<tool_call>parsing. Exactly the "agent reasoning about chat formats" case #2266 described.What the session log shows (13-step turn):
stopReason: toolUse, the model even spells out<|im_start|>(not an EOS id) freely in reasoning.`<|im_start|>{role}\n{content}'— and the very next thing it must produce is<|im_end|>. It samples id 248046, generation stops,stopReason: stop, blocks end mid-sentence with no text or tool call after the reasoning block.Why the user-side mitigation is a dead end: we explicitly instructed the model to avoid emitting the literal (use a spaced form or a name). The model complied for 12 steps and still slid into the real EOS id on the 13th — the task itself requires naming that token, and at the tokenizer level the literal and the EOS id are the same thing. Prompt instructions fight the training prior and lose probabilistically; a 13-step turn only needs one slip, and each slip ends the turn with the same
stopcode a natural end uses, so the harness cannot distinguish truncation from completion and the task dies silently.Input side is clean here (confirms the #537 fix holds): all four truncations in the session were generation-side sampling of id 248046, none involved input-encoded specials.
On the logit_bias diagnostic from @nashcap: agreed it is not production-viable for agents — an agent loop needs a natural end-of-turn signal, and banning 248046 removes the only one the model has.
Happy to provide the session log excerpts or a minimal repro on 0.1.46 if useful. The practical impact statement for prioritization: any agent workflow whose subject matter is prompt formats, templates or tokenizers (the exact workflows local-model users point Strata at) trips this deterministically, and there is no client-side workaround that survives contact with the task.
(Edit: fixed the accidental JSON wrapper from the first post attempt.)
@Niko1221 commented on GitHub (Nov 5, 2026):
Thanks for taking the time to report this.
Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. 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.