Skip to content

serve: flush each completed prompt before the next call - #671

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-serve-ready-flush
Oct 22, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-serve-ready-flush

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

서버가 새 prompt 작업을 시작하기 전에 이미 만들어진 token을 먼저 클라이언트로 보내서, 동시 요청의 중간 응답이 기다리는 시간을 줄입니다.

Part of #565.

What and why

With several requests in flight, the serve worker started the next prompt before it sent the tokens that were already ready. A request that had finished its prompt waited behind every prefill that was still queued. The worker now sends ready tokens after each completed prompt start, each completed prompt plan and each decode round, before it seals a cache or runs more prompt work.

pump_ready reuses pump_at, so completion, cancellation and error handling stay in one place. take_need gives the turn-based worker the same cached-need consumption. No model, kernel, device allocation, rank constant or public API changes. The worker is shared by every model seat, and no model code changes.

On one DGX Spark with four concurrent 4096-token requests, the median request TTFT fell from 43.925 s to 20.399 s (-53.56%, one main/head pair). The responses now arrive one after another as each prefill finishes, where on main three of them arrived together after the last prefill. Greedy output is identical on all six request pairs.

Release notes: Changed: the server sends ready tokens before it starts another prompt, which lowers the TTFT of the middle requests in a concurrent batch.

Code shape

  • No second copy. Completion and error handling for a ready token has one owner, pump_at. The inline branches this replaces were moved there. The turn worker and the slot worker share take_need.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. The inline completion and error branches in the worker are removed.
  • No silent failure. Completion and client errors still end through end_request, and engine errors stay fatal.
  • Comments state what is true now. No dates or measured numbers in code comments.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt --all passes. cargo clippy has not been run on this head, so the lint count is unchecked.

Duplication found or removed (path:line), or "none": none. python3 tools/dup-scan.py found no candidates in the diff.

What I ran

The PR head is two commits on main e53cabebbb9b16249c81b7c26a026da1670f7d9d. The timing below ran on that head.

GPU Evidence

On an NVIDIA GB10, inside the build container and on the host:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.2     |

just gate-serve is not run. The tests it names are mock-backed, and I ran them directly on a Linux host:

cargo test -p bloomery-serve --test serve slots:: -- --ignored --nocapture --test-threads=1
test result: ok. 37 passed; 0 failed; 0 ignored; 0 measured; 63 filtered out; finished in 8.17s
just contrib-check --tier t0
DONE tier=t0 total=107 red=0 wall=344s

TTFT at two and four concurrent requests

One GB10 loaded the server once per arm, main then head, with FP4-Local as shipped (nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300), draft off, greedy, parallel 4 and total context 16896. Each arm sent one group of two and one group of four concurrent requests, each with 4096 input ids and 128 output ids from a code corpus. Both arms ran under a passive Nsight Systems launch. Driver 595.84, CUDA 13.3.1 build image. The GPU clock cap was lifted for each timed window and restored afterwards. No CUDA process ran before the lease, and the pre-lease load average was 0.66.

Main binary SHA256 16dc844eef2a0b43a7c2b0d483b9c54e07c9f4175004e2e25e06cc4bb7c523b1, head d5f13a4b1c577dcc39d63f7612d3036acf99528f0539761df0db0cace9c535c0. Corpus SHA256 7520b471436fb307e91ee22640ad8100701d48e63e3da7de9160b705b92915d1.

Metric Main Head Change
C@4 TTFT p50 (ms) 43924.8395 20399.2530 -53.56%
C@4 TTFT p95 (ms) 43925.412 32639.445 -25.69%
C@4 group makespan tok/s 9.56431 12.57441 +31.47%
C@2 TTFT p50 (ms) 25262.9065 12258.1740 -51.48%
C@2 TTFT p95 (ms) 25262.969 16328.804 -35.37%
C@2 group makespan tok/s 4.82843 11.56040 +139.42%

C@4 TTFT p50 decreased by 53.56% in one main/head pair. Group makespan throughput changed by +139.424% at C@2 and +31.472% at C@4. These are single observations, not significance or sustained-throughput claims. Main prompt durations were 10.277 to 14.813 s versus 8.089 to 8.189 s on head, so this pair does not isolate a pure host-delivery effect.

TTFT p50 is the median of the per-request values, and p95 is nearest-rank (the maximum for groups this small). Group makespan runs from the earliest send to the last delivered token, and group tok/s counts all generated ids over that time. The other percentage changes are derived from these values.

Sorted first-delivery times after the group's first send, C@4 main [10.376, 43.926, 43.926, 43.927] s and head [8.193, 16.352, 24.447, 32.641] s. On main the last three responses arrived together after the final prefill. On the head each response arrives as its own prefill completes.

This is one main/head pair, so these are single observations with no spread. Server load took 278.864 s on main and 244.795 s on head, outside request timing.

