Skip to content

[Data] Trigger Data lineage reconstruction on RayActorError and RayTaskError - #67885

Closed
ayushk7102 wants to merge 1 commit into
ray-project:masterfrom
ayushk7102:catch_actor_error_data_ft
Closed

ayushk7102 wants to merge 1 commit into
ray-project:masterfrom
ayushk7102:catch_actor_error_data_ft

Conversation

@ayushk7102

@ayushk7102 ayushk7102 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Ray Data lineage reconstruction now recovers a task whose body failed because an actor it called died, not just a task whose output object was lost. The motivating case is a parquet datasource V2 read whose FooterReader actor dies while ListFiles is running. More info in this issue: #67886

For the above ListFiles issue, fixing it with this PR depends on #67882. Without it, an ActorDiedError raised inside a map task reaches the driver as UnserializableException and can't be matched.

Before

When a lineage-tracked task fails, the error decides whether Ray Data reconstructs it:

Error from the task What happens
ObjectLostError Reconstruction: the task's seed input is resubmitted
RayTaskError(ActorDiedError) (the task called an actor whose process died) Task drained, counted as an errored block, dataset fails
RayTaskError(ActorUnavailableError) (the task called an actor whose node died) Task drained, counted as an errored block, dataset fails
Bare RayActorError (the actor running the task died) Left to Ray Core actor restarts and task retries
Anything else Task drained, counted as an errored block

Ray Core doesn't retry the two RayTaskError(...) cases either, because only RaySystemError is in Data's retry_exceptions. So a task that failed only because an actor it depends on died can't be recovered, even when its seed input is retained.

After

Error from the task What happens
ObjectLostError Reconstruction (unchanged)
RayTaskError(ActorDiedError) Reconstruction
RayTaskError(ActorUnavailableError) Reconstruction
Bare RayActorError Unchanged, left to Ray Core
Anything else Unchanged, counted as an errored block
  • New is_data_lineage_recoverable_error in lineage_reconstruction_mixin.py encodes the table: an ObjectLostError, or a RayTaskError that is also a RayActorError. ActorUnavailableError is included because the task body has already raised, so nothing is left to wait for.
  • DataOpTask.on_data_ready and process_completed_tasks use it to route matching errors into _reconstruct_lost_object.
  • LineageReconstructionError can wrap an error without object fields, so a failed reconstruction of an actor error is reported instead of raising AttributeError.

Subsystems

Execution (interfaces/physical_operator.py, operators/lineage_reconstruction_mixin.py, streaming_executor_state.py). ray/data/exceptions.py has a small ripple change so LineageReconstructionError accepts errors without object fields.

Testing

  • pytest python/ray/data/tests/test_lineage_reconstruction.py: 38 passed. New tests:
    • test_is_data_lineage_recoverable_error (lost object, nested ActorDiedError and ActorUnavailableError, bare ActorDiedError, nested ValueError).
    • test_actor_died_in_task_raises_only_when_lineage_tracked.
    • test_reconstruction_error_wraps_actor_error.
  • End to end, on a local 4-node cluster with Data reconstruction on, a 96-file V2 parquet read with slowed footer reads, stacked on the dependency PR:
    • SIGKILL one FooterReader process mid-listing: 1 reconstruction, ListFiles ran twice, all 24576 rows exactly once.
    • Kill the node hosting a FooterReader mid-listing: 2 reconstructions, ListFiles ran 3 times, all rows exactly once. The first rerun placed a new FooterReader on the killed node before the GCS marked it dead, and the second reconstruction recovered from that.
    • Before this change, both scenarios failed the dataset with no reconstruction.

Known limitation (follow-up)

A rerun of the target task skips outputs already emitted by position. FooterReader.read_footers yields footers in completion order within a batch, so a ListFiles rerun can order its output differently. If manifests were already emitted before the failure, this could drop or duplicate files. It isn't ruled out by the runs above. The follow-up is to make footer reads ordered whenever lineage reconstruction is on.

Notes

  • Not a duplicate. I searched open and closed PRs in this repo for is_data_lineage_recoverable_error and for RayActorError lineage reconstruction and found none.
  • AI assistance (Claude Code) was used to investigate and draft this change. I reviewed every changed line and ran the tests above.

