mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2980] serve: /v1/chat/completions ignores llama.cpp's n_predict, so a client's n_predict: 0 follow-up call regenerates the whole answer with no limit (~20k tokens, ~4–5 min of GPU time per reply) #1197
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#1197
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 @DanGTG on GitHub (Oct 17, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2980
Summary
/v1/chat/completionsignores the llama.cpp-native fieldn_predict. The answer limit is read only frommax_completion_tokens/max_tokens, and a missing or 0 value means "the rest of the context" (serve/server.py:5942onmainat477ac13c;:5819in 0.1.44.1, in_openai). Still the case onmainas of 2026-10-17.llama.cpp's own web UI (and possibly other llama.cpp-compatible clients) sends a follow-up request after every reply. The request carries the conversation so far, ending with the assistant's answer, plus
n_predict: 0andstream: false. In llama.cpp,n_predict: 0means "generate nothing": the client only wants the prompt processed, e.g. to measure context or warm the cache. Strata generates with no limit instead. The model answers the whole task again from scratch, and the client discards the result.Because Strata serves one request at a time, any other client of the server waits behind this request for those minutes. The chat user can cut it short: sending a new message cancels it (seen twice; it fits the client dropping its pending call, and Strata cancelling a request whose client disconnects). But that has a second cost. The follow-up never completes as a prompt-only call, so the conversation is never cached, and the user's next message re-reads the whole conversation from scratch. Strata already reports
n_predictin/props(default_generation_settings.params.n_predict), so llama.cpp clients reasonably expect it to be honoured on requests.Environment
296b59d2, git clone). It first appeared on amainZIP snapshot from 2026-10-04 (bundled engine 0.1.39) and is still there after updating, so it isn't a regression in 0.1.44.x. The same limit line is in both versions (serve/server.py:3368in the 2026-10-04 snapshot).backend: hip, AMD Radeon AI PRO R9700 (gfx1201, 32 GB), 96 GB RAMiq3_s,coder-iq1_m,unsloth-ud-iq4_xs(Qwen3.8-Flash-Next) andswift-iq3_s(Swift-1.5). The cases below are the ones captured in logs. The code path is in the shared request layer, so it does not depend on the model.return_progress,timings_per_token,backend_samplingandreasoning_format; after each reply it sends then_predict: 0call. Strata's own web app never sendsn_predictand doesn't trigger this.127.0.0.1:8080, llama-server's default port and also Strata's. When Strata later served that address,--openbrought up the cached llama-ui shell instead of Strata's page (its icons and bundle 404 against Strata), and llama-ui worked against Strata's llama.cpp-compatible API without any visible sign. Anyone who has used llama-server on 8080 can hit this without choosing that client.Minimal repro
Same prompt, non-streaming, against an idle server:
"n_predict": 8stop"max_tokens": 8length"max_tokens": 0stopWhat it looks like in practice (captured with
"api_monitor": true)stream: true, prompt 1,081 tokens, 29,263 tokens generated.stream: false,n_predict: 0. The messages are exactly [user prompt, the previous answer as anassistantmessage]. Prompt 5,763 tokens, 0 reused. Live metrics showedmax_tokens: 518517. It finished with 21,683 tokens in 292 s: about 64k characters of reasoning plus a full second answer.An earlier session the same day showed the same shape: chat prompt 1,081 → 39,593 tokens, then the follow-up at 7,468 prompt tokens, 0 reused, 20,181 tokens in 232 s. In an earlier occurrence, on the
coder-iq1_mpack, the user sent a new message about 200 s in, and that ended the follow-up.Interrupting it (
swift-iq3_s, from the server log)stopn_predict: 0)stopstopTwo things show here:
n_predict: 0honoured, request 2 would have taken about 10 s of prompt reading, and request 3 could have reused most of its prompt.History
No version has read
n_predictfrom a request. What changed over time is the cost:01529aaa(2026-09-24, first commit): the limit comes frommax_completion_tokens/max_tokens, with a default of 1024 if neither is set. Ann_predict: 0call was ignored, but capped at 1,024 tokens.656a8356(2026-09-26, "treat unset/-1 max_tokens as remaining context, not 1024"): the default became the rest of the context, so the same call now has no limit.08f8d591(2026-09-29, "add llama.cpp-compatible discovery endpoints"):/propsstarted reportingn_predict, so llama.cpp clients treat Strata as compatible.656a8356was a sensible change for real chat requests. It just made the missingn_predicthandling expensive.Suggested fix
Honour
n_predictin_openaiwhen neithermax_completion_tokensnormax_tokensis set. Note that this can't reuse the existingint(... or 0)pattern. Formax_tokens, 0 deliberately means "the rest", so passingn_predictthrough it would keepn_predict: 0unlimited. llama.cpp's semantics are:n_predict: -1: no limitn_predict: 0: process the prompt and generate nothing. Return an empty completion (completion_tokens: 0) once the prompt has been read; the client presumably wants the prompt cached.n_predict: N > 0: same asmax_tokens: NHappy to test a fix on gfx1201.
Related: #2141 (same family:
thinking_budget_tokens, llama-server's name, is ignored, so llama.cpp clients get unbounded thinking). Together, a llama.cpp client that tries to bound a request by either length or thinking gets no bound at all.@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.