Skip to content

[Data] [Data FT] Re-run lineage reconstruction tasks under their original task index - #68400

Merged
sampan-s-nayak merged 3 commits into
ray-project:masterfrom
sampan-s-nayak:data-lr-rerun-keeps-task-idx
Nov 25, 2026
Merged

sampan-s-nayak merged 3 commits into
ray-project:masterfrom
sampan-s-nayak:data-lr-rerun-keeps-task-idx

Conversation

@sampan-s-nayak

Copy link
Copy Markdown
Contributor

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.

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
Loading

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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sampan-s-nayak sampan-s-nayak changed the title [Data] (Data fault tolerance) Re-run lineage reconstruction tasks under their original task index [Data] [Data FT] Re-run lineage reconstruction tasks under their original task index Nov 20, 2026
@sampan-s-nayak
sampan-s-nayak marked this pull request as ready for review November 23, 2026 05:48
@sampan-s-nayak
sampan-s-nayak requested a review from a team as a code owner November 23, 2026 05:48
@sampan-s-nayak sampan-s-nayak added the go add ONLY when ready to merge, run all tests label Nov 23, 2026

@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 ensures that lineage reconstruction tasks reuse their original task index instead of generating a new one. This ensures consistent behavior for output file names, random seeds, and monotonically increasing IDs during task re-runs. The changes introduce a helper method _context_task_idx to resolve the task index from the reconstruction stamp and update the map operators accordingly, supported by new unit and integration tests. The review feedback suggests making the lineage task ID parsing in _task_index_of more robust against malformed IDs to prevent potential IndexError exceptions.

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

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

Approved with minor comments

return f"{operator_id}:{task_index}"


def parse_lineage_task_id(lineage_task_id: LineageTaskId) -> Tuple[str, int]:

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.

Can we type alias the return value here? e.g. OperatorId = str and TaskIndex = int next to LineageTaskId, and use them in make_lineage_task_id too.

Suggested change
def parse_lineage_task_id(lineage_task_id: LineageTaskId) -> Tuple[str, int]:
def parse_lineage_task_id(lineage_task_id: LineageTaskId) -> Tuple[OperatorId, TaskIndex]:

Comment on lines +665 to +667
def _create_task_context(
self, actor: ActorHandle, inputs: Optional[RefBundle] = None
) -> TaskContext:

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.

Should we make inputs a required kwarg in _create_task_context ?

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.

no I think it can stay optional for now, we mainly only need it for reconstruction tasks

Comment on lines +230 to +231
task_id = make_lineage_task_id("7691d4b1-7242-426b-8b17-a2ca4a1a811d", 51)
assert task_id == "7691d4b1-7242-426b-8b17-a2ca4a1a811d:51"

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: can we keep a short id like the others in this file so that it is more readable?

Move the operator ID and task index aliases to interfaces/common.py and
use them in lineage_tracker, the lineage reconstruction mixin and the
hanging detector, which had its own private OpId/TaskIdx. Shorten the
operator ID in the lineage task ID round-trip test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: sampan <[email protected]>
@sampan-s-nayak
sampan-s-nayak enabled auto-merge (squash) November 25, 2026 05:40

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

The Testing section still says the two end-to-end tests haven't run, but premerge build 77631 on ad81cc7 ran //python/ray/data:test_lineage_reconstruction and it passed. The description becomes the commit message, so that part is worth updating.

Locally on ca61327 against the merge base 32e5120 (pyarrow 25.0.1), both new tests fail on the base and pass on the head, and the rest of the file passes on both. Beyond random_sample, I checked the other three things the description lists (random(seed=...), monotonically_increasing_id(), streaming_train_test_split(seed=...)) and a write, each with one injected loss downstream, on the task pool, on an actor pool, and with RAY_DATA_ACTOR_ONLY_BACKEND=1. Over 13 cases with 3 runs each, every case changes after the re-run on the base (the re-run task sees index 10 instead of 4, and the write leaves an 11th file) and matches on the head. So the fix holds on all three paths. What's missing is a test on the actor paths; details in the comments below.

"""Build the ``TaskContext`` for a task submitted to ``actor`` on ``inputs``."""
return TaskContext(
task_idx=self._next_data_task_idx,
task_idx=self._context_task_idx(inputs),

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.

This line is the fix for the chaos test's case, and no test covers it. On this branch with RAY_DATA_ACTOR_ONLY_BACKEND=1, Write runs on this operator, not on the experimental one. With only this line reverted to self._next_data_task_idx, the same setup as test_re_run_write_overwrites_the_file_of_the_failed_attempt under that env var leaves 11 files with rows 40–49 written twice (3 of 3 runs), while all 40 tests in test_lineage_reconstruction.py and unit/test_lineage_reconstruction_executor.py still pass. Without the env var it shows up for an expression on an actor pool: with_column("mid", monotonically_increasing_id(), compute=ActorPoolStrategy(size=2)) re-runs the lost batch with different IDs.

A copy of the write test under tests/actor_only/ would cover it, since that directory's conftest sets the env var for the whole session.

task_index = self._next_data_task_idx

ctx = self._create_task_context(actor)
ctx = self._create_task_context(actor, bundle)

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.

Nothing reaches this one yet: outside the tests, ExperimentalActorPoolMapOperator isn't constructed on this branch or on master, and with RAY_DATA_ACTOR_ONLY_BACKEND=1 coverage of the two changed lines in this file is still 0. #68042 also changes _create_task_context here, so whichever PR merges second has to carry this over. A check like test_reconstruction_task_context_reuses_the_original_task_index, calling _create_task_context(actor, stamped_bundle) on this class, would keep it from getting lost in that rebase.

@sampan-s-nayak
sampan-s-nayak merged commit 88648d8 into ray-project:master Nov 25, 2026
6 checks passed
iamjustinhsu added a commit that referenced this pull request Nov 26, 2026
interfaces/common.py keeps both sides' type aliases: this branch's
PlacementGroupIdStr and master's OperatorId and TaskIndex (#68400).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
iamjustinhsu added a commit that referenced this pull request Nov 26, 2026
…ft-integration

Brings master's #68400 (re-run reconstruction tasks under their original
task index) up from 6/n. Both sides kept:
- MapOperator: this branch's _on_output_withheld hook and master's
  _context_task_idx.
- ExperimentalActorPoolMapOperator._create_task_context: master's inputs
  parameter, which the body passes to _context_task_idx, and this
  branch's docstring summary.

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

3 participants