Skip to content

fix(distributed): fast-fail silent stages and sanitize stage logs - #2787

Merged
inureyes merged 5 commits into
mainfrom
fix/issue-2782-fast-fail-silent-stages
Oct 31, 2026
Merged

inureyes merged 5 commits into
mainfrom
fix/issue-2782-fast-fail-silent-stages

Conversation

@inureyes

@inureyes inureyes commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Availability gate (item 1): a full stage_timeout exchange failure opens a gate that covers the whole runtime. While it is open, prepare_sequence_state and forward_sequence fail at once with a typed PipelineUnavailable, which callers can downcast through anyhow. Before this change, each request blocked the model worker for 30 s. The first request after a timeout sends ProbeState to every stage with the 2 s teardown wait and is served normally if all of them answer. Requests that arrive within the 10 s probe interval are refused without sending anything. Error replies and missed teardown acknowledgements never open the gate. A refused forward still goes through fail_sequence, so the fix(distributed): fail one request, not the coordinator, on stage errors #2753 contract holds. The gate logs one warn when it opens and one info when it closes. PipelineServerModel logs each refusal at debug. Client text is unchanged.
  • Locking: the availability mutex is never held across I/O. The probe time is recorded before the lock is released, so concurrent callers are refused instead of each sending its own probe. A generation counter matches probe results to their outage: a probe that succeeds after a sibling probe already closed the gate is served, and a stale failed probe leaves a newer state alone.
  • Peer text escaped (item 2): new peer_text.rs bounds stage-supplied text to 1024 bytes and applies escape_debug. It covers the stage Error message at the four runtime.rs sites, the serde reason in the malformed-reply warning, and request_key at the two remote_service.rs sites. stage_assignment now calls the shared helper.
  • Teardown-ack budget (item 3): adds HandshakeWarnClass::TeardownAck. The reworded "the frame was sent and a slow stage still applies it" line drops to debug once the budget is spent.
  • Docs: updates the failure-path paragraph of docs/distributed.md.

Failing-first evidence (9f06fef with only the test-support plumbing)

test result: FAILED. 35 passed; 4 failed
expected PipelineUnavailable: ... remote stage 127.0.0.1:33311 timed out after 1s
assertion `left == right` failed: the request after a timeout probes once and is then served
stage text reached the error unescaped: "boom\nINFO forged\u{1b}[31m"
40 of 40 teardown misses were logged at warn

Verification at 487634e

These ran on GB10 under gpu-lock with --test-threads=1, MLXCEL_REQUIRE_MODELS=1 and MLXCEL_SDPA_DETERMINISTIC=1. fmt and clippy (--lib --tests -D warnings) are clean.

Suite Result
distributed:: lib tests 1576 passed, 4 ignored
scheduler_pipeline_failure_tests 4 passed
distributed_integration 20 passed
pipeline_e2e 30 passed
pipeline_remote_real_models (--skip glm_moe_dsa) 10 passed
pipeline_server_remote_real_models (--skip glm_moe_dsa) 7 passed
pipeline_ci_multi_stage_real_models 4 passed
disaggregated_serving_e2e 2 passed
disaggregated_router_e2e 8 passed
server_exit_joins_worker 2 passed

A RunEntry timeout is attributed to the entry stage until the first probe names the silent one; per-stage attribution is out of scope per the issue.

Closes #2782

While one remote pipeline stage stayed silent (a stopped process, a partition, an on-path party dropping frames, none of which needs the cluster secret), every new request blocked the single model worker for a full 30 s stage timeout before failing, and sequences prepared before the outage each paid the same at their next forward. `RemotePipelineRuntime` now keeps an availability gate (`stage_availability.rs`): a full-`stage_timeout` exchange failure opens it, and while open `prepare_sequence_state` and `forward_sequence` fail at once with a typed `PipelineUnavailable` (downcastable through `anyhow`). It is not a fixed cooldown: the first request after the timeout probes every stage with the short teardown wait and is served when they all answer; requests inside the 10 s probe interval are refused without sending anything. Only `exchange` opens it; `Error` replies and teardown-ack misses never do. The forward-path refusal goes through `fail_sequence`, so `Err` still means the coordinator's state was discarded (#2753). While open, the teardown of a sequence is sent to the silent stage with no ack wait. The gate holds its mutex only for state transitions, never across the probe exchanges, and a generation counter keeps a probe from closing an outage that a newer timeout replaced while it was in flight. `PipelineServerModel` logs the refusal at debug; the open and close transitions carry the operator signal at warn and info.

A stage's `Error { message }`, and the upstream request id a stage logs, are now bounded to 1024 bytes and `escape_debug`-escaped before they reach a log line, through the shared `peer_text::loggable_peer_text` that `stage_assignment` already used for abort details, so an authenticated peer cannot forge log lines on the coordinator or on a stage.

A stage that misses the teardown ack wait while healthy (still finishing a long forward) draws its "did not acknowledge ... within ...; the frame was sent" line from the new `teardown-ack` warning budget, the rest at debug.

Tests: `runtime_availability_tests.rs` (gate fast-fail and probe recovery, one dropped reply does not refuse the next request, stage error text escaped, teardown-ack warnings budgeted), `stage_availability` state-machine tests, `peer_text` tests; the stub stage gains `set_silent`, `wait_for_commands` and an `Error { message }`. The scheduler timeout test's pinned command log now expects the `probe_state` before the next prepare.

Closes #2782
@inureyes inureyes added status:review Under review type:security Security vulnerability or fix priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Oct 31, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Fast-fail requests while a remote pipeline stage is silent (probing availability gate), escape stage-supplied text before logging, and budget teardown-ack warnings (#2782).

Findings Addressed

No CRITICAL or HIGH findings; no fix commits were needed.

Remaining Items

  • A RunEntry timeout opens the gate naming the entry stage, though any stage may be the silent one, so the open-transition warn line and the first zero-wait teardown can point at a healthy stage. The first probe corrects failed_peer. Per-stage RunEntry attribution is out of scope per the issue. (LOW)
  • StageAvailability::probe_failed can reopen a gate that a concurrent probe just closed without logging the closed-to-open warn line, and a second overlapping probe for the same generation is refused after the first closed the gate. Both need a probe that outlasts probe_interval plus concurrent callers, which the single model worker does not produce. (LOW)
  • When the gate names a stage that is actually healthy (one dropped reply), its late cancel and release acks are dropped by the next exchange's nonce matcher at warn, at most 3 per exchange. This happens once per full stage_timeout event, which already costs 30 s and logs the open line, so the rate is bounded and no budget is needed. (LOW, no change)

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass (distributed:: 1572 passed, scheduler_pipeline_failure_tests 4 passed, fmt and clippy clean on 7dade07)

…text

Two probes for the same outage can overlap when one outlasts the probe interval. Before this change a probe that failed after its sibling closed the gate reopened it without the open warn line, so the log showed a closed gate that was refusing requests, and a sibling that also succeeded was refused because the gate was already closed.

StageAvailability now takes the probe's generation in probe_failed as well as close_after_probe. A succeeded probe for an outage a sibling already closed is served (ProbeClose::AlreadyClosed). A failed probe of the current outage that finds the gate closed reopens it and the coordinator logs the open line again. A failed probe of an older outage leaves the newer state alone and refuses only its own request. Gate lines are logged after the mutex is dropped.

The coordinator's dropped-reply warning formatted the serde_json error raw, and serde_json quotes an unknown variant or field name from the payload verbatim, so a stage could forge a log line through it. The reason now goes through loggable_peer_text.

Validated with the distributed:: lib tests (1576 passed), scheduler_pipeline_failure_tests (4 passed), fmt and clippy. New unit tests cover the three overlap cases and the escaped serde reason.

Refs #2782
@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

No CRITICAL, HIGH or MEDIUM findings. Two LOW items fixed in 487634e.

Fixed

  • Overlapping availability probes (LOW, stage_availability.rs): probe_failed could reopen a gate a sibling probe had just closed without the open warn line, and a second succeeded probe of the same outage was refused. Both result methods now take the probe's generation: a succeeded sibling is served, a failed probe of the current outage reopens the gate and logs the open line again, and a failed probe of an older outage leaves the newer state alone. Three unit tests cover the cases.
  • Unescaped peer text in the dropped-reply warning (LOW, runtime.rs note_dropped caller): serde_json quotes an unknown variant or field name verbatim, so a stage holding the secret could forge a coordinator log line. Now escaped through loggable_peer_text, with a unit test.

Checked, no change

  • Unauthenticated on-path frame dropping only produces refusals: the gate state is fixed-size, keyed by configured stage addresses, and one probe (at most one teardown wait, stopping at the first silent stage) goes out per probe interval. Logs are bounded: one open warn per outage transition, one close info, refusals at debug, teardown misses under the teardown-ack budget.
  • The availability mutex is never held across an exchange; gate lines are now logged after it is dropped.
  • loggable_peer_text escapes C0/C1 controls, bidi and line-separator characters (escape_debug) after a 1024-byte char-boundary cut.
  • Remaining LOW items from the implementation review (RunEntry timeout attribution, late-ack drop warnings) are unchanged and in line with the issue's scope.

Verification

distributed:: 1576 passed, scheduler_pipeline_failure_tests 4 passed, fmt and clippy (--profile test-fast --features cuda --lib --tests -D warnings) clean on 487634e.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Oct 31, 2026
Bilingual report on the coordinator availability gate, peer text escaping and the teardown-ack warning budget from #2782. It records the probe-versus-cooldown and generation-counter decisions, the local gate results, the hosted 2-host logical failure at 487634e on the 50 ms bound of the new availability test, and the slow-but-alive stage risk.

Refs #2782
The hosted 2-host logical job (run 41161926566) measured 101 ms for the refused prepare against a 50 ms bound on a loaded runner. The command-log assertion is the precise check that nothing reaches the stage, so the time bound now only separates a refusal from the 1 s stage timeout.
@inureyes
inureyes marked this pull request as ready for review October 31, 2026 03:18
On the hosted 2-host logical job (run 41163802130) more than 300 ms passed between B's probe and C's prepare, so C probed again and the command-log assertion saw a second probe_state. A 2 s test interval keeps C inside the window on a loaded runner; the suite now takes about 4.6 s.
@inureyes
inureyes merged commit b52d15e into main Oct 31, 2026
33 checks passed
@inureyes
inureyes deleted the fix/issue-2782-fast-fail-silent-stages branch October 31, 2026 03:56
inureyes added a commit that referenced this pull request Oct 31, 2026
Bilingual report (English and Korean) for the five LOW residuals of #2787, #2788 and #2789 closed by this PR.
inureyes added a commit that referenced this pull request Oct 31, 2026
Closes the five LOW residuals of #2787, #2788 and #2789 listed in #2790, in one PR.

## Changes

- **KV storage report (item 1).** `kv_cache_storage_modes` returns `Option<Vec<Option<KVCacheMode>>>`; a `None` entry is a layer with no KV. Families describe layers with `LayerKv` (`Full`, `Sliding`, `Fp16Only`, `None`) from the predicate their cache builder uses. Llama 4 reports chunked layers as FP16 (`uses_chunked_cache` now drives the builder, the masks and the report). Qwen3-Next, Qwen 3.5, Qwen4-Exp, Bailing linear, LFM2 and NemotronNAS report linear, convolution and skipped layers as stateless. Model-owned families without a mode table report real storage instead of `None`: DeepSeek V4, RecurrentGemma, Muse Glimmer, Mamba, Mamba2 and RWKV7 as listed, plus Nemotron-H, Jamba, Falcon-H1, Plamo2, GraniteMoeHybrid, Kimi Linear, Kimi K3 and Inkling, which had the same gap, and the five VLM wrappers around them. The server log adds `kv_cache_mode_stateless_layers`; `logit_trace` prints the stateless count.
- **Sliding window (item 2).** `validate_sliding_window` (via `cache_window`, only when a layer slides) fails the load for 0 or values above `i32::MAX` in Gemma 3, Gemma 4, GPT-OSS, ExaOne 4, Laguna, Step 3.5, Ministral 3, Mellum and AFMoE; Gemma 3 also rejects `sliding_window_pattern: 0`. Gemma 3, GPT-OSS, Laguna, Mellum, ExaOne 4, Ministral 3 and AFMoE store the validated `i32` for their builders. Gemma 4 validates in both the single-process load and the pipeline-stage load (`Gemma4StageModel::from_filtered_weights`) and keeps its casts on the shared `TextConfig` (dozens of sites), now lossless after the check.
- **IREE local-task (item 3).** `csrc/xla_local_task.c` builds the device without the flag registry: executor with 8 MiB worker stacks over `MLXCEL_XLA_LOCAL_TASK_WORKERS` workers (1..=256, IREE's topology limit; anything else fails the load naming the variable) or the physical-core topology, all loaders, heap allocator, task driver, default device with the same proactor pool the runtime uses. Both device-creating entry points use it; other drivers are unchanged. Every IREE symbol used is exported by the pinned CUDA tree and by `iree-dist-3.12.0rc20260721-linux-x86_64` (the only dist published for that release; there is no aarch64 dist), and the new C file compiles against both header trees.
- **Test support (item 4).** `XlaPreparedPrefillLogits` needs mlxcel-xla `test-support` (root `test-utils`) or `diagnostics`, resets slots before each prefill, and `Qwen25VlLanguageDiagnosticEngine` wraps it. `xla_prepared_prefill` requires `test-utils`; the CI link step passes it.
- **Pipeline gate (item 5).** Only `StageUnreachable` (timeout or failed send) opens the gate. A `RunEntry` timeout opens it unattributed, so the entry stage keeps its teardown wait and the next probe names the silent stage; a failed send logs "could not be reached", and a probe that reopens the gate logs its real cause (send failure or timeout). `PipelineUnavailable.stage` is `Option<String>`. `docs/distributed.md` describes the new rule.

## Failing first

Each new test fails on `main` 1a257bc or, where it cannot compile there, under a mutation restoring `main`'s behaviour:

- Existing local-task tests, main binary: all three fail with `thread creation failed with 22; [runtime-init] failed to open IREE HAL device 'local-task'`.
- `local_task_executor_uses_8_mib_stacks_without_iree_flags`, stack set back to 128 KiB: `xla_local_task_probe failed: ... thread creation failed with 22`.
- `llama4_chunked_layers_report_fp16_storage_under_int8`: `left: Some([Some(Int8) x8])` vs expected `Int8` only at 3 and 7.
- `qwen3_next_linear_layers_report_no_kv_storage`: eight `Some(Int8)` vs `[None, None, None, Some(Int8), ...]`.
- `recurrent_gemma_reports_...`, `mamba_reports_every_layer_stateless`, `deepseek_v4_reports_fp16_storage_for_every_layer` (override returning `None`): `left: None` / `a storage report`.
- `gemma3_rejects_zero_sliding_window_pattern_at_load`, `sliding_window_zero_is_a_load_error` (validation off): the loads succeed.
- `run_entry_timeout_does_not_name_the_entry_stage` (main attribution): `failed_peer` is `Some("127.0.0.1:41749")`, the entry stage.
- `send_failure_opens_the_gate_with_a_send_reason`: the open line reads `remote stage 127.0.0.1:40565 did not answer within 1s`.

## Verification (spark-102, GB10)

- `cargo fmt --all -- --check`, `make verify-env-var-docs`: clean.
- `cargo clippy --profile test-fast --features cuda -p mlxcel -p mlxcel-core -p mlxcel-xla --lib --tests -- -D warnings` and `cargo clippy --release --features cuda,xla-iree,test-utils -p mlxcel-xla -p mlxcel --lib --test xla_prepared_prefill -- -D warnings`: clean.
- After the review fixes: clippy on `mlxcel` + `mlxcel-xla` lib and tests clean, `distributed::pipeline::` 416 passed, `mlxcel-xla` `local_task` 6 passed.
- Lib tests (`--test-threads=1`, gpu-lock): `models::` + `vision::` 3429 passed; `distributed::` + `server::batch::scheduler` 1845 passed; `mlxcel-core` `cache::` + `generate::` 624 passed; `mlxcel-xla --lib` 370 passed.
- Integration (`cuda,test-utils`): `distributed_integration` 20, `pipeline_e2e` 30, `pipeline_remote_real_models` 10, `pipeline_server_remote_real_models` 7, `pipeline_ci_multi_stage_real_models` 4 (`--include-ignored --skip glm_moe_dsa`, `MLXCEL_REQUIRE_MODELS=1 MLXCEL_SDPA_DETERMINISTIC=1`), `disaggregated_serving_e2e` 2, `disaggregated_router_e2e` 8: all pass.
- `cargo test --release --features cuda,xla-iree,test-utils --test xla_prepared_prefill -- --ignored`: 4/4 on the default `local-task` device. `MLXCEL_XLA_LOCAL_TASK_WORKERS=0` and `abc` fail the load naming the variable; `2` passes. Unit tests also reject 257 and 1000.
- Item 4 gating: a root `use mlxcel_xla::XlaPreparedPrefillLogits` fails `cargo check --features cuda,xla-iree` with E0432 and passes with `test-utils`. `--features cuda,xla-reference-diagnostics --lib --tests` checks clean. (Both checks ran in the `test-fast` profile.)
- Server smoke, `--kv-cache-mode int8`, release `mlxcel-server`: `llama-4-scout-17b-16e-instruct-4bit` logs `applied_layers=12 total_layers=48 stateless_layers=0`; `gemma-3-1b-it-4bit` logs `applied_layers=4 total_layers=26`.

Not changed: with `MLXCEL_XLA_DEVICE=cuda`, `local_task_gemma3_vlm_prefill_matches_mlx_mask` misses its 1e-3 tolerance (up to 5.4e-3) under the default `f16` CUDA precision, identically on `main`; it passes with `MLXCEL_XLA_PRECISION=f32`.

Closes #2790



## Compatibility notes

- `PipelineUnavailable.stage` is a public field and changes from `String` to `Option<String>` (`None` until a probe names the silent stage); callers that read it need `as_deref()`.
- The `kv_cache_mode_total_layers` startup log now counts only layers that hold KV, so hybrid models (Qwen3-Next, LFM2, Jamba and similar) log a lower total than before; stateless layers are reported in the new `kv_cache_mode_stateless_layers` field.
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority status:done Completed type:security Security vulnerability or fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hardening(distributed): Fast-fail silent stages and sanitize stage logs

1 participant