Repository navigation
[Data] [Data FT] Re-run lineage reconstruction tasks under their original task index - #68400
Conversation
…index Signed-off-by: sampan <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
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.
Signed-off-by: sampan <[email protected]>
ayushk7102
left a comment
There was a problem hiding this comment.
Approved with minor comments
| return f"{operator_id}:{task_index}" | ||
|
|
||
|
|
||
| def parse_lineage_task_id(lineage_task_id: LineageTaskId) -> Tuple[str, int]: |
There was a problem hiding this comment.
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.
| def parse_lineage_task_id(lineage_task_id: LineageTaskId) -> Tuple[str, int]: | |
| def parse_lineage_task_id(lineage_task_id: LineageTaskId) -> Tuple[OperatorId, TaskIndex]: |
| def _create_task_context( | ||
| self, actor: ActorHandle, inputs: Optional[RefBundle] = None | ||
| ) -> TaskContext: |
There was a problem hiding this comment.
Should we make inputs a required kwarg in _create_task_context ?
There was a problem hiding this comment.
no I think it can stay optional for now, we mainly only need it for reconstruction tasks
| task_id = make_lineage_task_id("7691d4b1-7242-426b-8b17-a2ca4a1a811d", 51) | ||
| assert task_id == "7691d4b1-7242-426b-8b17-a2ca4a1a811d:51" |
There was a problem hiding this comment.
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]>
rayo5o
left a comment
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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]>
…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]>
…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]>
Summary
A lineage reconstruction task now runs with the
TaskContext.task_idxof the task it re-runs. Before, it got a fresh index, so a re-runWriteadded a second file instead of replacing the first, and seeded operations drew different values.Before
TaskContext.task_idxcame 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:FilenameProvidernames 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 withexisting_data_behavior="overwrite_or_ignore". A Ray Core retry resends the sameTaskContext, 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 ownData sink ... finished. N rowscount stays correct, because it only counts the attempt it saw finish.random_sample(seed=...),streaming_train_test_split(seed=...), therandom(seed=...)expression andmonotonically_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'sTaskContext. For a bundle that carries areconstruction_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_orderoutput keys) still uses the fresh counter, so a re-run never shares a key with the attempt it replaces.A re-run
Writenow 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 changedSubsystems
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 newtest_reconstruction_task_context_reuses_the_original_task_index.pre-commiton the changed files: passes.pyrefly-datawas 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.test_lineage_reconstruction.py(test_re_run_write_overwrites_the_file_of_the_failed_attemptandtest_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