Repository navigation
[Data] [Train] (Data fault tolerance) Implement lineage reconstruction for push-based streaming_split via external consumer tasks - #68337
ayushk7102 wants to merge 8 commits into
Conversation
…xternal consumer tasks Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces tracking and lineage reconstruction for external consumer tasks, such as those in push-based splits. It adds the ExternalConsumerTasks class to manage external task submissions, completions, and failures, and integrates it with the streaming executor and lineage tracker. Two important issues were identified in the review: first, the exception handling in the push watcher loop fails to catch RayTaskError wrapping an ObjectLostError, which would prevent reconstruction of lost inputs; second, using num_returns=len(pending_pushes) in ray.wait can cause unnecessary 100ms delays if any push is slow, which can be resolved by setting num_returns=1.
| except ObjectLostError as e: | ||
| # A push whose input was lost raises the loss wrapped in | ||
| # RayTaskError. Unwrap it so reconstruction errors report the | ||
| # original loss. | ||
| lost = e.cause if isinstance(e, RayTaskError) else e |
There was a problem hiding this comment.
The except ObjectLostError as e: block will not catch RayTaskError exceptions, even if they wrap an ObjectLostError. As a result, any RayTaskError wrapping an ObjectLostError will fall through to the general except Exception: block and be abandoned instead of reconstructed.
To fix this, catch both ObjectLostError and RayTaskError, and re-raise the RayTaskError if its cause is not an ObjectLostError so it can be handled by the general exception handler.
except (ObjectLostError, RayTaskError) as e:
if isinstance(e, RayTaskError) and not isinstance(e.cause, ObjectLostError):
raise
# A push whose input was lost raises the loss wrapped in
# RayTaskError. Unwrap it so reconstruction errors report the
# original loss.
lost = e.cause if isinstance(e, RayTaskError) else e| ready, _ = ray.wait( | ||
| list(pending_pushes), | ||
| num_returns=len(pending_pushes), | ||
| timeout=_WATCH_WAIT_TIMEOUT_S, | ||
| fetch_local=False, | ||
| ) |
There was a problem hiding this comment.
Using num_returns=len(pending_pushes) causes ray.wait to block for the entire timeout (0.1s) unless all pending pushes are ready. If even a single push is slow, this introduces a 100ms delay in processing other pushes that are already completed.
Setting num_returns=1 allows ray.wait to return immediately as soon as at least one push is ready, returning all currently ready pushes without waiting for the slow ones.
| ready, _ = ray.wait( | |
| list(pending_pushes), | |
| num_returns=len(pending_pushes), | |
| timeout=_WATCH_WAIT_TIMEOUT_S, | |
| fetch_local=False, | |
| ) | |
| ready, _ = ray.wait( | |
| list(pending_pushes), | |
| num_returns=1, | |
| timeout=_WATCH_WAIT_TIMEOUT_S, | |
| fetch_local=False, | |
| ) |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit a7798de. Configure here.
| for i in range(output_op.num_output_splits()) | ||
| if i not in finished_splits | ||
| ) | ||
| return output_state.output_queue.has_next() |
There was a problem hiding this comment.
Dead split keeps executor alive forever
High Severity
The new keep-alive path treats leftover output for any split that has not called finish_split as unresolved work. A dead consumer never notifies, so that split stays unfinished: its pusher parks once the window is full, and remaining bundles sit in the output queue. run then never exits, mark_finished never fires, and healthy splits never receive EOF. Previously the loop stopped when operators completed, so a dead client could not pin the whole epoch.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit a7798de. Configure here.
…-split-ft-pr Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
There was a problem hiding this comment.
- Can we create release tests that has lost blocks to test end2end?
- Let's update the existing test:
training_ingest_benchmark-task=image_classification.full_training.parquet.pull_vs_push
training_ingest_benchmark-task=image_classification.skip_training.parquet.pull_vs_push
training_ingest_regression_test.throughput.pull_vs_push
training_ingest_regression_test.peak_object_store_memory.pull_vs_push
to include the external_consumer_tasks to make sure there is no obvious regression compared to the old pull iterator.
- also fix the bot comments
| lineage reconstruction. The executor keeps running while any external | ||
| task is unresolved, so a lost input can still be reconstructed. | ||
| """ | ||
| assert self._topology is None, "Enable before execute()." |
There was a problem hiding this comment.
assert self._external_consumer_tasks is None to avoid reinitialization by mistake
| for ref in ready: | ||
| push = pending_pushes.pop(ref) | ||
| try: | ||
| ray.get(ref) |
There was a problem hiding this comment.
is this ref the object? Do we need to fetch the object here?
| # doesn't wait on it. The re-produced block arrives later | ||
| # under a new seq. | ||
| consumer, key = self._consumers[push.split_idx] | ||
| consumer._push_split_deliver.remote( |
There was a problem hiding this comment.
Do we need this? I see the iterator just ignore the _LostBlock
…o prevent reinitalization Signed-off-by: Ayush Kumar <[email protected]>
…inal task index (#68400) ## Summary A lineage reconstruction task now runs with the `TaskContext.task_idx` of the task it re-runs. Before, it got a fresh index, so a re-run `Write` added a second file instead of replacing the first, and seeded operations drew different values. ## Before `TaskContext.task_idx` came from the operator's submission counter, `_next_data_task_idx`, which goes up on every submission, including reconstruction tasks. Several things are keyed on that index, and assume a re-run of the same task sees the same value: - **File writes.** `FilenameProvider` names a file `{write_uuid}_{task_index}`, and its contract says names "must be unique and deterministic for a given write UUID and task index". Parquet writes with `existing_data_behavior="overwrite_or_ignore"`. A Ray Core retry resends the same `TaskContext`, so it overwrites its own file. A reconstruction task got a new index, so it wrote a new file. If the failed attempt's file had already landed (for example, the node died after the upload but before the driver heard back), both files stayed, and the output had duplicated rows. Ray Data's own `Data sink ... finished. N rows` count stays correct, because it only counts the attempt it saw finish. - **Seeded and indexed values.** `random_sample(seed=...)`, `streaming_train_test_split(seed=...)`, the `random(seed=...)` expression and `monotonically_increasing_id()` all derive from the index, so a re-run produced different rows, values or IDs. Reconstruction also assumes a re-run reproduces its output block for block, since it skips blocks that were already delivered downstream. We hit the write case in a chaos release test (`image_embedding_from_uris_fake_gpu_lineage_reconstruction_chaos`, actor-only backend): the output check found 1,326 duplicated rows (41 images written twice), while the sink reported exactly the expected 2,484,000 rows. ## After `MapOperator._context_task_idx(inputs)` picks the index for the task's `TaskContext`. For a bundle that carries a `reconstruction_stamp`, it is the original index, read back from the stamp's lineage task ID (`{op_id}:{task_index}`). Otherwise it is the next counter value, as before. All three ways of submitting a map task use it: the task pool, the actor pool and the experimental actor-only pool. The operator's own bookkeeping (the in-flight task map, `preserve_order` output keys) still uses the fresh counter, so a re-run never shares a key with the attempt it replaces. A re-run `Write` now overwrites the failed attempt's file, and seeded operations reproduce their original output. ```mermaid flowchart TD subgraph Before subgraph BS[Subsystem: execution] subgraph BC[Component: MapOperator task submission] B1[reconstruction bundle] --> B2["TaskContext.task_idx = _next_data_task_idx (new)"] B2 --> B3["Write: new file {uuid}_{new}"] end end end subgraph After subgraph AS[Subsystem: execution] subgraph AC[Component: MapOperator task submission] A1[reconstruction bundle] --> A2["TaskContext.task_idx = original index from reconstruction_stamp"] A2 --> A3["Write: overwrites {uuid}_{original}"] end end end classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class A2,A3 changed ``` ## Subsystems Execution (map operator task submission). The three operator edits pass the input bundle through so the helper can read its stamp. ## Not a duplicate I searched open PRs for `task_idx`, "lineage reconstruction" with "write" or "duplicate", "idempotent write" and "reconstruction task index". The open Data fault-tolerance PRs (#68094, #68337, #68378) don't change the task index. ## Testing - `pytest python/ray/data/tests/unit/test_lineage_reconstruction_executor.py`: 6 passed, including the new `test_reconstruction_task_context_reuses_the_original_task_index`. - `pre-commit` on the changed files: passes. `pyrefly-data` was run separately with the hidden-directory exclusion turned off, because the branch lives in a worktree under a dot-directory. It reports no errors on changed lines. - **Not run yet:** the two new end-to-end tests in `test_lineage_reconstruction.py` (`test_re_run_write_overwrites_the_file_of_the_failed_attempt` and `test_re_run_draws_the_same_seeded_random_sample`). My local Ray build doesn't match this branch, so workers fail at startup for every test in that file, including existing ones. I'm building a matching one. I'll run both tests with and without the fix, and keep this PR in draft until they pass. AI assistance (Claude Code) was used to investigate and write this change. I've reviewed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: sampan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>


Description
This PR integrates the push-based model for the streaming split operator, introduced in this stack of PRs (#66465, #66466), with Ray Data lineage reconstruction. As a result, this integrates the new streaming model for Ray Train with Ray Data's lineage reconstruction, to improve fault tolerance for streaming ingest.
How it works
We introduce the notion of "external consumer tasks" to represent tasks that consume output blocks produced by the final operator in a Ray Data dataset. Then, we track the lineage of external consumer tasks for the push-based streaming_split, as the first implementation of this interface.
An external consumer takes outputs from the executor and consumes them in tasks that are submitted and monitored outside the executor's thread, such as the push-based split delivering blocks to train workers. The consumer reports each task's submission and outcome from its own threads. The executor applies those reports to the lineage tracker once per scheduling step, on its own thread, which is the only thread that touches the tracker.
1. Block delivered path (push succeeded)
Each external task is registered with the lineage tracker as a child of the tasks that produced its blocks. A completed external task produces nothing, so the lineage tracker garbage collects the metadata associated with its lineage at completion.

2. Block lost path (push failed)
If, during streaming ingest, an input was lost, it is the target of a reconstruction plan like a task inside the executor that hit a lost object. Only the blocks it consumed are re-produced. Reconstruction work, which includes re-submitting the seed tasks, queueing blocks downstream, and pruning extra blocks takes place just as it would with regular lineage reconstruction for regular, non-external tasks. An external consumer task's lineage is not garbage constructible while a fresh attempt or a reconstruction attempt is still under progress.
If some external task never completes its consumption, the lineage of its input blocks stays live until the executor shuts down. That includes the lineage of an output that a finished split took but failed to submit an external task to track, and of an abandoned task, which never completes.
Additional information
register_task_complete(..., num_outputs=0), so no new tracker API is added.RAY_DATA_PUSH_SPLIT_TRACK_PUSHES=0pushes without tracking, as [data][train][2/n] Push-based streaming_split: pushers, iterator, Ray Train integration, release tests #66466 did, and those pushes aren't covered by lineage reconstruction.pytest python/ray/data/tests/unit/test_lineage_tracker_*.py python/ray/data/tests/unit/test_external_consumer_tasks.pypasses (103 tests).