Skip to content

feat(cluster): make TP and pipeline serving request-safe - #3258

Merged
jundot merged 21 commits into
jundot:mainfrom
jonathan308:feat/cluster-v2-serving
Sep 8, 2026
Merged

jundot merged 21 commits into
jundot:mainfrom
jonathan308:feat/cluster-v2-serving

Conversation

@jonathan308

Copy link
Copy Markdown
Contributor

Important

Stacked draft (4/4). Depends on #3155, #3256, and #3257. This is opened now so the full backend series is visible upstream. Until the dependencies merge, GitHub shows their inherited commits because the dependency branches live on the fork. This branch will be restacked after each merge so the final review is the 20-commit incremental serving/cancellation/telemetry/cache delta.

Incremental fork review and green CI: jonathan308/omlx#6.

Scope

  • base TP and pipeline serving lifecycle
  • public request IDs propagated to rank zero
  • request-scoped disconnect aborts
  • targeted rank cancellation with bounded atomic request sets and acknowledgements
  • bounded prefill cancellation at synchronized chunk boundaries
  • cancellation fencing before distributed batch mutation
  • runtime-failure reconciliation and stale-engine suppression
  • per-request and aggregate prefill/decode/cache telemetry
  • pipeline prompt-cache agreement and response-token normalization
  • persistent rank-local prompt snapshots across restarts
  • cluster-wide hot/SSD cache clearing on loaded and unloaded peers
  • quiescence gates for unload and cache maintenance

Deliberately excluded

  • Phase split and Cluster v2 UI
  • DS4, ANE, MTP, native kernels, and other model/single-Mac optimizations
  • updater, release, repository, and branding changes

Validation

  • incremental branch CI: Python 3.11, 3.12, and 3.13 green
  • full local suite: 10,632 passed, 102 skipped
  • focused serving/cancellation/telemetry/cache suites: green
  • Ruff and git diff --check: passed

@jonathan308

jonathan308 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Following up on the Cluster v2 backend split from #3118 — these slices are high-impact for distributed/RDMA serving. Can we get a status update / review pass when you have bandwidth? Happy to restack or address feedback quickly. @jundot

…erator reaper

- abort_request(request_id): flags the request (its generator stops at the
  next yield boundary) and closes only that request's backend connection,
  replacing the all-or-nothing client close for single-request aborts
  (G3). Signature mirrors AsyncEngineCore.abort_request.
- abort_all_requests: flags all tracked requests, writes the rank-side
  cancel file, closes the shared client, then waits (bounded, default 15s)
  for BOTH the coordinator counter and rank-0 marker telemetry to report
  zero active requests — unload no longer trusts client close as drain
  evidence (G5).
- reap_orphaned_generators: pop-only sweep parallel to
  AsyncEngineCore._reap_orphaned_collectors; requests whose backend
  finished but whose consumer abandoned the generator are reaped after a
  grace period, so _active_requests can't leak and wedge (or spuriously
  unblock) quiescence-gated unload (G4). Driven from has_active_requests
  and abort_all_requests.
- ReadTimeout now also writes the rank-side cancel file: 300s of
  inactivity means a stalled rank, and the old path let the request run to
  completion with nobody reading (G5).
- Non-distributed engines are untouched; all changes are confined to
  DistributedBatchedEngine.
…han reaper

telemetry: force_cancel_all removes active uids through the registered
BatchGenerator, degrades safely with no generator/uids or a failing
batch loop, and the cancel file is consumed exactly once per epoch with
an ack while foreign-deployment files are ignored.

engine: abort_request flags one request and closes only its connection;
an aborted stream surfaces DistributedRequestAborted at the next yield
boundary and drains the counter; abort_all_requests writes the rank-side
cancel file and swaps the client; _wait_for_backend_drain requires
rank-side marker evidence and expires unconfirmed when ranks survive;
the orphan reaper drops only finished-and-abandoned requests and runs
from has_active_requests; a read timeout drops the cancel file.

Note: tests/test_distributed_engine.py imports omlx.engine.batched ->
engine_core -> mlx, so it needs the full env (WS3 build); the same holds
on the base branch.
@jonathan308

Copy link
Copy Markdown
Contributor Author

Restacked backend 4/4 onto current main after #3257 merged. The PR now contains only the 20 incremental serving/cancellation/telemetry/cache commits: 16 files, +2,270/-168. Focused validation passed locally: 197 passed, 3 skipped across distributed cache clearing, launcher, prompt snapshots, telemetry, distributed engine, and SSE keepalive. Hosted Python 3.11–3.13 CI is running on the restacked branch.

@jonathan308
jonathan308 force-pushed the feat/cluster-v2-serving branch from f155c20 to dcb7189 Compare September 8, 2026 05:11
@jundot

jundot commented Sep 8, 2026

