Skip to content

fix(distributed): reject model-owned paged families from the prefill handoff - #716

Merged
inureyes merged 3 commits into
mainfrom
fix/708-model-owned-handoff-rejection
Jul 9, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/708-model-owned-handoff-rejection

Conversation

@inureyes

@inureyes inureyes commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Summary

A disaggregated request for a model-owned paged family (gemma3 / gemma4 / llama4 / qwen3_5 / qwen3_next) crashed the prefill node's serving-role loop and took the whole node down: one request left every subsequent request returning 503 peer-down. This rejects those families with a clean per-request error and keeps the node serving.

Root cause

CachePool::extract_paged_blocks guarded against model-owned sequences with !caches.iter().all(is_paged_backed()), but a model-owned family's make_caches() returns an EMPTY vec, so .all() on the empty iterator is vacuously true and the guard fell through. These families are routed through the paged backend for shadow block-table accounting only, so sync_paged_state_with_lengths populates the block ids while the pool tensors are never written. The fall-through then read those unwritten tensors and PagedBlockPool::read_block_contents failed with "layer 0 has no pool tensors to read from". The error propagated out of prefill_text_request_for_handoff and the serving-role loop treated it as fatal and exited, so the router health monitor marked the peer down.

What changed

  • src/lib/mlxcel-core/src/cache.rs: extract_paged_blocks now detects the empty-caches case explicitly. A populated shadow block table with no pool-backed caches returns a clean error instead of issuing the doomed pool read; an empty shadow table takes the empty fast path. Added the extract_paged_blocks_rejects_model_owned_shadow_sequence unit test (with a model-owned empty-caches stub) pinning this.
  • src/server/batch/scheduler.rs: new BatchScheduler::handoff_supported() (natural sequence-state backend is DenseKvCache). prefill_text_request_for_handoff rejects unsupported models up front, before any allocation or prefill work.
  • src/distributed/disaggregated/coordinator.rs: run_prefill_role_networked checks handoff_supported once at startup (single warning, which keeps the #708 reference for operators) and rejects each request with a clean per-request error frame. It also no longer exits on a per-request prefill/extract failure: it reports an error frame for that request and keeps serving, reserving loop exit for transport-level conditions.
  • tests/disaggregated_router_e2e.rs: retargeted disaggregated_router_completions_match_single_node_byte_fallback from Gemma (model-owned, unrunnable by construction) to MiniCPM-2B (byte-fallback AND pool-backed), mirroring the chat-usage test; updated the GEMMA_DIR doc comment to note its new use. Added disaggregated_router_rejects_model_owned_family_and_keeps_serving.

A follow-up hardening pass addressed three review findings in the same serving loop: a malformed-but-well-framed request payload (a decode failure with no reply_to to answer) now drops just that request via continue instead of exiting the loop, since it is the same availability symptom as the original bug through a different trigger; every error/first-token ResultFrame encode failure at each in-loop send site now degrades to a per-request drop (logged and skipped) instead of propagating out and exiting the loop; and the issue number was moved out of the client-facing rejection message into the startup warning only, so operators still get the #708 pointer in logs without leaking an internal issue reference to API clients.

What the client sees

A completions/chat request for a model-owned family is rejected at the prefill node before any prefill work. The prefill node returns an error frame; the router renders it as an HTTP 500 JSON error ({"error":{"message":"prefill node error: the disaggregated handoff does not support this model's model-owned paged sequence-state backend; only pool-backed dense Fp16 families (qwen3 / llama3) can be handed off"}}). The node stays alive, so a second identical request receives the same clean 500, not a 503 peer-down.

Test plan

All run on Apple M1 Ultra with --features metal,accelerate.

  • cargo check --lib --tests (workspace) and cargo clippy --lib --tests --features metal,accelerate -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • cargo test --release --features metal,accelerate -p mlxcel-core cache::tests -- --test-threads=1: 60 passed, including extract_paged_blocks_rejects_model_owned_shadow_sequence.
  • cargo test --release --features metal,accelerate --lib -- distributed::disaggregated: 177 passed (coordinator / serving-protocol / stream-bridge).
  • E2E disaggregated_router_rejects_model_owned_family_and_keeps_serving on gemma-3-1b-it-4bit, re-run on the final hardened code (after the malformed-frame and encode-failure fixes): PASS, two consecutive requests, two consecutive clean HTTP 500s with the model-owned rejection message, no 503 peer-down.
  • E2E disaggregated_router_completions_match_single_node_byte_fallback on minicpm-2b-4bit: PASS, router body byte-identical to single-node (" café, café, café.\n...", completion_tokens 16, finish_reason length).
  • E2E disaggregated_router_chat_usage_matches_single_node_byte_fallback on minicpm-2b-4bit (regression check on serving-loop changes): PASS.

Closes #708

…handoff

A disaggregated request for a model-owned paged family (gemma3 / gemma4 / llama4 / qwen3_5 / qwen3_next) crashed the prefill node's serving-role loop and took the whole node down: one request left every subsequent request returning 503 peer-down.

Root cause: `CachePool::extract_paged_blocks` guarded against model-owned sequences with `!caches.iter().all(is_paged_backed)`, but a model-owned family's `make_caches()` returns an EMPTY vec, so `.all()` on the empty iterator is vacuously true and the guard fell through. These families are routed through the paged backend for shadow block-table accounting only, so `sync_paged_state_with_lengths` populates the block ids while the pool tensors are never written; the fall-through then read those unwritten tensors and `PagedBlockPool::read_block_contents` failed with "layer 0 has no pool tensors to read from". The error propagated out of `prefill_text_request_for_handoff` and the serving-role loop treated it as fatal and exited.

extract_paged_blocks now detects the empty-caches case explicitly: a populated shadow block table with no pool-backed caches returns a clean error instead of issuing the doomed pool read, and an empty shadow table takes the empty fast path. BatchScheduler gains a `handoff_supported()` node-level check (natural backend is `DenseKvCache`); `prefill_text_request_for_handoff` rejects unsupported models up front before any allocation or prefill work. The prefill serving-role loop checks `handoff_supported` once at startup (logging a single warning) and rejects each request with a clean per-request error frame, and it no longer exits on a per-request prefill/extract failure: it reports an error frame for that request and keeps serving, reserving loop exit for transport-level conditions. The router renders the error frame as a 500 chat/completions failure.

Retargets `disaggregated_router_completions_match_single_node_byte_fallback` from the model-owned Gemma checkpoint (unrunnable by construction) to MiniCPM-2B (llama-format, byte-fallback AND pool-backed), mirroring the chat-usage test. Adds `disaggregated_router_rejects_model_owned_family_and_keeps_serving`, which sends two model-owned requests through the 3-node stack and asserts a clean per-request 500 (not 503 peer-down) on both, proving the prefill node keeps serving. Adds `extract_paged_blocks_rejects_model_owned_shadow_sequence` pinning the guard against a model-owned sequence with a populated shadow block table.

Validation on Apple M1 Ultra: cache/coordinator/serving unit tests, the retargeted completions E2E (byte-identical to single-node on minicpm-2b-4bit), the new rejection E2E (gemma-3-1b-it-4bit), and the pre-existing chat-usage E2E all pass; clippy and fmt clean.

Refs #708
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:high High priority area:architecture Architecture and code structure changes area:core mlxcel-core: MLX FFI, primitives, KV cache, layers status:review Under review labels Jul 9, 2026
inureyes added 2 commits July 10, 2026 00:38
…loop

Review follow-ups on the #708 fix: a malformed-but-well-framed request payload now drops the request instead of exiting the serving loop (the same availability symptom via a different trigger), every error/first-token frame encode failure inside the loop degrades to a per-request drop instead of a loop exit, and the issue-number reference moved out of the client-facing rejection message (the startup warning keeps it for operators).
docs/distributed.md described disaggregated inference without stating which model families the paged prefill/decode handoff supports, unlike CONTINUOUS_BATCHING.md's existing scope note. Add a short paragraph noting the pool-backed-Fp16-only scope (qwen3, llama3) and that model-owned paged families (gemma3, gemma4, llama4, qwen3_5, qwen3_next) are now rejected at the prefill node with a clean per-request error instead of crashing the serving loop, linking to the fuller scope-and-limitations list.

Refs #708
@inureyes inureyes added status:done Completed and removed status:review Under review labels Jul 9, 2026
@inureyes
inureyes merged commit d189c67 into main Jul 9, 2026
4 checks passed
@inureyes
inureyes deleted the fix/708-model-owned-handoff-rejection branch July 9, 2026 15:50
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…handoff (lablup#716)

## Summary

A disaggregated request for a model-owned paged family (gemma3 / gemma4 / llama4 / qwen3_5 / qwen3_next) crashed the prefill node's serving-role loop and took the whole node down: one request left every subsequent request returning 503 peer-down. This rejects those families with a clean per-request error and keeps the node serving.

## Root cause

`CachePool::extract_paged_blocks` guarded against model-owned sequences with `!caches.iter().all(is_paged_backed())`, but a model-owned family's `make_caches()` returns an EMPTY vec, so `.all()` on the empty iterator is vacuously true and the guard fell through. These families are routed through the paged backend for shadow block-table accounting only, so `sync_paged_state_with_lengths` populates the block ids while the pool tensors are never written. The fall-through then read those unwritten tensors and `PagedBlockPool::read_block_contents` failed with "layer 0 has no pool tensors to read from". The error propagated out of `prefill_text_request_for_handoff` and the serving-role loop treated it as fatal and exited, so the router health monitor marked the peer down.

## What changed

- `src/lib/mlxcel-core/src/cache.rs`: `extract_paged_blocks` now detects the empty-caches case explicitly. A populated shadow block table with no pool-backed caches returns a clean error instead of issuing the doomed pool read; an empty shadow table takes the empty fast path. Added the `extract_paged_blocks_rejects_model_owned_shadow_sequence` unit test (with a model-owned empty-caches stub) pinning this.
- `src/server/batch/scheduler.rs`: new `BatchScheduler::handoff_supported()` (natural sequence-state backend is `DenseKvCache`). `prefill_text_request_for_handoff` rejects unsupported models up front, before any allocation or prefill work.
- `src/distributed/disaggregated/coordinator.rs`: `run_prefill_role_networked` checks `handoff_supported` once at startup (single warning, which keeps the `lablup#708` reference for operators) and rejects each request with a clean per-request error frame. It also no longer exits on a per-request prefill/extract failure: it reports an error frame for that request and keeps serving, reserving loop exit for transport-level conditions.
- `tests/disaggregated_router_e2e.rs`: retargeted `disaggregated_router_completions_match_single_node_byte_fallback` from Gemma (model-owned, unrunnable by construction) to MiniCPM-2B (byte-fallback AND pool-backed), mirroring the chat-usage test; updated the `GEMMA_DIR` doc comment to note its new use. Added `disaggregated_router_rejects_model_owned_family_and_keeps_serving`.

A follow-up hardening pass addressed three review findings in the same serving loop: a malformed-but-well-framed request payload (a decode failure with no `reply_to` to answer) now drops just that request via `continue` instead of exiting the loop, since it is the same availability symptom as the original bug through a different trigger; every error/first-token `ResultFrame` encode failure at each in-loop send site now degrades to a per-request drop (logged and skipped) instead of propagating out and exiting the loop; and the issue number was moved out of the client-facing rejection message into the startup warning only, so operators still get the `lablup#708` pointer in logs without leaking an internal issue reference to API clients.

## What the client sees

A completions/chat request for a model-owned family is rejected at the prefill node before any prefill work. The prefill node returns an error frame; the router renders it as an HTTP 500 JSON error (`{"error":{"message":"prefill node error: the disaggregated handoff does not support this model's model-owned paged sequence-state backend; only pool-backed dense Fp16 families (qwen3 / llama3) can be handed off"}}`). The node stays alive, so a second identical request receives the same clean 500, not a 503 peer-down.

## Test plan

All run on Apple M1 Ultra with `--features metal,accelerate`.

- [x] `cargo check --lib --tests` (workspace) and `cargo clippy --lib --tests --features metal,accelerate -- -D warnings`: clean.
- [x] `cargo fmt --all -- --check`: clean.
- [x] `cargo test --release --features metal,accelerate -p mlxcel-core cache::tests -- --test-threads=1`: 60 passed, including `extract_paged_blocks_rejects_model_owned_shadow_sequence`.
- [x] `cargo test --release --features metal,accelerate --lib -- distributed::disaggregated`: 177 passed (coordinator / serving-protocol / stream-bridge).
- [x] E2E `disaggregated_router_rejects_model_owned_family_and_keeps_serving` on gemma-3-1b-it-4bit, re-run on the final hardened code (after the malformed-frame and encode-failure fixes): PASS, two consecutive requests, two consecutive clean HTTP 500s with the model-owned rejection message, no 503 peer-down.
- [x] E2E `disaggregated_router_completions_match_single_node_byte_fallback` on minicpm-2b-4bit: PASS, router body byte-identical to single-node (`" café, café, café.\n..."`, completion_tokens 16, finish_reason length).
- [x] E2E `disaggregated_router_chat_usage_matches_single_node_byte_fallback` on minicpm-2b-4bit (regression check on serving-loop changes): PASS.

Closes lablup#708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:architecture Architecture and code structure changes area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:high High priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(distributed): prefill handoff crashes the serving loop for model-owned paged families (gemma3 and friends)

1 participant