Skip to content

[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

Merged
iamjustinhsu merged 11 commits into
ray-project:masterfrom
ayushk7102:data_lr_retrace_pending_reconstruction_task
Nov 21, 2026

Conversation

@ayushk7102

@ayushk7102 ayushk7102 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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:

ValueError: Task ... was submitted for plan ... with input ChildBlockDependency(...) from parent ..., but that block was never queued for the plan.

The bug

Take a small pipeline. A seed A feeds B, B fans out to C1 and C2, and both feed D. In the pictures, a thick edge is a block the reconstruction plan still needs from that parent.

0. D loses its output. That starts reconstruction plan P. The tracker walks back to A, re-runs it, and B, C1 and C2 are rebuilt for P.

retrace_step_0

1. C1 loses its input. The tracker walks back to A again and re-runs it, because B needs fresh input. So far so good.

retrace_step_1

2. A sends its block to B. The tracker crosses the A → B edge off. But B is busy, so the block sits in B's input queue for a while.

retrace_step_2

3. C2 loses its input while the block is still waiting. The tracker walks back from C2. When it gets to A, it sees the edge is crossed off and has no way to know the block is sitting in B's queue. So it puts A → B back on the list and re-runs A again.

retrace_step_3

4. B picks up the block from step 2. The tracker still has A → B on its list, so it thinks B is starting on input A never sent, and raises never queued for the plan.

retrace_step_4

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 B had already started by step 3, the same mistake shows up one step later. The extra A run feeds B again after B has already finished for the plan, and the tracker raises plan is not registered as a known reconstruction plan instead.

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 TaskNode gets one new field, plans_with_queued_reconstruction_task:

  • A plan is added when a parent adds a block to the downstream input queue (register_block_queued), and also when register_task_failed returns the task as a seed to re-run. The latter is necessary because the seed task does not have any parent to call register_block_queued for it. So we must update the state about the queued block right when inserting the input ref bundle into the source operator's queue
  • The plan is removed when the task is actually submitted for it (register_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_failed can now return no seeds. _reconstruct_lost_object logs that and returns.

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]>
@Yin-1022

Copy link
Copy Markdown
Contributor

Thanks for the fix! I ran some additional tests against this PR:

  • 72 existing lineage tracker tests passed.
  • 4 adversarial cases covering overlapping reconstruction attempts, different failure orders, and independent reconstruction plans all passed.
  • 1 additional streaming test checked the release callback timing when a new child dependency is introduced mid-reconstruction.

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.

@ayushk7102 ayushk7102 changed the title [Data] (Data fault tolerance) Stop a lineage re-trace at a pending reconstruction task [Data] (Data fault tolerance) Stop a lineage re-trace at a queued reconstruction task Nov 14, 2026
@ayushk7102
ayushk7102 marked this pull request as ready for review November 18, 2026 00:43
@ayushk7102
ayushk7102 requested a review from a team as a code owner November 18, 2026 00:43

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit b7260f9. Configure here.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Nov 18, 2026
@ayushk7102 ayushk7102 changed the title [Data] (Data fault tolerance) Stop a lineage re-trace at a queued reconstruction task [Data] (Data fault tolerance) Stop the lineage re-trace at a reconstruction task that is already waiting to be scheduled Nov 18, 2026
@ayushk7102 ayushk7102 changed the title [Data] (Data fault tolerance) Stop the lineage re-trace at a reconstruction task that is already waiting to be scheduled [Data] (Data fault tolerance) Stop the tracing back during LR at a reconstruction task that is already waiting to be scheduled Nov 18, 2026
@ayushk7102 ayushk7102 changed the title [Data] (Data fault tolerance) Stop the tracing back during LR at a reconstruction task that is already waiting to be scheduled [Data] (Data fault tolerance) Early stop the trace back to the seed task, at a reconstruction task that is already waiting to be scheduled Nov 18, 2026
@ayushk7102 ayushk7102 changed the title [Data] (Data fault tolerance) Early stop the trace back to the seed task, at a reconstruction task that is already waiting to be scheduled [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 Nov 18, 2026
…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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we want to check for null before adding to the set as reconstruction_plan_id is optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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[

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sampan-s-nayak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just one nit

@richardliaw richardliaw added the go add ONLY when ready to merge, run all tests label Nov 19, 2026
Signed-off-by: Ayush Kumar <[email protected]>
@richardliaw

Copy link
Copy Markdown
Contributor

merge conflicts

@NightWing1998 NightWing1998 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@iamjustinhsu
iamjustinhsu merged commit c3b3b2a into ray-project:master Nov 21, 2026
5 checks passed
sampan-s-nayak added a commit that referenced this pull request Nov 25, 2026
…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]>
iamjustinhsu added a commit that referenced this pull request Nov 26, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants