Skip to content

serve: observe drafted overlap in engine-call order - #745

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-stream-test-observation
Oct 23, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-stream-test-observation

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

두 요청이 겹쳐 진행되는지 보는 SSE 시험이 읽는 쪽 스레드의 실행 순서에 흔들리지 않도록, 엔진이 실제로 기록한 호출 순서로 판정하게 고칩니다.

Part of #565. Tracked in #699.

What and why

hw_drafted_passes_interleave_across_slots checks that two drafted requests run side by side. Besides the engine's call order, it also compared the arrival order of chunks in a log that both client reader threads append to. That order says when each reader thread got scheduled, not when the server sent a chunk. If the second reader starts late, the first stream is fully read before the second reader takes its first chunk, and the gate stops with "the streams did not overlap" even though the server interleaved the requests correctly.

The change is test-only and sits in crates/serve/tests/slots/mod.rs, plus the call sites of the other tests that read SeenChunk:

  • open_stream now owns connecting and sending the request. read_stream calls it and then reads, so the existing callers keep their behavior.
  • The gate sends both requests, waits until the second one is queued, then keeps the second reader paused until the first reader has finished. Reader lateness is now the default scenario of the gate instead of a race.
  • Overlap is judged from the engine's call record. Each slot's last engine call must come after the other slot's first one, and the slots' calls must alternate while both requests run. The arrival-order overlap check is removed.
  • SeenChunk no longer carries an arrival timestamp, since nothing may read client arrival order as server progress. It is now the slot, the stop flag and the chunk. The two readers in yields.rs and the plain-step and reasoning-close delivery tests in mod.rs use the new shape; the delivery tests read the slot.

The final-chunk, per-slot ids, draft count, accepted count and concurrent-slot metric assertions are unchanged. No production code, output bit, default or GPU path changed.

Release notes: internal: the drafted-overlap serve test no longer reports a false error when a client reader thread is scheduled late.

Code shape

  • No second copy. The request send was moved out of read_stream into open_stream, which both paths use. The existing read_chunks stays the only chunk reader.
  • Model code holds only architecture facts. No model code is touched.
  • Dead code is gone. The arrival-order overlap check and its inputs are removed.
  • No silent failure. The new engine-order assertions use expect on a missing slot record and name both slots in the message.
  • Comments state what is true now. The SeenChunk and read_stream docs describe client observation only, and the reader order is not claimed to be the server's.
  • No relaxed gate. The assertion that replaces the arrival-order check reads the engine's own record. It carries a dated PIN with the reason, and the serial mutant below shows it still catches requests that do not overlap.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. rustfmt --edition 2024 --check on the changed file and git diff --check are clean; clippy has not been run on this head.

Duplication found or removed (path:line), or "none": none. The duplicate scan reported no candidate.

What I ran

The tests use mock engines and loopback HTTP, so they need no GPU and no model. They ran on a Linux x86_64 CPU machine at head 104d57a3a6cf0381bede2ff1e895f7399510ee5d, with RUSTFLAGS='-C target-cpu=native' and locked, offline Cargo.

FAIL-first, with the arrival-order overlap check put back into the gate on this head (rc 101):

cargo test --locked --offline -p bloomery-serve --test serve slots::hw_drafted_passes_interleave_across_slots -- --ignored --exact --nocapture

The gate panicked with stream 0 ended before stream 1 began: the streams did not overlap, and the run ended with test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 106 filtered out.

With the change, cargo test --locked --offline -p bloomery-serve --test serve slots:: -- --include-ignored --nocapture --test-threads 4 ended with test result: ok. 42 passed; 0 failed. That covers the interleave gate, stream_chunks_preserve_utf8, stream_chunks_refuse_invalid_or_incomplete_frames, the two yields.rs tests, the plain-step and reasoning-close delivery tests, and hw_each_slot_gives_its_request_alone_ids.

Mutant on the real server: I changed Worker::step to advance only the first active request (while k < self.active.len() became while k < self.active.len().min(1)), so the second request starts after the first has finished. The gate then failed with rc 101 on the new assertion, slot 0 ended before slot 1 began: the passes did not overlap, with all 23 of slot 0's passes recorded before slot 1's 23. Both mutants were restored and git diff --exit-code passed; neither was committed.

Not run: clippy, t0, the full workspace test run, and any GPU gate. The change touches no production code and no CUDA path, so I took no timing or output-bit measurement.

Reproduction

cargo test --locked --offline -p bloomery-serve --test serve slots:: -- --include-ignored --nocapture --test-threads 4

What I ran into

This does not block the PR. Four delivery tests, two in mod.rs and two in yields.rs, each carry the same loop that rereads the client log every 5 ms until BOUND. They could share one helper; I left them as they are, since moving them is a test cleanup apart from this fix. It has no effect on decode, prefill or time to first token.

AI help

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

@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: The revised gate measures engine progress and retains checks against serialized requests.

Checked

Duplicates: 1 new function checked (open_stream); no duplicate owner found. Existing request helpers consume the response. dryer reported 0 candidate pairs.

Complexity: crapper flagged no changed function.

Silent failure: 3 changed record lookups followed. Missing slot records panic by name.

Tests: six changed tests checked by static mutation review:

Overlap predicate: an independent interval-and-adjacency check agreed on all 8,190 binary traces of lengths 1–12. Serialized, repeated-live-slot, missing-slot and empty traces were rejected.

Gates: the replaced arrival-order clause has a dated PIN and reason at crates/serve/tests/slots/mod.rs:875. The PR documents the old clause's false failure and a failing serialized-worker mutant.

Escape catalog: no pattern matched. No production hot path changed.

Notes

Rust tests were not rerun. The PR reports 42 passing slot tests and the serialized-worker mutation failure.

🔨 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.

1 similar comment
@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 6733301 into midagedev:main Oct 23, 2026
7 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