Correctness

  • All six request pairs returned the same 128 greedy ids on main and head.
  • FAIL-first, five cases. The new regression fails on main (FAIL-FIRST main rc=101) and on a variant that drains only before the admission list (FAIL-FIRST initial fix rc=101). Removing each of the three drain calls fails it too: after a completed decode (completed decode rc=101), after a new prompt (new prompt rc=101) and after a prompt's last part (last prompt part rc=101). Restored code passes.
  • The regression uses the existing mock with four resident slots. It checks that an existing decoder's token is delivered before the newcomer starts, that a completed whole prompt is delivered before the next prompt, and that a completed final quantum is delivered before another long quantum. It counts non-empty token payloads, not empty prompt heartbeats.
  • Two JSON-schema streams that both need a fill: a second regression holds B's fill after A's final fill and checks that A's text reaches the client first. It passes on the head (1 passed; 0 failed). With the new four-line pump after each fill removed, it fails at the delivery assertion (panicked at crates/serve/tests/slots/yields.rs:736), and the eleven slots::yields:: tests pass again once the line is restored.
  • cargo test -p bloomery-serve: 344 unit tests pass.
  • No arithmetic changed, so no oracle or KL measurement was added. The mock covers four resident slots, and no multi-GPU run was made.

What I ran into

This does not block the PR. Prefill of the queued prompts is still serial, so the last response of a group of four still arrives at about 33 s. Changing prompt quanta or mixed prompt and verify passes would be separate work.

Hardware

One NVIDIA DGX Spark (GB10), driver 595.84, CUDA 13.3.1 build image. The slots:: tests and just contrib-check --tier t0 ran on a Linux x86 host.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added the serve The HTTP server: crates/serve label Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: completed schema fills still hold ready text behind another request's fill.

Must fix

1. Drain a completed schema fill before the next fill (kind A)

crates/serve/src/worker.rs:778 Two resident JSON-schema streams with fixed runs between decisions can both need Fill. A's final fill makes tokens ready (crates/serve/src/genloop.rs:2415), but this loop runs B's fill before pumping A. A's text waits through B's fill call; the drain after step() arrives too late. This is the same defect on the schema sibling path.

Fixing this boundary now lets the regression cover both prefill producers. Insert this after tick_of(...) and before needs.push(Need::Fill):

let Some(need) = self.pump_at(k) else {
    continue;
};
self.active[k].need = Some(need);

This caches the next call for the next round and handles a removed request without misaligning needs. Extend the regression with two schema streams: hold B's fill after A's final fill, and assert that A's text arrives before releasing B.

Non-blocking

⚠ Complete the verification evidence: crates/serve/src/worker.rs:515. Supply the timing commands and output, the source commit used for the timed candidate, and full just gate-serve output. The PR supplies the base commit and binary hashes, but its posted integration run selects only slots::. Identify a retained tools/ probe or stats/record for this delay, or explain its omission, so the result is reproducible and a recurrence diagnosable.

Checked

Duplicates: 3 new items checked; no duplicate owner. Dryer reported 0 pairs.
Complexity: crapper flagged no changed functions; the new production helpers consume cached needs and scan active requests.
Silent failure: the optional-need paths end completion and pump errors through end_request; engine-call errors remain fatal.
Tests: the new regression checks delivery before prompt boundaries. The PR reports FAIL-first rc=101 and failure when each drain at worker.rs:504, :515 and :750 is removed. It does not exercise two schema fills.
Gates: none removed or relaxed; the new regression is hw_-prefixed and ignored.
Escape catalog: no C1–C4 pattern matched.

Notes

Static validation only; tests were not executed here.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4
juliankang4 force-pushed the dgx-spark-serve-ready-flush branch from 926dcae to bf5a0fd Compare October 22, 2026 20:42

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: No behavior or quality defect survived review.

Non-blocking

⚠ Make the latency probe reproducible: worker.rs:504. The GB10 timing table omits the benchmark commands and their output, and identifies the measured head by binary hash rather than source SHA. Identify the probe or diagnostic record and attach the server/client commands, output and both measured source SHAs, as required by CONTRIBUTING.md:71–74.

Checked

Duplicates: 2 new worker helpers reuse pump_at; dryer reported 0 pairs.
Complexity: crapper flagged no changed function.
Silent failure: pump_at returns None after request removal and completion/error handling through end_request.
Tests: the new assertions check token delivery before blocked prompt work and schema delivery before another slot's fill completes. The PR reports failures when each drain at worker.rs:504, 515 or 750, or the post-fill pump at line 792, is removed; these runs were not repeated during review.
Gates: 2 new ignored hw_ tests; no pins moved or cases removed.
State: cached needs are consumed once; traversal retries the current index after request removal; ended resident slots are queued for sealing.
Escape catalog: none of C1–C4 matched.

Notes

Tests were not run during this review. No gate-recipe run is attached, so GPU evidence is false.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 21526e7 into midagedev:main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant