Skip to content

fix: join side-model workers on server exit - #2827

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-2745-join-side-workers
Nov 2, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/issue-2745-join-side-workers

Conversation

@inureyes

@inureyes inureyes commented Nov 2, 2026

Copy link
Copy Markdown
Member

Summary

A CPU build aborts with pure virtual method called when a worker frees MLX state after main returns. #2742 joined the chat model worker; this PR joins every side worker too, exits a sleeping worker without reloading, bounds and documents the load-in-progress case, and always drains the remote pipeline stage.

What changed

  • Added shutdown_and_wait to AudioModelProvider, EmbeddingModelProvider, ImageModelProvider and RerankModelProvider, plus an inherent method on RealtimeVoiceChatEngine. Each reuses WorkerExitObserver; Drop keeps its current join.
  • serve_with_model_provider now keeps one clone of every side Arc and joins the side workers first, then the chat worker, on the blocking pool under a single WORKER_EXIT_TIMEOUT deadline. Side-worker failures log warn! and never replace the error that ended serving. New log line: side model workers exited before process exit.
  • A worker sleeping under --sleep-idle-seconds now breaks on ModelRequest::Shutdown without clearing sleeping or reloading.
  • join_model_worker_before_exit takes its timeout as a parameter. On timeout the warning and returned error say the worker is still running and that a CPU build may abort with pure virtual method called at exit. The same limitation is documented on WORKER_EXIT_TIMEOUT, ROUTER_SHUTDOWN_TIMEOUT and in docs/server-features.md, since model load has no cancellation point (rejected: adding one is not expressible across the per-family loaders with lazy MLX evaluation).
  • The --pp-peer stage path captures the signal result, always shuts the stage down inside tokio::task::spawn_blocking, then returns the signal error if there was one. The select-then-shutdown sequence is a helper unit-tested with a failing signal future and a fake handle. The router half was already fixed in fix(server): join model workers before the process exits #2742.
  • Tests: two real-server cases in tests/server_exit_joins_worker.rs (Whisper side worker, embedding worker joined before a later --image-model failure), the sleeping-worker test, a startup_tests.rs timeout test with a fake worker that sleeps 2 s before reading its channel, and the stage-shutdown test.

Test plan

  • cargo fmt --check
  • cargo clippy -p mlxcel --lib --tests -- -D warnings
  • cargo check -p mlxcel --lib --tests
  • cargo build -p mlxcel --bin mlxcel-server
  • cargo test -p mlxcel --lib server::startup::
  • cargo test -p mlxcel --test server_exit_joins_worker (real-model cases skip on this host: the checkpoints are absent)
  • GPU host: repeat server_exit_joins_worker with --features cuda and run the 2-host logical PP CI job (not available in this environment)

Closes #2745

@inureyes inureyes added status:done Completed type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Nov 2, 2026
On a CPU build, an MLX free that runs after the C runtime's static destructors start aborts with `pure virtual method called`. PR #2742 joined the chat model worker but left the audio, realtime, embedding, image and rerank workers joining only in their unbounded `Drop`, on whichever thread dropped the last `Arc`.

Each side provider now exposes `shutdown_and_wait`, sharing the chat worker's `WorkerExitObserver`, and `serve_with_model_provider` keeps one clone of every side `Arc` and joins the side workers first, then the chat worker, on the blocking pool under one `WORKER_EXIT_TIMEOUT` deadline. Side-worker failures log `warn!` and never replace the error that ended serving. The sleeping worker now exits on `Shutdown` without reloading. `join_model_worker_before_exit` takes its timeout as a parameter and reports that a timed-out worker is still running, which a CPU build may abort on; the limitation is documented because model load has no cancellation point. The remote pipeline stage path always shuts the stage down and joins it on the blocking pool, including when the Ctrl-C handler cannot be installed.

Validation: cargo fmt --check, clippy on the lib and tests with -D warnings, cargo check, the server build and the startup unit tests pass. The real-model integration tests skip on this host because their checkpoints are absent.

Refs #2745
@inureyes
inureyes force-pushed the fix/issue-2745-join-side-workers branch from b808c3d to 310993d Compare November 2, 2026 08:06
@inureyes
inureyes marked this pull request as ready for review November 2, 2026 08:07
@inureyes
inureyes merged commit b30cce6 into main Nov 2, 2026
1 check passed
@inureyes
inureyes deleted the fix/issue-2745-join-side-workers branch November 2, 2026 08:07
@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:low Low 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: join side-model workers and finish remaining exit-path gaps after #2738

1 participant