[GH-ISSUE #4035] [Engine] Newline stop at max_tokens returns finish_reason "length" after removing the stop #1741

Open
opened 2026-11-04 01:53:38 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @Jackmeson1 on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4035

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

On /v1/chat/completions with stop: ["\n"] and max_tokens: 3, a greedy answer whose third token is the newline comes back as "ALPHA" with finish_reason: "length". The server recognised the stop string and removed it from the content, but reports the token cap as the reason.

The same request on /v1/messages (stop_sequences: ["\n"], max_tokens: 3) returns stop_reason: "stop_sequence" with stop_sequence: "\n".

Expected: finish_reason: "stop". docs/DETAILS.md ("Current limits") says the answer ends before the first stop string, which is not sent, with finish_reason "stop" (stop_reason "stop_sequence" on the Anthropic side).

From the code at 7dd5cf18:

  • serve/server.py:5606-5610 builds the done record with the engine's finish ("length" here) and adds stop_sequence when stops.hit is set, without changing finish.
  • The Anthropic path (serve/server.py:6025) checks stop_sequence first, so it reports stop_sequence.
  • The OpenAI path (serve/server.py:5886) maps from finish alone, so length stays length.

Smallest steps or command that reproduce it

Checkout 7dd5cf18e68c639a8773e096c5c79f971ea2a9f5. build/ was configured with CMake; the values from build/CMakeCache.txt are: generator Unix Makefiles, CMAKE_BUILD_TYPE=Release, STRATA_ENABLE_CUDA=ON, CMAKE_CUDA_ARCHITECTURES=120.

Server config I ran (area3_config.json):

{
  "exe": "/content/Strata/build/strata",
  "cwd": "/content/Strata",
  "tokenizer": "/content/Strata-data/packs/q2_0/tokenizer",
  "model_name": "qwen3.8-flash-next-q2_0",
  "log": "/content/area3_engine.log",
  "args": [
    "--pack", "/content/Strata-data/packs/q2_0",
    "--native", "/content/Strata-data/models/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf",
    "--ple-gguf", "/content/Strata-data/models/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf",
    "--expert-profile", "/content/Strata/data/expert-profile.bin",
    "--expert-cache", "auto",
    "--prefill", "512",
    "--spec", "4",
    "--spec-min-p", "0.5",
    "--mtp", "/content/Strata-data/mtp/rt",
    "--max-context", "4096",
    "--kv", "int8",
    "--ple-io", "ram",
    "--vram-reserve-mib", "74000",
    "--adapt-swaps", "0",
    "--pcie-frac", "0"
  ]
}
cd /content/Strata
python3 serve/server.py --engine strata --config /content/area3_config.json --host 127.0.0.1 --port 18091

Client, from another terminal:

import json
import urllib.request

base = "http://127.0.0.1:18091"
messages = [{
    "role": "user",
    "content": "Write exactly these two lines and nothing else:\nALPHA\nBETA"
}]

def post(path, body):
    req = urllib.request.Request(
        base + path,
        data=json.dumps(body).encode(),
        headers={"Content-Type": "application/json"}
    )
    with urllib.request.urlopen(req, timeout=180) as response:
        return json.load(response)

for cap, stop in [(20, False), (20, True), (3, False), (3, True)]:
    body = {
        "model": "strata",
        "messages": messages,
        "temperature": 0,
        "reasoning_effort": "none",
        "max_tokens": cap
    }
    if stop:
        body["stop"] = ["\n"]
    result = post("/v1/chat/completions", body)
    choice = result["choices"][0]
    print(json.dumps({
        "max_tokens": cap,
        "stop_enabled": stop,
        "content": choice["message"]["content"],
        "finish_reason": choice["finish_reason"],
        "completion_tokens": result["usage"]["completion_tokens"]
    }))

result = post("/v1/messages", {
    "model": "strata",
    "messages": messages,
    "temperature": 0,
    "thinking": {"type": "disabled"},
    "max_tokens": 3,
    "stop_sequences": ["\n"]
})
print(json.dumps({
    "content": result["content"],
    "stop_reason": result["stop_reason"],
    "stop_sequence": result.get("stop_sequence"),
    "output_tokens": result["usage"]["output_tokens"]
}))

The max_tokens: 3 control without a stop returns ALPHA\n, so the third token is the newline. I ran only this config (--vram-reserve-mib 74000 leaves a partial expert cache on this 97,887 MiB card); the finish mapping above is in serve/server.py, not in the engine.

Reproduction status

Reproduced locally, and again on 0.2.11 (see Strata version)

Strata version

0.2.11 (commit c3b3f50355, engine 0.1.57), re-tested 2026-11-05. Still present. Through serve/server.py with the repository's byte tokenizer and a scripted engine output ALPHA\nBETA (no GPU), a request with a newline stop and a 6-token cap returns ALPHA with the OpenAI finish_reason length, streaming and non-streaming; the Anthropic endpoint reports stop_sequence. The final flush in Service._run (server.py around line 6720) still matches the stop after the loop, and the done record keeps finish="length". The GPU reproduction above is from the original commit.

Originally reported on commit 7dd5cf18e6 (main), engine 0.1.49.2

Graphics card, memory and system

NVIDIA RTX PRO 6000 Blackwell Server Edition 97,887 MiB · 176 GiB RAM · Ubuntu 24.04.4 LTS (Linux 6.6.122+, Google Colab), driver 580.82.07, CUDA 13.0.88, GCC 13.3.0, Python 3.13.16, AMD EPYC 9B45 (48 logical CPUs)

Model, size and settings

Qwen3.8-Flash-Next GSQ-RCO Q2_0 (two GGUF parts, pack, MTP draft layer) · 4096 context · INT8 KV · settings as in the config above

Logs

Client output (my run, 2026-10-25):

{"max_tokens": 20, "stop_enabled": false, "content": "ALPHA\nBETA", "finish_reason": "stop", "completion_tokens": 6}
{"max_tokens": 20, "stop_enabled": true, "content": "ALPHA", "finish_reason": "stop", "completion_tokens": 4}
{"max_tokens": 3, "stop_enabled": false, "content": "ALPHA\n", "finish_reason": "length", "completion_tokens": 3}
{"max_tokens": 3, "stop_enabled": true, "content": "ALPHA", "finish_reason": "length", "completion_tokens": 3}
{"content": [{"type": "text", "text": "ALPHA"}], "stop_reason": "stop_sequence", "stop_sequence": "\n", "output_tokens": 3}

Server log, one done line per request in the same order:

[strata] done: 6 tokens in 0 s (117.0 tok/s) (stop, cancel=False), expert cache 72.4% hit
[strata] done: 4 tokens in 0 s (232.6 tok/s) (stop, cancel=False), expert cache 79.2% hit
[strata] done: 3 tokens in 0 s (148.5 tok/s) (length, cancel=False), expert cache 79.2% hit
[strata] done: 3 tokens in 0 s (149.3 tok/s) (length, cancel=False), expert cache 79.2% hit
[strata] done: 3 tokens in 0 s (149.3 tok/s) (length, cancel=False), expert cache 79.2% hit

Not checked: streaming responses at this boundary, other models, other engine settings.

Originally created by @Jackmeson1 on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4035 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### What happened On `/v1/chat/completions` with `stop: ["\n"]` and `max_tokens: 3`, a greedy answer whose third token is the newline comes back as `"ALPHA"` with `finish_reason: "length"`. The server recognised the stop string and removed it from the content, but reports the token cap as the reason. The same request on `/v1/messages` (`stop_sequences: ["\n"]`, `max_tokens: 3`) returns `stop_reason: "stop_sequence"` with `stop_sequence: "\n"`. Expected: `finish_reason: "stop"`. `docs/DETAILS.md` ("Current limits") says the answer ends before the first stop string, which is not sent, with `finish_reason` "stop" (`stop_reason` "stop_sequence" on the Anthropic side). From the code at `7dd5cf18`: - `serve/server.py:5606-5610` builds the `done` record with the engine's `finish` ("length" here) and adds `stop_sequence` when `stops.hit` is set, without changing `finish`. - The Anthropic path (`serve/server.py:6025`) checks `stop_sequence` first, so it reports `stop_sequence`. - The OpenAI path (`serve/server.py:5886`) maps from `finish` alone, so `length` stays `length`. ### Smallest steps or command that reproduce it Checkout `7dd5cf18e68c639a8773e096c5c79f971ea2a9f5`. `build/` was configured with CMake; the values from `build/CMakeCache.txt` are: generator Unix Makefiles, `CMAKE_BUILD_TYPE=Release`, `STRATA_ENABLE_CUDA=ON`, `CMAKE_CUDA_ARCHITECTURES=120`. Server config I ran (`area3_config.json`): ```json { "exe": "/content/Strata/build/strata", "cwd": "/content/Strata", "tokenizer": "/content/Strata-data/packs/q2_0/tokenizer", "model_name": "qwen3.8-flash-next-q2_0", "log": "/content/area3_engine.log", "args": [ "--pack", "/content/Strata-data/packs/q2_0", "--native", "/content/Strata-data/models/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf", "--ple-gguf", "/content/Strata-data/models/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf", "--expert-profile", "/content/Strata/data/expert-profile.bin", "--expert-cache", "auto", "--prefill", "512", "--spec", "4", "--spec-min-p", "0.5", "--mtp", "/content/Strata-data/mtp/rt", "--max-context", "4096", "--kv", "int8", "--ple-io", "ram", "--vram-reserve-mib", "74000", "--adapt-swaps", "0", "--pcie-frac", "0" ] } ``` ```bash cd /content/Strata python3 serve/server.py --engine strata --config /content/area3_config.json --host 127.0.0.1 --port 18091 ``` Client, from another terminal: ```python import json import urllib.request base = "http://127.0.0.1:18091" messages = [{ "role": "user", "content": "Write exactly these two lines and nothing else:\nALPHA\nBETA" }] def post(path, body): req = urllib.request.Request( base + path, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"} ) with urllib.request.urlopen(req, timeout=180) as response: return json.load(response) for cap, stop in [(20, False), (20, True), (3, False), (3, True)]: body = { "model": "strata", "messages": messages, "temperature": 0, "reasoning_effort": "none", "max_tokens": cap } if stop: body["stop"] = ["\n"] result = post("/v1/chat/completions", body) choice = result["choices"][0] print(json.dumps({ "max_tokens": cap, "stop_enabled": stop, "content": choice["message"]["content"], "finish_reason": choice["finish_reason"], "completion_tokens": result["usage"]["completion_tokens"] })) result = post("/v1/messages", { "model": "strata", "messages": messages, "temperature": 0, "thinking": {"type": "disabled"}, "max_tokens": 3, "stop_sequences": ["\n"] }) print(json.dumps({ "content": result["content"], "stop_reason": result["stop_reason"], "stop_sequence": result.get("stop_sequence"), "output_tokens": result["usage"]["output_tokens"] })) ``` The `max_tokens: 3` control without a stop returns `ALPHA\n`, so the third token is the newline. I ran only this config (`--vram-reserve-mib 74000` leaves a partial expert cache on this 97,887 MiB card); the finish mapping above is in `serve/server.py`, not in the engine. ### Reproduction status Reproduced locally, and again on 0.2.11 (see Strata version) ### Strata version 0.2.11 (commit c3b3f5035506, engine 0.1.57), re-tested 2026-11-05. Still present. Through `serve/server.py` with the repository's byte tokenizer and a scripted engine output `ALPHA\nBETA` (no GPU), a request with a newline stop and a 6-token cap returns `ALPHA` with the OpenAI `finish_reason` **`length`**, streaming and non-streaming; the Anthropic endpoint reports `stop_sequence`. The final flush in `Service._run` (server.py around line 6720) still matches the stop after the loop, and the done record keeps `finish="length"`. The GPU reproduction above is from the original commit. Originally reported on commit 7dd5cf18e68c639a8773e096c5c79f971ea2a9f5 (main), engine 0.1.49.2 ### Graphics card, memory and system NVIDIA RTX PRO 6000 Blackwell Server Edition 97,887 MiB · 176 GiB RAM · Ubuntu 24.04.4 LTS (Linux 6.6.122+, Google Colab), driver 580.82.07, CUDA 13.0.88, GCC 13.3.0, Python 3.13.16, AMD EPYC 9B45 (48 logical CPUs) ### Model, size and settings Qwen3.8-Flash-Next GSQ-RCO Q2_0 (two GGUF parts, pack, MTP draft layer) · 4096 context · INT8 KV · settings as in the config above ### Logs Client output (my run, 2026-10-25): ```text {"max_tokens": 20, "stop_enabled": false, "content": "ALPHA\nBETA", "finish_reason": "stop", "completion_tokens": 6} {"max_tokens": 20, "stop_enabled": true, "content": "ALPHA", "finish_reason": "stop", "completion_tokens": 4} {"max_tokens": 3, "stop_enabled": false, "content": "ALPHA\n", "finish_reason": "length", "completion_tokens": 3} {"max_tokens": 3, "stop_enabled": true, "content": "ALPHA", "finish_reason": "length", "completion_tokens": 3} {"content": [{"type": "text", "text": "ALPHA"}], "stop_reason": "stop_sequence", "stop_sequence": "\n", "output_tokens": 3} ``` Server log, one `done` line per request in the same order: ```text [strata] done: 6 tokens in 0 s (117.0 tok/s) (stop, cancel=False), expert cache 72.4% hit [strata] done: 4 tokens in 0 s (232.6 tok/s) (stop, cancel=False), expert cache 79.2% hit [strata] done: 3 tokens in 0 s (148.5 tok/s) (length, cancel=False), expert cache 79.2% hit [strata] done: 3 tokens in 0 s (149.3 tok/s) (length, cancel=False), expert cache 79.2% hit [strata] done: 3 tokens in 0 s (149.3 tok/s) (length, cancel=False), expert cache 79.2% hit ``` Not checked: streaming responses at this boundary, other models, other engine settings.
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:6659870962 --> @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).
Author
Owner

@Jackmeson1 commented on GitHub (Nov 5, 2026):

Re-tested on 0.2.11; the result is in the updated Strata version section of the issue.

<!-- gh-comment-id:6660609957 --> @Jackmeson1 commented on GitHub (Nov 5, 2026): Re-tested on 0.2.11; the result is in the updated Strata version section of the issue.
Author
Owner

@Jackmeson1 commented on GitHub (Nov 5, 2026):

/reopen

<!-- gh-comment-id:6660643771 --> @Jackmeson1 commented on GitHub (Nov 5, 2026): /reopen
Author
Owner

@github-actions[bot] commented on GitHub (Nov 5, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6660649775 --> @github-actions[bot] commented on GitHub (Nov 5, 2026): Reopened, thank you. A maintainer will pick it up from here.
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#1741
No description provided.