@ayushk7102
ayushk7102 requested a review from a team as a code owner November 6, 2026 03:22

@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 extends lineage reconstruction in Ray Data to recover from tasks that fail due to actor deaths (i.e., RayActorError wrapped in RayTaskError) in addition to standard ObjectLostErrors. It introduces the is_data_lineage_recoverable_error helper function, updates the streaming executor and physical operators to handle these recoverable errors, and adapts LineageReconstructionError to safely wrap general exceptions. Comprehensive unit tests have been added to validate these changes. I have no feedback to provide as there are no review comments.

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

from a high level perspective, shouldn't the operator spinning the "actor pool/actor" retry at the failed actor level?
in this case, is it not possible for list files to catch that a particular actor it spun died and retry the work for that actor rather than LR getting triggered resubmitting the entire ListFiles task?
also my understanding was that lineage reconstruction would get triggered in cases when an input object is lost to rebuild the lost objects vs here it feels like we are substituting retries of a failed actor with lineage reconstruction.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Nov 6, 2026

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

also I agree with @NightWing1998 comment. we can modify the list files task to handle fault tolerance internally or make it return a lineage reconstructable exception (we can consider introducing a new dedicated exception type for this but I dont really like this idea)

"""
if isinstance(error, ObjectLostError):
return True
return isinstance(error, RayTaskError) and isinstance(error, RayActorError)

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 should not trigger lineage reconstruction for TaskErrors right? this could end up behaving as a retry mechanism instead of a FT mechanism for node deaths and object losses.

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.

also ActorUnavailableError is retried by ray core so we should exclude it from lineage reconstruction

remaining_output_budget[state] - bytes_read, 0
)
except ObjectLostError as e:
except (ObjectLostError, RayActorError) as e:

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: lets accept all exceptions here and if its not lineage reconstructable we can record it as an errored block. this was is_data_lineage_recoverable_error() will become the central check for lineage recoverable error types.

@ayushk7102

ayushk7102 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Changed the approach given feedback. We will now rely on #67988, with Ray Core to handle the restarts/retries for FooterReader actor deaths/failures, which I think is more idiomatic and allows lineage reconstruction to focus on object reconstruction rather than task/actor failures

@ayushk7102
ayushk7102 deleted the catch_actor_error_data_ft branch November 10, 2026 23:18
goutamvenkat-anyscale pushed a commit that referenced this pull request Nov 19, 2026
…s in listing order (#67988)

## Summary
This PR turns on Ray Core restarts and task retries for
`FooterReaderActor`, so a footer-reader process or node death no longer
fails the Datasource v2 (DSv2) Parquet `ListFiles` task. Retries are
only exactly-once if `read_footers` yields the same file at each
position on every attempt, so it now always yields in listing order.

Fixes #67886, an issue that on
a `FooterReaderActor` death in the ListFiles task, datasets would simply
fail, which made file listing not fault tolerant. Initially, I wanted to
solve this problem by [triggering data lineage reconstruction on these
errors](#67885), but we would
have to expand the errors we trigger LR for. Also this would re-submit
the listing task from the start, and would substitute actor-level
retries with block reconstruction. A good Ray/Ray-Data pattern is that
the owner of the actor pool should handle its failures.

## Before
- `FooterReaderActor` used Core defaults: no restarts and no task
retries. If a `FooterReader` died mid-listing, `ListFiles` raised
`RayTaskError(ActorDiedError)` (process death) or
`RayTaskError(ActorUnavailableError)` (node death), and the dataset
failed.
- `read_footers` yielded footers in completion order (`as_completed`)
unless `preserve_order=True`. That made its output depend on IO timing,
so enabling Core retries alone would be wrong. Core matches a retried
streaming generator's items to the first attempt's by position
(`ObjectRefStream::InsertToStream` drops an index below the consumer's
cursor). A retry that finishes footers in a different order would then
silently drop some files and duplicate others, and the row count would
still look right. With the old ordering, a standalone repro (an actor
with Core retries, SIGKILLed after delivering 6 of 20 files) dropped and
duplicated 3–6 files in 10/10 trials with `preserve_order=False`, and
0/10 with `preserve_order=True`.

## After
- `FooterReaderActor = ray.remote(max_restarts=-1,
max_task_retries=-1)(FooterReader)`. A dead actor restarts, and its
in-flight `read_footers` calls are retried. Python exceptions such as IO
errors are still not retried and fail as before.
- `read_footers` always yields in `files` order. The `preserve_order`
argument and the `as_completed` branch are removed, along with the
now-unused plumbing in `FooterFileIndexer._process_file_infos` /
`_read_footers`. The public `list_files*` signatures are unchanged
because the `FileIndexer` interface requires them.
- This follows the existing Ray Data pattern: `ActorPoolMapOperator`
actors use `max_restarts=-1, max_task_retries=-1` with streaming
`submit`, and work done concurrently inside one call is always put back
in input order (async UDFs in `plan_udf_map_op.py`, `ReadFiles` in
`datasource_v2/common/file_reader.py`), regardless of `preserve_order`.
- User-facing `DataContext.execution_options.preserve_order` is
unchanged everywhere else, including path discovery in
`NonSamplingFileIndexer`, operator output queues, `streaming_split` and
union.

```mermaid
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: IO]
            subgraph BC[Component: DSv2 Parquet listing / ListFiles task]
                B1[FooterFileIndexer._read_footers] --> B2["FooterReaderActor<br/>no restarts, no task retries"]
                B2 --> B3["read_footers<br/>completion order unless preserve_order"]
                B2 -. actor dies .-> B4[ListFiles fails, dataset fails]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: IO]
            subgraph AC[Component: DSv2 Parquet listing / ListFiles task]
                A1[FooterFileIndexer._read_footers] --> A2["FooterReaderActor<br/>max_restarts=-1, max_task_retries=-1"]
                A2 --> A3["read_footers<br/>always listing order"]
                A2 -. actor dies .-> A4[Core restarts actor and retries call, exactly-once]
            end
        end
    end
    Before ~~~ After
    classDef removed fill:#ffcdd2,stroke:#c62828,color:#000
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class B4 removed
    class A2,A3 changed
    class A4 added
```

## Benchmarks to measure perf overhead

**Summary:** On realistic workloads, yielding footers in listing order
costs nothing measurable on full reads, batch inference or total job
time. The one consistent cost is a few hundred milliseconds per read
when a `limit` is pushed down into listing: +0.38s at the default footer
batch size, levelling off at about +0.7s for larger batch sizes. The
cost doesn't grow with job length.

### Why the cost is capped

`FooterFileIndexer._read_footers` already drains footer batches in FIFO
order (10 files per batch by default), and each batch only drains once
its slowest footer has landed. This PR only changes when files *inside*
a batch are released. A file can now wait for an earlier, slower footer
in the same batch, but every batch still drains at the same time as
before. So each file is delayed by at most one batch's slowest-footer
time, and the delay doesn't carry over to later batches. The cost shows
up when listing stops early (a pushed-down `limit`) or when the dataset
is a single batch.

### Setup

- Release tests were run unmodified, with their release config's
cluster, data and env vars, over 3 paired rounds (master and PR
concurrently). Footer latency comes from S3, with no injected delays.

### Release tests (default settings)

| Release test | Cluster | Master (mean of 3) | PR (mean of 3) | Δ |
|---|---|---|---|---|
| `read_parquet_fixed_size` | 4× m5.8xlarge | 134.7s | 134.4s | −0.2%
(noise) |
| `read_large_parquet_fixed_size` | 4× m5.8xlarge | 530.3s | 530.5s |
0.0% |
| `image_classification_from_parquet_fixed_size` | 10× g4dn.2xlarge |
209.0s | 208.1s | −0.4% (noise) |
| `training_ingest_benchmark` (`s3_parquet_cpu`), job total | 1×
r8i.16xlarge | 891.3s | 890.0s | −0.1% |
| ↳ per `limit(1024)` iteration (12 configs) | | 12.90s | 13.28s |
**+0.38s (+2.9%)** |

### Footer batch size sweep (`training_ingest_benchmark`,
`RAY_DATA_PARQUET_FOOTER_BATCH_SIZE`)

| Footer batch size | `limit(1024)` iteration Δ (~12.8s) | Configs
slower on PR | `limit(8192)` iteration Δ (~60s) | Job total Δ (~15 min)
|
|---|---|---|---|---|
| 10 (default) | +0.38s (+2.9%) | 9/12 | noise | −0.1% |
| 30 | +0.55s (+4.3%) | 11/12 | noise | +1.1% |
| 100 | +0.71s (+5.6%) | 11/12 | +1.2% | +2.0% |
| 300 | +0.68s (+5.4%) | 12/12 | noise | +1.0% |

### Constructed worst case (for scale, not representative)

Ten files, a single footer batch: the first file in listing order has a
slow footer (150k tiny row groups, pruned by the filter), followed by
nine 144 MB compacted files with heavy `map_batches` work. One node,
default settings.

| | Master | PR | Δ |
|---|---|---|---|
| Time to first batch | 13.1s | 21.3s | +8s |
| End to end | 31.4s | 39.0s | +7.5s (+24%) |

### Findings

1. **No measurable cost on full reads or batch inference.** All
release-test deltas are within run-to-run noise.
2. **Pushed-down `limit` pays a small fixed cost per read.** Master
stops listing on whichever footers land first, while this PR waits for
the first files in listing order. That's +0.38s per `limit(1024)` read
at the default batch size. It's visible on 12s iterations and lost in
noise on 60s ones.
3. **Larger footer batches raise that cost, but it levels off at about
0.7s.** A bigger batch gives master more fast footers to stop on, until
the batch holds more files than the limit needs. Total job time stays
within about 2% at every batch size tested.
4. **Large regressions need a contrived layout.** A slow-footer file at
the head of a single-batch dataset with heavy downstream work costs
about one slow-footer latency (+24% on a ~30s job). That cost shrinks as
the dataset spans more batches.
5. **In exchange,** footer-reader actor deaths no longer fail the
dataset, and the files a pushed-down `limit` reads no longer depend on
IO timing.


## Subsystems
IO (`_internal/datasource_v2/formats/parquet/`)

## Testing
- New
`test_footer_chunking.py::test_read_footers_actor_returns_all_file_chunks_after_actor_death`.
It calls `read_footers` on a real `FooterReaderActor` with
`_generator_backpressure_num_objects=1`, so the actor can run at most
one result ahead of the caller.
`test_generators.py::test_streaming_generator_actor_restarted_before_first_completion`
uses the same option for the same reason. The test SIGKILLs the actor
after the caller has consumed the first result, keeps reading the same
generator, and asserts that every file arrives once in listing order and
that the row-group rows sum to all 1200 rows. The last result can only
come from the retried call, and the retry was logged in 3/3 runs.
- With `max_task_retries=0` (restarts still on), the test fails with
`ActorUnavailableError`.
- With `as_completed` restored in `read_footers`, it failed in 2 of 3
runs, because local completion order is random. The deterministic check
for ordering is `test_footer_reader.py::test_yields_in_listing_order`,
which yields under reversed completion order without Ray.
- `test_parquet_datasource_v2.py`: the fake actor no longer takes
`preserve_order`, and
`test_footer_indexer_forwards_preserve_order_to_footer_reads` is removed
because the plumbing it checked no longer exists.
`test_footer_indexer_preserves_listing_order_across_batches` still
checks that the driver drains batches in order.
- `conda run -n ray_env pytest
python/ray/data/tests/datasource_v2/test_footer_chunking.py
python/ray/data/tests/datasource_v2/test_footer_reader.py
python/ray/data/tests/unit/datasource_v2/`: 841 passed, 93 skipped.
- `conda run -n ray_env pytest
python/ray/data/tests/datasource/test_read_parquet_v2.py`: passes except
`test_read_parquet_v2_retries_transient_filesystem_errors`, which fails
identically on unmodified master locally (`ModuleNotFoundError: No
module named 'test_read_parquet_v2'` when workers unpickle the test's
filesystem handler). Not related to this change.
- `pre-commit run` on the changed files: passes.

## Notes
- Not a duplicate: searched open PRs for `FooterReader` and
footer-reader actor retries. The only related one is #67885 (mine),
which this replaces.
- AI assistance (Claude Code) was used to investigate, implement and
benchmark this change. I reviewed every changed line and ran the tests
above.

---------

Signed-off-by: Ayush Kumar <[email protected]>
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]>
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.

3 participants