Repository navigation
server: deadline_s ends a reply at its deadline with every token and usage - #3438
Conversation
aac2b3f to
f500b25
Compare
f500b25 to
b14bde2
Compare
|
Thanks @jayleaton. The existing deadline tests pass, but there is one finish-reason race to fix. At
|
|
Thanks, confirmed and fixed in
— Jay Leaton |
|
@jayleaton, thank you. we applied the series to main and read it end to end: the field parses and refuses bad values before the Nothing to change from us. One note for the record: the macOS server tests were compiled and linked but not No hardware run is needed on our side - the change reaches no engine, kernel or backend, and the request-level
|
caed33c to
c7c06c7
Compare
|
Thank you @jayleaton. The finish-reason race is fixed as described: the read loop checks the mailbox's finished flag under its own mutex, so a reply the engine already ended keeps stop or length and sends no cancel, while a deadline that really fired still ends the reply with every token, usage and ids. The slow-writer and late-read tests cover both the chat and HTTP paths. No device run is needed. One thing before it lands: the zig-b job on this head fails three of the pinned serving hashes, which usually means a pinned source file changed and needs its re-pin in this PR. Please re-pin them, or tell us if you think the pins moved on main instead.
|
|
Thanks. I checked the three hashes, and I don't think any pin moved, in this PR or on main.
So I haven't re-pinned anything: re-pinning to the "found" values would make the drift check pass on drift. The head — Jay Leaton |
|
Thank you @jayleaton for tracing those three blocks. The pins are right, and re-pinning to the drifted values would break the drift check, so no change is needed there. The deadline finish-reason fix and tests are accepted. One item remains: this head conflicts with current main in zig/src/server/chat.zig. We will rebase it onto current main ourselves; nothing is needed from you.
|
c7c06c7 to
24c862e
Compare
|
Thanks @jayleaton. As promised, we rebased this onto current main ourselves, keeping your commits as they were; nothing else changed. It is in the landing queue now, and nothing is needed from you.
|
24c862e to
9b13364
Compare
|
On exact head After that resolution, Igor Lessio - AIFLOW LABS |
9b13364 to
9c91113
Compare
|
I reran the deadline checks on the exact #4276 train tip zig build test-request-deadline-host test-tool-required-host test-server-cpu -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary allExit 0. The deadline target passed 34/34, required tools passed 33/33, and server CPU passed 1,723 with 15 skipped. The host test log includes warnings for the optional grammar dylib. This covers the combined train, whose automatic PR jobs were skipped. The manually dispatched No GPU workflow has since completed successfully on the same train SHA. I also trial-merged the same train into zig build test-request-deadline-host test-tool-required-host test-h3-image-prompt test-h3-geometry test-h3-boundaries test-h3-image-server tf-h3-image-server -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary allI also merged the published deadline head Igor Lessio - AIFLOW LABS |
…usage
A request may name "deadline_s" (seconds, more than 0, at most 1000000), for
chat and legacy completions. At that time the server cancels the engine
itself, still commits the tokens the engine gives before its finished event,
and labels the reply finish_reason "deadline". The final response keeps
usage and token_ids/token_sha256. A token the engine gives after the
deadline cancel may be EOS, hit a stop string or reach max_tokens; the
reply still ends "deadline". A deadline that passes after the reply already
ended (a stop string's own cancel) is not counted. Without the field
nothing changes.
A cancel from POST /v1/requests/{id}/cancel that came first keeps the
reply "cancelled": the deadline then sends no second cancel and never
relabels it. docs/api.md lists the field.
test-request-deadline-host: through chat.run and through openai.run (chat
and completions, whole and streamed): a forced deadline ends the reply with
finish deadline, the late token, usage and ids; no field and a deadline the
reply never meets give the same reply, token sha and stream choices; 0, -1,
"300", true and 1e7 are refused before the engine. A cancel ask before the
deadline, with an engine that ends late, still ends "cancelled".
…adline passes while it drains A slow client could still be writing out tokens the engine had already finished with (stop or length) when deadline_s passed; the server then sent a cancel to the finished request and labelled the whole reply "deadline". Before marking a deadline, the read loop now checks the mailbox's finished flag under the mailbox's own mutex: an engine that ended first keeps its finish reason and gets no cancel. test-request-deadline-host: the engine ends inside submit, before the 50 ms deadline, and the first stream write takes 100 ms: the reply ends "stop" with abcde and no cancel is sent (chat.run); over HTTP, for chat and completions, whole and streamed, a reply the engine ended before the deadline and the server first reads after it keeps "stop".
9c91113 to
2e79a2c
Compare
|
Thank you @jayleaton. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
What this changes
Before: a client that wants a reply bounded in time has to time out and disconnect (or call the cancel route from a
second connection); a disconnect loses the reply's usage and token ids. After: a request may carry
deadline_s(seconds, more than 0, at most 1,000,000) on chat and legacy completions. At that time the server cancels the engine
itself, keeps every token the engine gives before its finished event, and ends the reply with
finish_reason: "deadline", usage andtoken_ids/token_sha256. A reply that ends first, or acancel that came first, keeps its own ending: the deadline is marked only while the engine
has not finished, checked under the mailbox's mutex, so a slow client still draining a finished reply keeps
stoporlength. Without the field nothing changes.(one reason code for every wait or refusal): if One reason code for every wait or refusal, and an audit of queue limits #2135 settles on names,
"deadline"can follow them.Context: RFC: compute lane, a server-run code call whose reply equals the client's own round trip #3439 (RFC, compute lane) names this as its first slice; this PR stands alone and does not depend on it.
6b493a3ef); two commits: the field (b14bde22a) and the review fix for a slow writer (79d08ea32).atc overlap --json(base6b493a3ef, 2026-11-15 14:44Z, on the tree of headaac2b3fa0, incomplete: list and time limits):conflictswith Muse Spark Open on CUDA, on two GB10s #1295 and server: split recipient-addressed replies into reasoning, answer and tool calls #1336 inzig/src/server/chat.zig; both already conflict with main in the same files. Becausethe run was incomplete, I also test-merged (
git merge-tree) this head against every open pull request updated since2026-11-01 that touches these files (88). New conflicts, none of them on main already: server: an opt-in request journal with replay and crash quarantine #3221 and dsv41: serve structured output with the lane core's grammar masks (from #1665 by @nuk3s) #3026 (and ocr: GLM-OCR reader on /v1/ocr (#2440 step 3) #2572-ocr: POST /ocr in PaddleX's contract (#2440 step 6) #2575)
on the
Preparedreturn line or theGenerationinit line inchat.zig, and logit_bias: token biases and -100 bans on each row's draw for Qwen CUDA, Qwen3.5-2B Metal and Nemotron Parse HIP #3146, Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b) #2648 and Draft: DeepSeek-V4.1 prefill on a GB10 pair, decode on Metal over the #2648 hand-off (alignment base) #3386 on the field listin
openai.zig. Each request field adds itself to those same lines, so whichever lands second has a one-line rebase.I moved this PR's test imports, build step and
docs/api.mdrow so they no longer meet lane host: --stall-seconds marks a stalled engine unavailable, --stall-exit restarts it #3165, feat(server): optional JSON lines for request start and end #3195, server: POST /v1/prompt_cache/flush drops the prompt cache's kept states #3210, server: an opt-in request journal with replay and crash quarantine #3221,server: forget one conversation's kept states (POST /v1/imprint/forget) #3226, lane host: a slow reader's stream sits out rounds at 1,024 unread tokens; one stalled 60 s is cancelled #3234 or server: "execution_witness": true binds a reply to the witness at admission and at its end, with its prompt, resolved request and tokens #2958.
Checks on this head
79d08ea32on base6b493a3ef; every check below ran on this tree.python3 tools/zig/lean_check.py, on the base and on this head: 341 and 341, 0 new(
tools/zig/lean_new.py; the 341 are inherited).python3 tools/pr_check.py --base <main> --pr 3438: 0 errors, 0 warnings.zig build test-request-deadline-host: 30 pass, 0 fail, 0 skip as Zig counts the filtered run; 10 tests are new(5 through
chat.run, 5 over HTTP throughopenai.run). The two slow-writer tests (an engine that ended before the50 ms deadline, read 100 ms late) fail on
b14bde22awith the reply labelleddeadline.zig build test-server-cpu: 1470 of 1478 pass, 8 skip (checkpoints andlibtfgrammar.soabsent), 0 fail, withumask 022. With umask 002 one test on main fails the same way without this change:
cli_config_test"serve --config: expand reads the file …" writes its file under the umask, and--configrefuses a group-writable file (0664). This PR does not touch
cli.zigorcli_config*.zig.zig build check-native-cuda-host -Dsm=121: success.zig build test-golden: 322 of 335 equal to the server goldens, 13 listed as known (main's ownKNOWN-DIFFERlist: tool streams, required tool choice and format without
libtfgrammar.so), 0 unexpected; 55 of 55 equal."deadline"label infinish, 3 tests fail; without thecancel-came-first guard, the new cancel test fails (
deadlineinstead ofcancelled); without the completion check(
ended_first = false), both slow-writer tests fail (deadlineinstead ofstop). All three fail as planted.zig fmt --check build.zig zigandgit diff --check: clean.metal_targets.zig'sserver_tests, whichzig build testruns on a Mac)cross-built with
-Dtarget=aarch64-macosfrom Linux through a local, uncommitted step: semantic analysis passes onthe base and on this head, and the emitted build links to a Mach-O arm64 executable that holds the 10 new tests. It
was not run. See "Not run".
79d08ea32:zig,zig-windows,zig-macos-dev-tools,pytest,release-paths,benchmark-clients(ubuntu and windows) and
fmtpass;host-nightly-linuxandhost-nightly-macosskip on pull requests.zig-macos-dev-toolsbuilt the tf-*tools; this change touches no API they call); Windows ran only in CI (
zig-windows). The diff adds no platform calls (the clock is theexisting
server/clock.zig).Receipt
calls the engine's existing cancel. The host tests compare main's behaviour (no field) with a deadline the reply never
meets: same reply, token sha and stream chunks, byte for byte.
chat.zig. The Responses and Ollamaroutes build their own chat body from listed fields and do not pass
deadline_son.deadline_s, default absent (no deadline), a number in (0, 1e6];anything else is refused with HTTP 400 before the engine. No profile row.
6b493a3ef, head79d08ea32, Zig 0.17.0, aarch64 Linux (GB10 host, CPU only, no GPU used), no checkpoint (fakeengines in the tests).
chat.runandopenai.run, chat andcompletions, whole and streamed: ran on aarch64 Linux; macOS compiled and linked, not run; Windows through CI's
zig-windows.it never meets, is byte-identical to main (test above). No token is changed or added.
Checklist