Skip to content

[Data] (Data Fault Tolerance 4/n) Integrate data lineage tracker with streaming executor - #66220

Merged
goutamvenkat-anyscale merged 47 commits into
ray-project:masterfrom
ayushk7102:data_lineage_integration
Oct 10, 2026
Merged

goutamvenkat-anyscale merged 47 commits into
ray-project:masterfrom
ayushk7102:data_lineage_integration

Conversation

@ayushk7102

@ayushk7102 ayushk7102 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Note: By default the changes introduced in this PR are a no-op in Ray Data. Data lineage reconstruction is enabled only when the job turns off Ray Core lineage reconstruction via the JobConfig (JobConfig(_disable_job_level_lineage_reconstruction=True), #65487)

This PR wires the lineage tracker introduced in #65519 and developed to support fan-in and fan-out tasks in #65642, #66136.

This is a part of a larger effort to introduce lineage reconstruction as a first class construct in Ray Data for application-level fault tolerance. A more detailed proposal can be found on this Ray Enhancement Proposal (ray-project/enhancements#74)

A task serves at most one reconstruction plan here; batching several plans onto one seed re-execution is a follow-up PR.

Additional Information

I've broken down the changes introduced in this PR at a higher level below.

Concepts

This is a representation of block lineage and how it dictates which tasks need to be submitted for reconstruction.

lineage_diagram

As seen in the sketch above, lineage for a fan-out pipeline results in certain blocks being pruned as they are not required to reconstruct the lost object(s). Conversely, fan-in pipelines require a number of ancestor blocks to be reconstructed. This has a direct impact on the number of re-submitted tasks with Data lineage reconstruction.

At a high level, the sketch below shows that lineage reconstruction and regular Ray Data task execution run in tandem during a pipeline. The main ideas to grasp are the following:

  • Blocks that are emitted by reconstruction tasks that are NOT part of a lost block's lineage are pruned, or NOT propagated downstream
  • Blocks produced by reconstruction tasks that are part of a lost block's lineage are withheld in a separate data structure (while accounting for their resource usage). When all reconstruction blocks in a dependency set are ready, they are bundled and added to the operator outqueue for a child reconstruction task to consume
fan_in_fan_out_LR

Building the lineage graph while the dataset executes

  1. A LineageTracker instance is declared for the DAG's streaming executor
  2. An operator that reads directly from an InputDataBuffer is a 'seed' operator. Its input is durable and resubmittable (a ReadTask/FileManifest, or the data itself for from_*), so it retains that bundle in a map in case it ever needs to re-submit seed tasks. The tracker stores IDs, never actual RefBundles.
  3. On task submission:MapOperator._submit_data_task registers any task to be submitted with the LineageTracker, keeping track of whether it's a fresh task or a reconstruction task, and assigning it a logical Ray Data task ID
    • A producing task registers each block that is produced with the LineageTracker, via _output_ready_callback. Specifically, a tuple of (producing task logical ID, output index). A consuming task during submission time (3.) looks up the above dependencies to add edges in the lineage graph
  4. On task completion: The LineageTracker marks the task in the graph as complete.

Triggering lineage reconstruction when any output block is lost

  1. The callback DataOpTask.on_data_ready catches an ObjectLostError, and triggers data lineage reconstruction
  2. The LineageTracker traces the lost object's lineage, back to its seed task, and opens a reconstruction plan for it (or folds to an existing plan, if already open)
  3. The streaming executor aborts the lost task so its operator releases resources, these will be requested again by the triggered reconstruction tasks
  4. The streaming executor also clears the completion state for the DAG (if necessary), and re-submits the seed task.

Managing reconstructed blocks

  1. As each reconstruction task emits blocks, check the reuse status of each block. NEW flows downstream as usual, PRUNED/UNRELATED is dropped these are not required to reconstruct lost objects, and REUSED is
    withheld so that it can be passed along to following reconstruction tasks
  2. For a fan-in, the withheld objects must be released together, so that a downstream reconstruction task can accept inputs exactly as in its original attempt (maintaining the same order of blocks)

Known Limitations in Current Implementation

  • No batching of seed tasks (if multiple reconstruction plans can be served by a single seed task). This is explicitly addressed in a follow up PR to enable batching of reconstruction plans.
  • Blocks lost after they're handed to an iterator (iter_batches, iter_rows, take, take_all) aren't reconstructed. This is going to be addressed as part of a follow up effort to integrate external consumers (e.g. Ray Train) with Data FT
  • No support for DAGs with shuffles. Lineage reconstruction for pipelines with AllToAllOperator / shuffles in the DAG needs to be scoped. We will work on this in the future.

ayushk7102 and others added 9 commits September 21, 2026 16:26
…t lineage

Wires the lineage tracker into the streaming executor so a lost task output is
reconstructed from its lineage instead of failing the dataset. An
`ObjectLostError` on a tracked task walks that task's ancestry back to its seed
tasks and re-injects their retained inputs; re-produced outputs are classified
per plan as they are generated, so pruned ones are dropped rather than
re-emitted and the output row set stays exact.

Opt-in behind `DataContext.enable_seed_input_lineage_recovery` (default off), so
this is a no-op unless the flag is set.

A task serves at most one reconstruction plan here; batching several plans onto
one seed re-execution is a follow-up.

Signed-off-by: Ayush Kumar <[email protected]>
Signed-off-by: Ayush Kumar <[email protected]>
@ayushk7102
ayushk7102 force-pushed the data_lineage_integration branch from 4f6d837 to 742cfa9 Compare September 21, 2026 23:29
@ayushk7102 ayushk7102 changed the title (Data Fault Tolerance 4/n) Integrate data lineage tracker with streaming executor [Data] (Data Fault Tolerance 4/n) Integrate data lineage tracker with streaming executor Sep 21, 2026
@ayushk7102
ayushk7102 marked this pull request as ready for review September 22, 2026 04:02
@ayushk7102
ayushk7102 requested a review from a team as a code owner September 22, 2026 04:02

@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 introduces experimental object-loss lineage recovery for Ray Data, integrating a new LineageTracker to record task lineage and coordinate task reconstruction plans upon encountering ObjectLostError. The changes span the streaming executor, physical operators, and metadata fetchers, and are accompanied by a comprehensive suite of integration tests. The review comments identify three critical issues in the recovery logic: a potential deadlock in _clear_downstream_completion_state on multi-input operators due to blindly resetting input completion states, a potential deadlock in fan-out scenarios where parent block outputs are prematurely popped from the held reconstruction dictionary, and a potential AttributeError when calling stamp_seed_reinjection on non-map seed operators.

@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.

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Sep 22, 2026

@Kunchd Kunchd 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.

Thanks for the followup PR! I left some clarifying questions for how the tracker fits into ray data. The logic for how the lineage tracker is used looks good, but we definitely should have another Data member review the actual integration itself to make sure we're invoking the lineage tracker registrations at all the necessary locations.

Comment on lines +119 to +120
Record which task produced a block, so that whichever task later
consumes it can declare the dependency.

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.

Suggested change
Record which task produced a block, so that whichever task later
consumes it can declare the dependency.
Record which task produced a block, so that whichever task later
consumes it can fetch the dependency easily with the block_id.

the executor thread, where an exception tears down the whole dataset.
"""
if not isinstance(task, DataOpTask) or task.data_task_id is None:
logger.info(

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.

Probably want to log this at warning level.

)
return False

# A reconstruction that re-fails stays in the plan it serves; a fresh failure

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.

Suggested change
# A reconstruction that re-fails stays in the plan it serves; a fresh failure
# A retry of a failed reconstruction attempt stays in the plan it serves; a fresh failure

"registered with the lineage graph; cannot recover.",
task.data_task_id,
state.op.name,
)

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: instead of logging the error here, we should add this message as part of the error message we throw and propagate it up so the user layer can see reconstruction was triggered but failed. This will help them help us by providing better failed traces.

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.

Adding a LineageReconstructionError which will represent any errors caught during lineage reconstruction. This will subclass ObjectLostError and will carry the original task failure reason as well, so that we can surface more information about the failed task and reconstruction attempt


seed_task_ids = sorted(traced_seed_ids)

if not seed_task_ids:

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.

In what cases is the seed_task_ids empty? is this expected?

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.

Traced the code here and I realize this is not possible. The only way we can come across empty list of seed tasks if the sed task was not registered, but this is not possible as we would have raised a ValueError above when we start the walk to the seed op.

"[lineage-recovery] No retained input for seed task %s; cannot "
"recover.",
seed_id,
)

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.

Same here, please propagate this as error message upwards.

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.

Removing this as it's not possible to reach this state as mentioned above

InputDataBuffer,
)

return any(isinstance(dep, InputDataBuffer) for dep in self.input_dependencies)

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.

Why any() here? Is it possible for only some of the input dependencies to but InputDataBuffer?

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.

Good catch. Since map_operator is a OneToOneOperator it will only have a single input dependency and this can become

return isinstance(self.input_dependency, InputDataBuffer)

Comment on lines +844 to +848
Addressed to the consumer that owns the child rather than broadcast to every
output dependency. No adjacent consumer owning it means some non-map operator
sits between them: there is nobody to carry the identity to, and the bundle is
submitted as ordinary work. Warned about rather than raised: the rows still
flow.

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: Could we rephrase this, I couldn't quite understand what it was saying.

@ayushk7102 ayushk7102 Sep 23, 2026 •

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.

Basically, we need to store a mapping between the input bundle and the (child_task_ID, plan_ID) so that the child operator can identify which task ID to assign the reconstruction task, and what plan it belongs to.

Rephrased it as follows:

        """Store a mapping of the input bundle to the (child task, plan ID) it belongs to.

        The bundle travels downstream through the normal output queue, and the child op
        needs to the original child task ID and plan ID for scheduling it as a reconstruction task.
        When that operator submits a task for these blocks, it reuses the child's
        original id, so the lineage tracker sees the plan's re-execution rather than
        a new task.
       """"

# set is in hand synchronously -- see `_release_reconstruction_children`.
self._reconstruction_outputs: Dict[
PlanId, Dict[ParentBlockOutput, RefBundle]
] = {}

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.

We only keep track of the task submission at the map_operator level. Are all the operator we want to target in our initial pass (streaming execution) an implementation of the map_operator?

@ayushk7102 ayushk7102 Sep 23, 2026 •

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.

Discussed offline, for our v1, we only want to support DAGs which are composed with non-shuffle operators. map_operator should cover all operator types except Aggregate, Join, Count, Mix, Union and a few others which we want to address with shuffle work

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.

Also, in the interim, we are going to explicitly disable data LR on DAGs where these operators are found.

@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.

Stale Bugbot comment from a previous run.

…ued_block() on lineage tracker

Signed-off-by: Ayush Kumar <[email protected]>

@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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

seed_op.name,
seed_input.size_bytes(),
reconstruction_plan_id,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reconstruction retries have no bound

High Severity

_reconstruct_lost_object re-injects the stored seed RefBundle on every ObjectLostError with no attempt limit. For from_* and materialized sources the seed input is the data, so a lost source object is re-submitted unchanged, fails again, and the executor resubmits forever.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8aaddd5. Configure here.

except LineageReconstructionError as recon_error:
# In case lineage reconstruction fails, abort the task
task.mark_aborted(recon_error)
_record_errored_block(recon_error, state.op.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fetcher loss skips reconstruction

Medium Severity

ObjectLostError from the threaded metadata fetcher is routed through _record_errored_block instead of _reconstruct_lost_object. The lost block is dropped and counted as an error, so lineage reconstruction never runs for objects that disappear after they are deferred.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8aaddd5. Configure here.

@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.

Stale Bugbot comment from a previous run.

…ructionMixin for extensibility

Signed-off-by: Ayush Kumar <[email protected]>

@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 and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 999d41a. Configure here.

lineage_tracker: "LineageTracker",
task_index: int,
inputs: RefBundle,
) -> Tuple[LineageTaskId, Optional[ReconstructionPlanId], List[ParentBlockOutput]]:

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.

Let's make this a dataclass

@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 5d54e14 into ray-project:master Oct 10, 2026
6 checks passed
iamjustinhsu pushed a commit that referenced this pull request Oct 29, 2026
… Data lineage reconstruction (#66990)

## Description

When several tracked tasks lose their output, each failure opens its own
reconstruction plan. If those plans trace back to the same task, today
each one re-injects the seed separately, so the read runs once per plan.
So does every downstream task that the plan shared. That is a lot of
redundant work during reconstruction.

Let's say there are two different downstream objects that are lost
independently, which result in two separate reconstruction plans A and
B. Let's also say that both plans A and B trace back to the same seed
task (say T). With the changes from this PR, we should now only
re-submit the seed task T once for both plans. This "batching" can be
done by noticing that the traced seed task for a plan is already queued
for submission (but not submitted yet), and simply joining on to the
same seed task. By updating the lineage tracking metadata, we can use
the same seed to emit block outputs required for multiple different
reconstruction plans at the same time.

The `LineageTracker` API is unchanged. Batching is purely an
optimization. If a plan can't be batched, behavior is exactly what it
was before, with the task re-run for that plan. We can only batch
reconstruction plans with a queued task because if it is submitted, it's
likely that it is too late, and the required output block for the second
plan has already been dropped due to being `OBJECT_PRUNED` at the time.



**Limitations:**
- Joining depends on timing. It only happens if the second failure is
processed before the seed's re-execution is dispatched.

## Related issues

Optimization on top of the Ray Data integration with lineage tracker API
first started in #66220

## Additional information

 ### Tests

  ```
  conda run -n ray_env pytest
  python/ray/data/tests/test_lineage_reconstruction.py \
    python/ray/data/tests/test_ref_bundle.py \
    python/ray/data/tests/unit/test_lineage_tracker_linear.py \
    python/ray/data/tests/unit/test_lineage_tracker_fan_out.py \
    python/ray/data/tests/unit/test_lineage_tracker_fan_in.py -q
  117 passed
  ```


  New or updated tests in `test_lineage_reconstruction.py`:
-
`test_losses_before_the_seed_is_submitted_share_one_reconstruction_task`:
two real losses through `_reconstruct_lost_object` re-inject the seed
once, and the one run serves both plans, holding and releasing outputs
correctly for each.
- `test_joined_plans_sharing_a_child_release_it_once`: a child both
plans need is released once, stamped with both plans, and runs once.
- `test_shared_child_is_batched_until_it_is_submitted`: a plan joins a
queued child, or re-runs it if the child was already submitted.
- `test_seed_targeted_by_one_plan_and_reused_by_another`: one run serves
a plan it is the target of and a plan it is an intermediate of.
-
`test_loss_after_the_seed_reconstruction_task_is_submitted_re_injects_the_seed`:
a new plan due to a object loss after another plan's submission can no
longer join it, and rather is re-submitted as a new plan

---------

Signed-off-by: Ayush Kumar <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
richardliaw pushed a commit that referenced this pull request Nov 20, 2026
…ng executor integration tests to prevent flakiness (#68049)

## Description
This PR rewrites all of the integration tests for lineage reconstruction
as well as some unit tests, to fix flakiness in the test suite.

### Why
`test_lineage_reconstruction` was flaky in CI. This is because several
tests simulated a lost block with a `lose_output` fixture that
monkeypatched `DataOpTask.on_data_ready` to raise `ObjectLostError` on
the Nth time the executor polled a given task. The problem is that the
number of polls it takes to drain a task is non-deterministic. It
depends on whether metadata is fetched on a background thread or inline,
and on how fast tasks are submitted and finish. the task drained before
the Nth poll, so the loss never fired and an assertion based on the
number of reconstructions failed.

### Integration test changes
Rather than relying on executor poll timing/task completion time, we now
encode a failure into the data itself (i.e. a particular row will tell
the UDF to mock a lost block). A `map_batches` UDF raises
`ObjectLostError` when it sees a specific row, and the executor handles
that exactly like a block lost with its node. The end-to-end tests then
check that the loss actually happened, and every row comes back exactly
once. They cover linear, fan-in, fan-out, multi-operator, actor pool and
write pipelines, plus a block that's lost a second time while it's being
reconstructed.

### Unit test changes
I reworked all of the old lineage reconstruction unit tests that are
specific to the integration with the streaming executor. The purely unit
tests that don't need a Ray cluster moved to
`tests/unit/test_lineage_reconstruction_executor.py`.

No production code changes.

## Related issues
Related to #66220 and #66990.

## Additional information
I checked open PRs and nothing else rewrites these tests. #67366, #67885
and #68042 add tests to the same file, so whichever of us lands second
will need to rebase.

Testing: I ran the unit tests 30 times and the integration tests 6 times
(3 with the threaded metadata fetcher, 3 with the inline one).
Everything passed every time.

---------

Signed-off-by: Ayush Kumar <[email protected]>
iamjustinhsu added a commit that referenced this pull request Nov 20, 2026
12/n stopped Ray Core from restarting actor-only actors. A dead
actor is released and the sizer replaces it, so its lost work, and any
blocks lost with a node, have to be rebuilt by Ray Data lineage
reconstruction (#66220). This PR wires that into the
actor-only backend.

**Recovery routing**
- On a lineage-tracked task, `RayActorError` (the actor died) now goes
to lineage reconstruction, like `ObjectLostError`. That applies in both
the default executor loop and the actor-only loop, through one shared
`recover_or_count_lost_output` helper. `ActorUnavailableError` does not.
- Deferred metadata-fetch failures go through the same routing. The
fetcher now reports the failed task instead of its operator name.
- The actor-only backend refuses to start when the job has Data
reconstruction off
(`JobConfig(_disable_job_level_lineage_reconstruction=True)` not set),
because nothing else can recover a node loss. Plans #66220 can't
reconstruct (split, union, mix, limit) still run, with reconstruction
off for that dataset.

**ResourceBank accounting**
- During reconstruction, a re-made block is withheld until its child's
whole input set is back. Withheld blocks are now charged to the
producing actor, and also counted as withheld, so they can be told apart
from output a consumer can drain. Release, a displaced copy, and
`clear_internal_output_queue` each undo the charge.
- A released input set goes into the output queue under the producing
actor's key (`_output_add_kwargs`), not the task index.

**Escape hatch for withheld-block wedges**
- An actor is wedged when its pull budget is exhausted only because of
blocks it is withholding. Nothing downstream can drain those blocks
until the set is complete, so it would stall forever.
- `relieve_withheld_wedges` runs before the existing output-limit walk.
It gives a wedged actor room for what it withholds plus one block:
1. free object store on its node, reserved in the bank so no other grant
counts it again;
2. then unused budget lent by other actors on the same node, whose caps
go down by the same amount;
3. if that's not enough, it waits while those actors' full budgets would
cover the rest once their outputs are consumed, and only oversubscribes
beyond that.
- Grants are kept on the actor and given back once its withheld outputs
are released, or when it dies (lenders get their budget back).
- The existing output-limit hatch now uses the same reservation and
borrowing. It still grants its one-block bump immediately when there's
no room.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
Co-authored-by: sampan <[email protected]>
Co-authored-by: Prasad Palkar <[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.

4 participants