Why the decode report at shutdown can stall teardown for half an hour and frees nothing

PR #5024 · reviewed at ea1a6e22, re-checked at 9df434a7 (the reviewed files are unchanged since d2e22762) · review still pending · Megatron-LM e0a4bfed

Before
PR 3's shutdown stopped every engine in index order, then the frontend, NATS and etcd.
This PR
Stops the decode engines one by one. Then, for each decode engine, it makes one call that tells the prefill engines "this decode engine is gone, let go of the KV blocks you kept for it". Only then does it stop prefill.
Status
Open — not fixed in this PR. Raised as review comment C3, which asks to delete the report step, with nothing in its place, and to stop every engine at once as vLLM does (C11).

Two pages on this PR, one question each. This one: the report step at shutdown.

Background. A prefill engine keeps a prompt's KV blocks pinned until the decode engine that asked for them has copied them. It tracks each decode engine by an owner ID. If a decode engine dies mid-copy, those blocks stay pinned. Upstream's fix is confirm_terminated(address, owner): it tells a prefill coordinator that the owner is gone, so it unpins the blocks. Dotted words have a short explanation: hover or tap them.
It is not a reference count that has to reach zero. Prefill does not need the report to exit. It can stop at any time, and when it stops, every block it kept goes with it. The report only helps when prefill keeps running after a decode engine dies, which is the case upstream wrote it for. At full shutdown prefill stops one step later, so the report frees nothing that stopping prefill doesn't.

Example: 1 prefill engine P0, whose coordinator answered the address lookup but then hangs; 3 decode engines D0–D2; the default control_timeout_s = 600 (C1 removes this key; with any per-call timeout T, the wait is decode engines × T). Each report waits up to 600 s in the worker plus a 10 s margin in the driver, and confirm_terminated waits its full timeout with no retry when nobody answers.

Where the wait comes from. Not from stopping decode: that is usually quick. It comes from the reports:

  1. The decode engines stop, one after another (L1409).
  2. Then one report per decode engine, one after another (L1492). Each report asks every prefill coordinator.
  3. If one coordinator never answers, each report waits its full 610 s before the next one starts: 3 × 610 s ≈ 30.5 min.
  4. Only then does prefill stop, and that would have freed the same blocks anyway.
This PR stop D0–D2 report D0 · 610 s report D1 · 610 s report D2 · 610 s P0 stops here: its coordinator and every pinned block go with it ≈ 30.5 min of waiting before prefill even stops Proposed stop D0–D2 and P0 at once: same blocks freed, no wait 0 s 610 s 1220 s 1830 s decode prefill report

Why the report changes nothing here: upstream keeps owner IDs only in the coordinator's memory and says

"Source coordinators and their engines must restart as a single lifecycle unit … Ownership is not replicated."

So stopping P0 one line later frees every block the report would have freed. The hook exists for replacing one failed decode engine while prefill keeps running, and it requires every decode rank to have exited first. Here the decode kill is issued but not awaited, as the PR's own docstring says.

What would fix it — proposed, not in the PR

Where the fix lands: RL only, two files. dynamo_generation.py (shutdown and three helpers) and dynamo_worker_mixin.py (three worker reads). No Megatron-LM change: the hook stays for a later PR that replaces a decode engine live.

Nothing below is implemented. The report is deleted, not made faster: nothing replaces it, because stopping prefill already frees the blocks.

Shutdown, after the fix (proposed, not run) · driver process

# driver, MegatronDynamoGeneration.shutdown
owners = read handoff owner from each decode rank 0
for d in decode: stop(d)
stop(every engine at once)                                # C3 + C11: cleanup ≤30 s, then kill; no role order
for owner in owners: prefill0.confirm_decode_terminated(owner)
for p in prefill: stop(p)                                 # stopping prefill frees every kept block
stop frontend, NATS, etcd

Delete too: _prefill_coordinator_addresses, _handoff_owners, _confirm_decode_terminated, and the worker's confirm_decode_terminated.

🔴 review comment C3 — dynamo_generation.py:1381

Why stop gracefully at all?

Mostly, it doesn't need to. At the end of a run nothing is saved here: partial checkpoints are taken while the run is live, not at shutdown. On main:

Two things still need an explicit stop: the frontend, NATS and etcd, which run as their own processes outside Ray, and the engines' placement groups, if the Ray cluster outlives the run. C3 and C11 ask for exactly vLLM's model: one cleanup wave across every engine, then kill, then the services. A decode engine killed while copying from a prefill engine that is being killed too has nothing left to wait for, so no role order is needed.

So what. With one prefill coordinator that does not answer, shutdown waits about (number of decode engines) × 610 s: 30.5 min for 3 decode engines, over 5 hours for 32, about 3.5 days for 500. It buys nothing, because stopping prefill frees the same blocks. Drop the step; batching the calls would cap the wait but still free nothing. With the step gone, every engine can stop at once, with no role order (at 1,000 engines, C11).