Skip to content

serve: hold a request's next call through one owner - #689

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:fix-serve-flush-leftovers
Oct 22, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:fix-serve-flush-leftovers

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

serve worker에서 요청이 다음 engine call을 들고 있게 하는 단계를 helper 하나로 모으고, 이전 PR이 넣은 두 hw 시험에 각자 확인하는 내용의 doc 주석을 답니다. 동작은 바뀌지 않습니다.

Part of #565.

What and why

This is a cleanup that follows #671 (merged). Behavior does not change, and no checklist line of #565 closes.

#671 made a request's tokens reach its client before the engine runs another request's call. Two things it left behind are fixed here.

  • Two hw tests that serve: flush each completed prompt before the next call #671 added had no doc comment saying what they check. crates/serve/tests/slots/yields.rs:292 now says what hw_a_decode_answer_reaches_the_client_before_a_new_prompt_starts checks, and :682 does the same for hw_a_schema_fill_reaches_the_client_before_the_next_fill_finishes.
  • The step "pump the request, then keep its next engine call on it" was written out three times in crates/serve/src/worker.rs: in turn, in pump_ready, and after a fill in step. It is now hold_need (worker.rs:1182), called from step (:792), turn (:1065) and pump_ready (:1173). take_need (:1193) now holds the pump itself, so the pump has one site, where it had four before. Because take_need returns the call a request already holds before it pumps, a pump cannot run on top of a held call. The count of copies of .need = Some(need) goes from three to one.

Active::need (worker.rs:310) said the field is only used under turns, which stopped being true with #671. The doc comment now says what the field holds today.

Pumps, engine launches, copies and syncs stay the same in number. The only new work is moving one Option<Need> out of a request and back in for requests that already hold a call.

Release notes: Under the hood: the serve worker keeps a request's next engine call through one helper, and the two yield gate tests say what they check.

Code shape

  • No second copy. hold_need is the one place that keeps a pumped call on its request, and take_need is the one place that pumps. The three hand written copies in turn, pump_ready and the fill path are gone.
  • Model code holds only architecture facts. The change is in the common serve worker and its tests.
  • Dead code is gone. pump_at and the one line take_need it fed became one function.
  • No silent failure. A pump that ends a request is booked as before, and hold_need returns false for it.
  • Comments state what is true now. The Active::need comment and the new doc comments describe the current code.
  • No relaxed gate. No band, tolerance or lint level moved, and no test was removed.
  • cargo fmt is clean on the two changed files. cargo clippy has not been run on this head.

Duplication found or removed (path:line): the three copies named above, now crates/serve/src/worker.rs:1182.

What I ran

The head is ea1a4094788f068b263be3eb84c768c8a5efadc8, two commits on main 31b5be41f3d58ff47fd43f0c8bfd4695f087395a.

BLOOMERY_BOX_LOCAL=1 just gate-serve
test result: ok. 101 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.25s
== rc 0

The command also runs the bloomery-serve library tests and the other serve test targets. The library tests had 344 passing.

Each call of hold_need was removed in turn, and so were the pump_ready calls in the run loop (after a step, after a start and after a prompt finishes). Every one of these six mutations is caught by the test that guards that call. This ran on an earlier head of this branch that differs from the final one only in a doc comment on hold_need:

FAIL-FIRST-OK fill (slots::yields::hw_a_schema_fill_reaches_the_client_before_the_next_fill_finishes) rc=101
FAIL-FIRST-OK turn (slots::hw_live_requests_take_turns_and_a_prompt_waits_for_the_turn_boundary) rc=101
FAIL-FIRST-OK ready (slots::yields::hw_a_decode_answer_reaches_the_client_before_a_new_prompt_starts) rc=101
FAIL-FIRST-OK after-step (slots::yields::hw_a_decode_answer_reaches_the_client_before_a_new_prompt_starts) rc=101
FAIL-FIRST-OK after-start (slots::yields::hw_a_decode_answer_reaches_the_client_before_a_new_prompt_starts) rc=101
FAIL-FIRST-OK prompt-done (slots::yields::hw_a_decode_answer_reaches_the_client_before_a_new_prompt_starts) rc=101

The tree was restored after each mutation. The tests use a mock engine, so no model file is needed.

I did not run an A/B. The change adds no launch, copy or sync, and the pump count is unchanged.

GPU Evidence

crates/serve has no CUDA code. The gate ran on a GB10 machine; these lines come from nvidia-smi there:

NVIDIA GB10, 595.84
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |

What I ran into

This does not block the PR.

  • cargo clippy and just contrib-check have not been run on this head.
  • The six mutations above ran on the earlier head described in "What I ran", not on the final head.

Hardware

A GB10 (aarch64 Linux, 20 CPUs), driver 595.84, CUDA 13.3, for the gate and the six mutations.

AI help

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

The prompt-boundary and schema-fill gates had no doc comment of their own.
turn, pump_ready and a fill's flush each pumped a request and kept its call
by hand. hold_need keeps the call take_need gives, and take_need, holding
pump_at's body, is the one place a request is pumped, so a held call is
never pumped over.
@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: CLEAN: The refactor preserves token delivery, request termination, and engine-call scheduling.

Checked

Duplicates: 1 new item checked (hold_need); no existing duplicate. Dryer reported 0 candidate pairs.
Complexity: take_need 1 → 7 incorporates the unchanged pump body; step 25 → 26 replaces the existing fill-result branch. Neither adds a scheduling decision.
Silent failure: 2 terminal paths followed. Completed and failed pumps still remove and book the request; errors reach the client through Msg::Done.
Tests: assertions unchanged. The property-name delivery assertion guards the post-fill hold at crates/serve/src/worker.rs:792; the delivered-token assertion guards the ready hold at crates/serve/src/worker.rs:1173. The PR reports these and four other mutations failed on an earlier head that differed only in a doc comment.
Gates: no pins, thresholds, test cases, or assertions moved.
Performance: the serve scheduler adds one Option take/store per visit to a request holding a call. Pump, allocation, launch, copy, and sync counts remain unchanged.
Escape catalog: no patterns matched.

Notes

Verification here was static. Gates and mutations were not rerun; the PR reports a passing gate-serve run.

🔨 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 8e59fad 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