Skip to content

[pipeline] Fix silent drop in fused subprocess pipeline - #1576

Merged
mthrok merged 1 commit into
mainfrom
fix-fuse
Jun 30, 2026
Merged

[pipeline] Fix silent drop in fused subprocess pipeline #1576
mthrok merged 1 commit into
mainfrom
fix-fuse

Conversation

@mthrok

@mthrok mthrok commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Problem. A non-continuous fused subprocess pipeline (fuse_subprocess_stages=True) could silently drop its earliest items under concurrent/instrumented startup. Root cause (confirmed by instrumenting _run_sessions): the non-continuous workers shared one work-stealing input queue, and the bridge _feed put num_workers anonymous _SESSION_END markers on it. A worker that drained its stream and reached _SESSION_END early could loop back and consume a second marker meant for a slower peer still holding un-flushed items. That peer never ended, _collect reached its _DONE count from the wrong workers and finished, and the peer's earliest items were discarded with no error or log.

A startup READY-handshake (the original hypothesis) does not fix this — items in a bounded mp.Queue are never lost before draining; the loss is the double-_SESSION_END consumption on the shared queue.

Fix. Give each non-continuous worker its own input queue (continuous mode already does this). The bridge round-robins items across the per-worker queues and sends exactly one _SESSION_END to each, so every worker ends exactly once and no worker can steal a peer's marker. _broadcast_shutdown now sends one _POOL_SHUTDOWN per worker queue. This unifies both modes and removes the shared marker entirely.

…r input queues)

Summary:

**Problem.** A non-continuous fused subprocess pipeline (`fuse_subprocess_stages=True`) could silently drop its earliest items under concurrent/instrumented startup. Root cause (confirmed by instrumenting `_run_sessions`): the non-continuous workers shared one work-stealing input queue, and the bridge `_feed` put `num_workers` anonymous `_SESSION_END` markers on it. A worker that drained its stream and reached `_SESSION_END` early could loop back and consume a *second* marker meant for a slower peer still holding un-flushed items. That peer never ended, `_collect` reached its `_DONE` count from the wrong workers and finished, and the peer's earliest items were discarded with no error or log.

A startup READY-handshake (the original hypothesis) does **not** fix this — items in a bounded `mp.Queue` are never lost before draining; the loss is the double-`_SESSION_END` consumption on the shared queue.

**Fix.** Give each non-continuous worker its own input queue (continuous mode already does this). The bridge round-robins items across the per-worker queues and sends exactly one `_SESSION_END` to each, so every worker ends exactly once and no worker can steal a peer's marker. `_broadcast_shutdown` now sends one `_POOL_SHUTDOWN` per worker queue. This unifies both modes and removes the shared marker entirely.

**Files**
- `_subprocess_pipeline_pool.py`: one input queue per worker in both modes; per-worker shutdown.
- `_components/_subprocess_pipe.py`: `_feed` round-robins items + broadcasts one `_SESSION_END` per queue; `max_threads` updated; docstrings.
- `subprocess_pipeline_fuse_test.py`: updated `FeedAbortTest` for the new `_feed` signature; added `StartupRaceFuseTest` regression test.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 29, 2026
@meta-codesync

meta-codesync Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D110118262. (Because this pull request was imported automatically, there will not be any future comments.)

@mthrok
mthrok marked this pull request as ready for review June 30, 2026 09:59
@mthrok
mthrok merged commit c6c1a51 into main Jun 30, 2026
109 of 111 checks passed
@mthrok
mthrok deleted the fix-fuse branch June 30, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant