Repository navigation
[Data] (Data fault tolerance) Stop early from tracing back to the seed task, when a reconstruction task that is already waiting to be scheduled is found - #68094
Conversation
When a re-execution in a reconstruction plan loses its input, register_task_failed re-traces the plan up to the seed task. It did so even when a task on the path already had a reconstruction task for the plan that was queued, or submitted but not yet past the needed output. That task's input was then queued a second time for the plan, and register_task_submission raised "never queued for the plan" or "plan is not registered as a known reconstruction plan". The trace now adds the needed ChildBlockDependency to that task's plan set and stops there. The pending reconstruction task reads the plan set as it produces each output, so it re-produces the output for the new child too. The tracker learns about pending reconstruction tasks from calls the operator already makes, so no public method changes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ayush Kumar <[email protected]>
|
Thanks for the fix! I ran some additional tests against this PR:
The streaming test confirmed that late-added dependencies are handled by the task-completion release callback rather than triggering an immediate release. No correctness issues were identified in these tests. Sharing these results as additional validation while the PR is still in draft. |
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 enhances the LineageTracker to track reconstruction plans with queued but not yet submitted reconstruction tasks using a new plans_with_queued_reconstruction_task field on TaskNode. This optimization avoids redundant seed task resubmissions when pending parent reconstruction tasks are already set to re-produce the necessary inputs. Additionally, it updates the streaming executor to handle scenarios where no seed tasks are resubmitted and introduces comprehensive unit tests to validate these behaviors. As there are no review comments, I have no feedback to provide.
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 b7260f9. Configure here.
…n that was initially queued Signed-off-by: Ayush Kumar <[email protected]>
| child_task_node = self._lineage_task_id_to_task_node[ | ||
| entry.child_lineage_task_id | ||
| ] | ||
| child_task_node.plans_with_queued_reconstruction_task.add( |
There was a problem hiding this comment.
nit: do we want to check for null before adding to the set as reconstruction_plan_id is optional?
There was a problem hiding this comment.
We should return early above if reconstruction_plan_id is None https://github.com/ray-project/ray/pull/68094/changes#diff-856868c32e96b0cb096d57de9dae55aa5b290357f9a27efdbfee684938854f5eL177
| del task_node.plan_to_child_block_lineages[reconstruction_plan_id] | ||
| # The child now has queued input for the plan, so a reconstruction task of | ||
| # the child is pending for the plan. | ||
| child_task_node = self._lineage_task_id_to_task_node[ |
There was a problem hiding this comment.
could the block get queued to more than one child task node? may not happen when dealing with map operators but could be something to cover when supporting broadcast
There was a problem hiding this comment.
Currently, no operator in Ray Data queues the same block object to multiple consumer tasks. But yes, that would change when/if we support broadcasts in the future.
sampan-s-nayak
left a comment
There was a problem hiding this comment.
lgtm, just one nit
Signed-off-by: Ayush Kumar <[email protected]>
|
merge conflicts |
NightWing1998
left a comment
There was a problem hiding this comment.
nit-pick:
Near-duplicate tests repeat a long setup
The two 'resubmits the seed while a parent re-execution is submitted' tests, and the 'produced the input' test, repeat the same ~8-line setup and the same trailing split/seed assertions.
Fold the shared setup into one helper, or collapse the overlapping-submission tests into one parametrized case.
…ending_reconstruction_task Signed-off-by: Ayush Kumar <[email protected]>
…a queued reconstruction plan (could be redundant) Signed-off-by: Ayush Kumar <[email protected]>
…a queued reconstruction plan (could be redundant) Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
…com:ayushk7102/ray into data_lr_retrace_pending_reconstruction_task
…ace_pending_reconstruction_task
…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]>
…ests into jhsu/generalize-lineage-tracker-for-intermediate-available-inputs Brings master's #68094 (stop tracing at a task with a queued reconstruction task) and #68400 up from 6/n onto this branch's restart at the nearest available input. #68094's rules now apply to restart tasks, not just seeds: - register_task_failed marks every returned restart task with plans_with_queued_reconstruction_task, since a re-injected input has no parent to mark it, and can return no restart tasks. - _reconstruct_lost_object tracks the plans per restart task and joins, stamps and logs each one with only the plans whose trace returned it; with nothing to resubmit it logs and returns. Tests: #68094's fan-in tests expect the {task: input} return value, and its stamping test gives its lost task a no-op cancel callback, since losing a task now cancels it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: iamjustinhsu <[email protected]>

Description
This PR fixes a bug in Ray Data lineage reconstruction that shows up under heavy chaos, when two sibling tasks lose their input during the same reconstruction. When a reconstruction task runs, its outputs are added to the downstream operator's queue, and the lineage tracker removes that dependency from the task's record. The next task may not start right away, so the block can wait in its input queue. If a second sibling task loses its input during that time, the tracker walks back up to the seed again. It doesn't know a block is already waiting in a queue downstream, so it adds each dependency back and re-runs the seed. When the downstream task then starts on the waiting block, the tracker's record says its parent never sent it, and the assertion fails with:
The bug
Take a small pipeline. A seed
AfeedsB,Bfans out toC1andC2, and both feedD. In the pictures, a thick edge is a block the reconstruction plan still needs from that parent.0.
Dloses its output. That starts reconstruction planP. The tracker walks back toA, re-runs it, andB,C1andC2are rebuilt forP.1.
C1loses its input. The tracker walks back toAagain and re-runs it, becauseBneeds fresh input. So far so good.2.
Asends its block toB. The tracker crosses theA → Bedge off. ButBis busy, so the block sits inB's input queue for a while.3.
C2loses its input while the block is still waiting. The tracker walks back fromC2. When it gets toA, it sees the edge is crossed off and has no way to know the block is sitting inB's queue. So it putsA → Bback on the list and re-runsAagain.4.
Bpicks up the block from step 2. The tracker still hasA → Bon its list, so it thinksBis starting on inputAnever sent, and raisesnever queued for the plan.The root cause is that the tracker forgets a block as soon as it's sent, but the block can sit in the next operator's queue for a while before anything runs on it. Under chaos, operators back up, so that window gets long enough for a second sibling to fail inside it.
If
Bhad already started by step 3, the same mistake shows up one step later. The extraArun feedsBagain afterBhas already finished for the plan, and the tracker raisesplan is not registered as a known reconstruction planinstead.The fix
Track reconstruction plans waiting to be submitted
The lineage tracker now tracks when a reconstruction task's input is waiting in its operator's queue for a reconstruction plan. Each
TaskNodegets one new field,plans_with_queued_reconstruction_task:register_block_queued), and also whenregister_task_failedreturns the task as a seed to re-run. The latter is necessary because the seed task does not have any parent to callregister_block_queuedfor it. So we must update the state about the queued block right when inserting the input ref bundle into the source operator's queueregister_task_submission).Fresh tasks don't need this. They don't get a lineage task ID until they're submitted, and their blocks are never part of a reconstruction plan. The operator already makes all of these calls, so no public method changes.
Stop tracing up to the seed at a waiting reconstruction plan
The walk stops at a task that has input waiting. When a sibling fails, the tracker still adds the sibling's dependency to the waiting task, but it doesn't walk past it or re-run the seed. The waiting task hasn't started yet, so when it runs it produces the sibling's input too. This fixes the production crash.
Rows still come out exactly once. A task only gets its input as one complete bundle, and each dependency is sent once per plan.
Smaller changes
register_task_failedcan now return no seeds._reconstruct_lost_objectlogs that and returns.