Skip to content

serve: the spawned mock's gates wait until it serves before their first request - #990

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-gate-serve-props-wait
Oct 29, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-gate-serve-props-wait

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

serve 시험이 가끔 503 "Loading model"로 실패하던 경쟁을 고쳐, 시험이 서버가 요청을 받기 시작한 뒤에 첫 요청을 보내게 했습니다.

What and why

bloomery-serve prints its startup line right after it binds the listener. It only starts answering after server.run() takes the listener over, and until then every route replies 503 loading. The spawn_mock helper in crates/serve/tests/serve.rs returned the address as soon as it saw the startup line, so the first request of hw_props_engine_object, a_key_never_reaches_what_the_process_prints_or_serves and hw_engine_error_is_500_then_503_then_exit sometimes reached the listener too early and got the 503.

spawn_mock now calls a new wait_served(addr) before it returns. It polls /health until the server serves, accepts only a 503 loading answer in between, and stops with a named assert on any other answer or on a timeout. /health needs no API key, so the --api-key test works too. The change touches only the test harness.

Release notes: internal: the serve tests no longer race the server's startup, which made three tests fail intermittently.

Code shape

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none.

What I ran

The same loop ran 300 times before and after the fix. Each pass runs the three tests that use spawn_mock:

cargo test -q -p bloomery-serve --test serve -- --include-ignored --exact \
  hw_props_engine_object a_key_never_reaches_what_the_process_prints_or_serves hw_engine_error_is_500_then_503_then_exit

Before the fix, 11 of the 300 passes failed with the 503 body, 5 in hw_props_engine_object and 6 in a_key_never_reaches_what_the_process_prints_or_serves:

11 assertion `left == right` failed: {"status":"loading","phase":"load","bytes_done":0,"bytes_total":0,"error":{"code":503,"message":"Loading model","type":"unavailable_error"}}

After the fix, none failed:

300 test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured;

The full serve test file passes after the fix:

cargo test -q -p bloomery-serve --test serve -- --include-ignored
test result: ok. 111 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 7.25s

rustfmt --edition 2024 --check crates/serve/tests/serve.rs passes with no output.

AI help

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

@github-actions github-actions Bot added the serve The HTTP server: crates/serve label Oct 29, 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 readiness wait closes the startup race for all three callers without advancing the mock engine.

Non-blocking

⚠ Preserve recurrence and diagnosis coverage: crates/serve/tests/serve.rs:1266. Deleting the wait reopens the startup window; none of its three callers forces that window to occur.
Add a controlled delayed-handoff regression check and retain the stress reproduction as a tools probe, or explain why these fix layers are unnecessary. This makes a future regression reproducible.

Checked

Duplicates: 1 new item checked; no existing readiness-wait owner found. Dryer reported 0 pairs.
Complexity: crapper flagged no functions; the new loop has one readiness decision and explicit failure assertions.
Silent failure: 0 new suppression/default sites. Invalid JSON, unexpected replies and sustained loading fail explicitly.
Tests: no test definitions changed. Mutation analysis: deleting the wait restores intermittent failures; the PR reports before/after stress runs.
Gates: no existing threshold, assertion or case removed or relaxed; no pins moved.
Adversarial: health bypasses authentication and leaves the injected-failure counter unchanged; a failed wait drops the child through Reaped.
Performance: test harness only; no inference hot path changed.
Escape catalog: no patterns matched.

Notes

Static review only; the reported test runs were not rerun.

🔨 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 178ba67 into midagedev:main Oct 29, 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