Copy link
Copy Markdown
Owner

@jonathan308, thank you for the thoughtful work on this important part of distributed serving. I’ve taken another pass through the PR to consolidate my findings and avoid asking you to make changes over multiple rounds. Please take a look and let me know what you think.

I found several integration pieces present in #3118 but missing from this split:

  • Cancellation: initialize the cancel state and connect vote completion, batch drain/arm methods, and the required control-channel operations. Watchdog scope=all cancellation also needs the synchronized generation path, and cancelled requests need to signal completion to waiting response queues.
  • Cancellation lifecycle: include plan_hash in acknowledgements and restore stale-cancel handling. I reproduced an acknowledged all-request cancel causing a later targeted cancel to retain scope=all.
  • Cache maintenance: register live prompt caches, implement SSD clearing, and connect unloaded local/remote cache clearing using each peer’s own paths. Please adapt the restored code to this split’s dependencies—for example, the original SSD clear() calls flush(), which is absent here.
  • Request and cache agreement: forward the transport request ID through /v1/completions streaming and connect the prompt-cache agreement helper, including its required control-channel methods.

Please preserve #3257’s authentication improvements and the follow-up fixes already on main when restoring these pieces.

I’ll verify the restored integration paths when the update is ready. If you happen to rerun your two-Mac setup, any observations would be helpful.

Once I’ve verified the update and CI passes, I can proceed with merging.

@jonathan308

Copy link
Copy Markdown
Contributor Author

@jundot thanks checking what's missing & my tests from the old hardware setup won't be the same waiting on new hardware coming this week . Still can get tests done just different reference hardware this time .

@jonathan308

Copy link
Copy Markdown
Contributor Author

@jundot I restored the integration paths from your consolidated review in fd547df8, while keeping #3257's authenticated rank-control handshake/message framing intact.

  • Cancellation now initializes/validates the cancel-vote epoch, finishes shared votes on both control-plane and fallback broadcasts, drains Metal work, performs an authenticated rank barrier, arms the exact epoch/UID set, and only then permits batch removal. Watchdog scope=all now stops registered generation contexts and enters that shared generation-loop path rather than mutating rank zero from the heartbeat thread. Cancelled UIDs also put the terminal sentinel into their response queues.
  • Cancel files and acknowledgements are plan-scoped and worker-lifetime-scoped. Watchdog epochs advance past an existing future-skewed marker, existing files become startup watermarks, and acknowledged/stale scope=all markers are not merged into a later targeted cancel. The reproducer now asserts the later marker remains scope=requests.
  • Live LRUPromptCache instances are registered and cleared; SSDPromptSnapshotStore.clear() was adapted to this split's synchronous store (no nonexistent flush()); cold local roots are removed when no distributed engine is loaded; and cold peer cleanup resolves GlobalSettings on each peer instead of sending the coordinator's /Users/... paths over SSH.
  • /v1/completions forwards the transport request ID into both streaming and non-streaming generation. The existing prompt-cache agreement helper is now invoked after memory/SSD lookup, using newly restored authenticated broadcast_owned_bytes() control operations; cancellation uses the restored authenticated barrier().

Validation on the branch: 335 passed, 3 skipped across endpoint integration, control-plane, telemetry/cancellation, prompt snapshots, inference worker, distributed engine, SSE, admin cache clearing, and server tests. A full local run reached 11,298 passing after the endpoint follow-up; the remaining 11 failures are local MLX ABI/version checks (force_fused / exact MLX 0.32.2), outside the touched paths. Hosted Python 3.11–3.13 CI is running now. I do not have the original two-Mac setup available for a hardware rerun.

@jundot

jundot commented Sep 8, 2026

Copy link
Copy Markdown
Owner

@jonathan308, thanks for addressing the review so quickly. I verified the restored cancellation and cache paths, including cancelling one request while another continues generating. The authentication improvements are preserved, and Python 3.11–3.13 CI has passed. LGTM, I’ll merge this.

@jundot
jundot merged commit 94530d8 into jundot:main Sep 8, 2026
3 checks passed
xunlinkx added a commit to xunlinkx/omlx that referenced this pull request Sep 19, 2026
While PR jundot#3258 bounded continuous-batching prefill to 1 chunk via
PrefillCancellationTimeBudget, sequential serving routes (_serve_single,
used when callers pass an explicit seed or on non-batchable architectures)
still ran the entire prompt prefill synchronously inside stream_generate
without checking the cancellation context.

This hooks cooperative cancellation into _TelemetryQueue during prompt
progress reports, polling cancel requests and checking context._should_stop
after every chunk. On disconnect, prefill halts within one chunk and
cleans up cleanly across all ranks.

Relates to jundot#3013.
@jonathan308
jonathan308 deleted the feat/cluster-v2-serving branch September 20, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants