[GH-ISSUE #2236] Bug: engine truncates the answer when generated text contains the literal EOS token string #890

Closed
opened 2026-11-04 01:46:48 +07:00 by bsakaguchi · 4 comments
Owner

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

  • Engine: strata 0.1.43 (server.py from the same tree)
  • OS: Ubuntu 22.04.5 LTS, kernel 5.15.0-185-generic
  • GPU: 2× NVIDIA L20 48G, dual-GPU layer split, no batch
  • Model: Qwen3.8-Flash-Next UD-Q4_K_XL GGUF, --spec 4, MTP drafts, --max-context 262144
  • Clients: OpenAI-compatible /v1/chat/completions with tools + reasoning_effort=medium, streaming on
    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.
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 - Engine: strata 0.1.43 (server.py from the same tree) - OS: Ubuntu 22.04.5 LTS, kernel 5.15.0-185-generic - GPU: 2× NVIDIA L20 48G, dual-GPU layer split, no batch - Model: Qwen3.8-Flash-Next UD-Q4_K_XL GGUF, --spec 4, MTP drafts, --max-context 262144 - Clients: OpenAI-compatible /v1/chat/completions with tools + reasoning_effort=medium, streaming on 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(如 </s>、[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.
Author
Owner

@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-ids adds. 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). The raw: 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:

  • The prompt side is not the problem. Since 0.1.43.1 (#2026) and the 0.1.44 additions, a control-token string inside a message is read as text, so an old conversation that quotes these markers is not poisoned on the way in. If it still goes wrong with such a history, the model is copying the marker out of it as the id again, and that is the case above.
  • We cannot tell from the id whether the model meant "end my turn" or "write the marker". Ignoring the id would also stop real turn ends, so the default stays as it is.
  • Cheapest workaround today: ask for the marker with a break in it (<|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 set max_tokens). If it still stops at the marker, we have misread something and want to see that log.

<!-- gh-comment-id:6153518432 --> @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-ids` adds. 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). The `raw:` 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: - The prompt side is not the problem. Since 0.1.43.1 (#2026) and the 0.1.44 additions, a control-token string inside a message is read as text, so an old conversation that quotes these markers is not poisoned on the way in. If it still goes wrong with such a history, the model is copying the marker out of it as the id again, and that is the case above. - We cannot tell from the id whether the model meant "end my turn" or "write the marker". Ignoring the id would also stop real turn ends, so the default stays as it is. - Cheapest workaround today: ask for the marker with a break in it (`<|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 set `max_tokens`). If it still stops at the marker, we have misread something and want to see that log.
Author
Owner

@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

  • Does the model emit the marker in the answer itself? Yes. Engine 0.1.44.1, IQ3_S, temperature: 0:
    the marker text is published in content in 5/5 runs, spelled out with ordinary character tokens.
  • The logit_bias {"248046": -100} check. Your reading is confirmed: 0/5 stop, the model spells the
    marker 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.
  • The case that actually truncates here has no think block open. Asking for raw chat-template text with
    reasoning_effort: none gives 5/5 stop, 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 on
    the id while a <think> block is open" would not cover that one.
  • I could not reproduce my input-side priming claim against a control (10 runs with the literal marker
    in a tool block, 10 with it masked, prompt_tokens 109 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 a
signal the server already has, and it is the one any recovery would have to key off.

<!-- gh-comment-id:6194104556 --> @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 - **Does the model emit the marker in the answer itself?** Yes. Engine 0.1.44.1, IQ3_S, `temperature: 0`: the marker text is published in `content` in 5/5 runs, spelled out with ordinary character tokens. - **The `logit_bias {"248046": -100}` check.** Your reading is confirmed: 0/5 stop, the model spells the marker 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. - **The case that actually truncates here has no think block open.** Asking for raw chat-template text with `reasoning_effort: none` gives 5/5 `stop`, 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 on the id while a `<think>` block is open" would not cover that one. - **I could not reproduce my input-side priming claim** against a control (10 runs with the literal marker in a tool block, 10 with it masked, `prompt_tokens` 109 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 a signal the server already has, and it is the one any recovery would have to key off.
Author
Owner

@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):

  • Steps 1-12: normal, stopReason: toolUse, the model even spells out <|im_start|> (not an EOS id) freely in reasoning.
  • Step 13: the model explains how the Qwen chat template renders messages, writes `<|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 stop code 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.)

<!-- gh-comment-id:6290125999 --> @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):** - Steps 1-12: normal, `stopReason: toolUse`, the model even spells out `<|im_start|>` (not an EOS id) freely in reasoning. - Step 13: the model explains how the Qwen chat template renders messages, writes `` `<|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 `stop` code 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.)*
Author
Owner

@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:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6659269406 --> @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: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#890
No description provided.