[GH-ISSUE #4037] [Engine] Chat and Messages silently coerce boolean and fractional token limits #1742

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/4037

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

/v1/chat/completions accepts true and 2.5 in either max_tokens or max_completion_tokens; my requests produced 1 and 2 completion tokens respectively. /v1/messages does the same for max_tokens. Chat max_tokens: false also succeeds and allows the 81-token answer to finish.

/v1/responses rejects the tested max_output_tokens: true and 2.5 requests with HTTP 400 and "max_output_tokens must be a positive whole number".

Expected: reject boolean and fractional token limits with HTTP 400 instead of silently converting them to a different generation budget. Preserve the documented integer -1 and 0 sentinel values.

Chat and Messages convert their selected token limit with int(...) at serve/server.py:7147 and serve/server.py:7395. This converts True to 1 and 2.5 to 2. With no other cap field supplied, False falls through the or expression to 0; Service.prepare treats that as the remaining context allowance (serve/server.py:4889-4898).

Smallest steps or command that reproduce it

The same build and config as in #4035 (commit 7dd5cf18). Server:

cd /content/Strata
python3 serve/server.py --engine strata --config /content/area3_config.json --host 127.0.0.1 --port 18091

Client:

import json
import urllib.error
import urllib.request

base = "http://127.0.0.1:18091"
prompt = "Count from 1 to 30, separated by single spaces, and nothing else."


def post(path, body):
    req = urllib.request.Request(
        base + path,
        data=json.dumps(body).encode(),
        headers={"Content-Type": "application/json"}
    )
    try:
        with urllib.request.urlopen(req, timeout=300) as response:
            return response.status, json.load(response)
    except urllib.error.HTTPError as e:
        return e.code, json.loads(e.read() or b"{}")


def chat(field, value):
    body = {"model": "strata", "messages": [{"role": "user", "content": prompt}],
            "temperature": 0, "reasoning_effort": "none", field: value}
    status, r = post("/v1/chat/completions", body)
    if status != 200:
        return {"status": status, "error": r.get("error", r)}
    c = r["choices"][0]
    return {"status": status, "finish_reason": c["finish_reason"],
            "completion_tokens": r["usage"]["completion_tokens"], "content": c["message"]["content"]}


def messages(value):
    body = {"model": "strata", "messages": [{"role": "user", "content": prompt}],
            "temperature": 0, "thinking": {"type": "disabled"}, "max_tokens": value}
    status, r = post("/v1/messages", body)
    if status != 200:
        return {"status": status, "error": r.get("error", r)}
    return {"status": status, "stop_reason": r["stop_reason"], "output_tokens": r["usage"]["output_tokens"],
            "content": "".join(b.get("text", "") for b in r["content"] if b.get("type") == "text")}


def responses(value):
    body = {"model": "strata", "input": prompt, "temperature": 0, "reasoning": {"effort": "none"},
            "max_output_tokens": value}
    status, r = post("/v1/responses", body)
    if status != 200:
        return {"status": status, "error": r.get("error", r)}
    return {"status": status, "response_status": r.get("status"), "incomplete": r.get("incomplete_details"),
            "output_tokens": (r.get("usage") or {}).get("output_tokens")}


cases = [
    ("chat max_tokens", lambda v: chat("max_tokens", v), [2, 1, True, False, 2.5]),
    ("chat max_completion_tokens", lambda v: chat("max_completion_tokens", v), [2, True, 2.5]),
    ("messages max_tokens", messages, [2, True, 2.5]),
    ("responses max_output_tokens", responses, [2, True, 2.5]),
]
for name, fn, values in cases:
    for v in values:
        print(json.dumps({"case": name, "value": v, **fn(v)}))

These cases are a subset of a larger client I ran; the log lines below are excerpts from that run, unchanged.

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 a scripted engine (no GPU), on Chat (max_tokens and max_completion_tokens) and Messages (max_tokens), streaming and non-streaming: true returns HTTP 200 with a budget of 1, 2.5 returns 200 with a budget of 2, and false returns 200 with the remaining context as the budget; integer 0 and -1 keep their documented meaning. Responses rejects all three with HTTP 400. The conversions are at server.py around lines 8596 and 8865. 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 · 4096 context · INT8 KV · the config in #4035

Logs

Excerpts from my run, 2026-10-25:

{"case": "chat max_tokens", "value": 2, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "}
{"case": "chat max_tokens", "value": 1, "status": 200, "finish_reason": "length", "completion_tokens": 1, "content": "1"}
{"case": "chat max_tokens", "value": true, "status": 200, "finish_reason": "length", "completion_tokens": 1, "content": "1"}
{"case": "chat max_tokens", "value": false, "status": 200, "finish_reason": "stop", "completion_tokens": 81, "content": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30"}
{"case": "chat max_tokens", "value": 2.5, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "}
{"case": "chat max_completion_tokens", "value": 2, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "}
{"case": "chat max_completion_tokens", "value": true, "status": 200, "finish_reason": "length", "completion_tokens": 1, "content": "1"}
{"case": "chat max_completion_tokens", "value": 2.5, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "}
{"case": "messages max_tokens", "value": 2, "status": 200, "stop_reason": "max_tokens", "output_tokens": 2, "content": "1 "}
{"case": "messages max_tokens", "value": true, "status": 200, "stop_reason": "max_tokens", "output_tokens": 1, "content": "1"}
{"case": "messages max_tokens", "value": 2.5, "status": 200, "stop_reason": "max_tokens", "output_tokens": 2, "content": "1 "}
{"case": "responses max_output_tokens", "value": 2, "status": 200, "response_status": "incomplete", "incomplete": {"reason": "max_output_tokens"}, "output_tokens": 2}
{"case": "responses max_output_tokens", "value": true, "status": 400, "error": {"message": "max_output_tokens must be a positive whole number", "type": "invalid_request_error", "param": "max_output_tokens", "code": null}}
{"case": "responses max_output_tokens", "value": 2.5, "status": 400, "error": {"message": "max_output_tokens must be a positive whole number", "type": "invalid_request_error", "param": "max_output_tokens", "code": null}}

Not checked in this run: streaming requests, numeric-string caps, false in chat max_completion_tokens, Messages max_tokens, or Responses max_output_tokens, or requests supplying both chat cap fields.

Originally created by @Jackmeson1 on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4037 ### 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 `/v1/chat/completions` accepts `true` and `2.5` in either `max_tokens` or `max_completion_tokens`; my requests produced 1 and 2 completion tokens respectively. `/v1/messages` does the same for `max_tokens`. Chat `max_tokens: false` also succeeds and allows the 81-token answer to finish. `/v1/responses` rejects the tested `max_output_tokens: true` and `2.5` requests with HTTP 400 and `"max_output_tokens must be a positive whole number"`. Expected: reject boolean and fractional token limits with HTTP 400 instead of silently converting them to a different generation budget. Preserve the documented integer `-1` and `0` sentinel values. Chat and Messages convert their selected token limit with `int(...)` at `serve/server.py:7147` and `serve/server.py:7395`. This converts `True` to 1 and `2.5` to 2. With no other cap field supplied, `False` falls through the `or` expression to 0; `Service.prepare` treats that as the remaining context allowance (`serve/server.py:4889-4898`). ### Smallest steps or command that reproduce it The same build and config as in #4035 (commit `7dd5cf18`). Server: ```bash cd /content/Strata python3 serve/server.py --engine strata --config /content/area3_config.json --host 127.0.0.1 --port 18091 ``` Client: ```python import json import urllib.error import urllib.request base = "http://127.0.0.1:18091" prompt = "Count from 1 to 30, separated by single spaces, and nothing else." def post(path, body): req = urllib.request.Request( base + path, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"} ) try: with urllib.request.urlopen(req, timeout=300) as response: return response.status, json.load(response) except urllib.error.HTTPError as e: return e.code, json.loads(e.read() or b"{}") def chat(field, value): body = {"model": "strata", "messages": [{"role": "user", "content": prompt}], "temperature": 0, "reasoning_effort": "none", field: value} status, r = post("/v1/chat/completions", body) if status != 200: return {"status": status, "error": r.get("error", r)} c = r["choices"][0] return {"status": status, "finish_reason": c["finish_reason"], "completion_tokens": r["usage"]["completion_tokens"], "content": c["message"]["content"]} def messages(value): body = {"model": "strata", "messages": [{"role": "user", "content": prompt}], "temperature": 0, "thinking": {"type": "disabled"}, "max_tokens": value} status, r = post("/v1/messages", body) if status != 200: return {"status": status, "error": r.get("error", r)} return {"status": status, "stop_reason": r["stop_reason"], "output_tokens": r["usage"]["output_tokens"], "content": "".join(b.get("text", "") for b in r["content"] if b.get("type") == "text")} def responses(value): body = {"model": "strata", "input": prompt, "temperature": 0, "reasoning": {"effort": "none"}, "max_output_tokens": value} status, r = post("/v1/responses", body) if status != 200: return {"status": status, "error": r.get("error", r)} return {"status": status, "response_status": r.get("status"), "incomplete": r.get("incomplete_details"), "output_tokens": (r.get("usage") or {}).get("output_tokens")} cases = [ ("chat max_tokens", lambda v: chat("max_tokens", v), [2, 1, True, False, 2.5]), ("chat max_completion_tokens", lambda v: chat("max_completion_tokens", v), [2, True, 2.5]), ("messages max_tokens", messages, [2, True, 2.5]), ("responses max_output_tokens", responses, [2, True, 2.5]), ] for name, fn, values in cases: for v in values: print(json.dumps({"case": name, "value": v, **fn(v)})) ``` These cases are a subset of a larger client I ran; the log lines below are excerpts from that run, unchanged. ### 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 a scripted engine (no GPU), on Chat (`max_tokens` and `max_completion_tokens`) and Messages (`max_tokens`), streaming and non-streaming: `true` returns HTTP 200 with a budget of 1, `2.5` returns 200 with a budget of 2, and `false` returns 200 with the remaining context as the budget; integer `0` and `-1` keep their documented meaning. Responses rejects all three with HTTP 400. The conversions are at server.py around lines 8596 and 8865. 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 · 4096 context · INT8 KV · the config in #4035 ### Logs Excerpts from my run, 2026-10-25: ```text {"case": "chat max_tokens", "value": 2, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "} {"case": "chat max_tokens", "value": 1, "status": 200, "finish_reason": "length", "completion_tokens": 1, "content": "1"} {"case": "chat max_tokens", "value": true, "status": 200, "finish_reason": "length", "completion_tokens": 1, "content": "1"} {"case": "chat max_tokens", "value": false, "status": 200, "finish_reason": "stop", "completion_tokens": 81, "content": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30"} {"case": "chat max_tokens", "value": 2.5, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "} {"case": "chat max_completion_tokens", "value": 2, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "} {"case": "chat max_completion_tokens", "value": true, "status": 200, "finish_reason": "length", "completion_tokens": 1, "content": "1"} {"case": "chat max_completion_tokens", "value": 2.5, "status": 200, "finish_reason": "length", "completion_tokens": 2, "content": "1 "} {"case": "messages max_tokens", "value": 2, "status": 200, "stop_reason": "max_tokens", "output_tokens": 2, "content": "1 "} {"case": "messages max_tokens", "value": true, "status": 200, "stop_reason": "max_tokens", "output_tokens": 1, "content": "1"} {"case": "messages max_tokens", "value": 2.5, "status": 200, "stop_reason": "max_tokens", "output_tokens": 2, "content": "1 "} {"case": "responses max_output_tokens", "value": 2, "status": 200, "response_status": "incomplete", "incomplete": {"reason": "max_output_tokens"}, "output_tokens": 2} {"case": "responses max_output_tokens", "value": true, "status": 400, "error": {"message": "max_output_tokens must be a positive whole number", "type": "invalid_request_error", "param": "max_output_tokens", "code": null}} {"case": "responses max_output_tokens", "value": 2.5, "status": 400, "error": {"message": "max_output_tokens must be a positive whole number", "type": "invalid_request_error", "param": "max_output_tokens", "code": null}} ``` Not checked in this run: streaming requests, numeric-string caps, `false` in chat `max_completion_tokens`, Messages `max_tokens`, or Responses `max_output_tokens`, or requests supplying both chat cap fields.
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:6659876496 --> @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:6660611855 --> @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:6660644553 --> @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:6660648927 --> @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#1742
No description provided.