Repository navigation
[Core] Fix EvictLineage evicting all lineage due to negative byte accounting - #67271
Merged
rueian merged 1 commit intoOct 26, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in TaskManager::RemoveLineageReference where it returned a negative delta instead of the positive number of bytes released, which caused the eviction loop to drain the entire queue. A unit test was added to verify that eviction stops at the target. The reviewer suggested defensively wrapping the returned value in std::max to guarantee it is never negative.
…ounting TaskManager::RemoveLineageReference() returned the net change of total_lineage_footprint_bytes_ (new - prev). Releasing lineage can only decrease that total, so the value was always <= 0. EvictLineage() treats it as "bytes evicted" and loops while lineage_bytes_evicted < min_bytes_to_evict (always positive at the call site), so the accumulator could never reach the target. The only remaining exit was an empty queue: whenever eviction was triggered, it evicted every entry in reconstructable_owned_objects_ instead of stopping after enough lineage was released. Consequence: every eligible, in-scope object in the queue was marked INELIGIBLE_LINEAGE_EVICTED, while only tasks whose in-scope return IDs were all present in the queue were actually freed. Once the limit was hit, the next node death could leave an object with neither a copy nor lineage, and reconstruction failed with OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED. Fix: return the negated delta (bytes released, non-negative), matching the LineageReleasedCallback contract. The accumulator can then reach min_bytes_to_evict and the loop stops after a partial eviction. Test: add TaskManagerLineageEvictionTest.TestEvictLineageStopsAtTarget, which fails with the previous return value (queue drained) and passes with the fix. Signed-off-by: dragongu <[email protected]>
dragongu
force-pushed
the
fix/evict-lineage-negative-bytes
branch
from
October 22, 2026 09:39
591657c to
5be279d
Compare
rueian
approved these changes
Oct 23, 2026
Kunchd
approved these changes
Oct 26, 2026
Kunchd
left a comment
Contributor
There was a problem hiding this comment.
Thanks for making this fix!!! Now lineage reconstruction won't drop lineages for no reason 🤣
elliot-barn
added a commit
that referenced
this pull request
Oct 28, 2026
MSVC rejects the lambda's implicit use of the local const max_retries (C3493: cannot be implicitly captured), so task_manager_test fails to build on Windows since #67271. Pass -1 directly instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: elliot-barn <[email protected]>
justinyeh1995
pushed a commit
to justinyeh1995/ray
that referenced
this pull request
Oct 28, 2026
…ounting (ray-project#67271) ## Description The lineage-release callback returned the byte delta with the wrong sign, so eviction never reached its target and removed the entire reconstructable-object lineage. Under memory pressure, one eviction wiped lineage for every in-flight object while freeing only ~835MB; a node death seven minutes later left 13 objects unrecoverable and failed the job with `OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED`. The fix reports released bytes with the correct sign so eviction stops once it has released enough lineage. ## Related issues N/A. ## Additional information ### Production evidence `RAY_max_lineage_bytes` was set to 20GiB. The job failed with this sequence: ```text [2026-10-22 10:09:34,054 I ...] task_manager.cc:1149: Total lineage size is 21474.8MB, which exceeds the limit of 21474.8MB [2026-10-22 10:09:34,757 I ...] task_manager.cc:1213: Evicted -835.169MB of task lineage. ... [2026-10-22 10:16:18,617 I ...] Attempting to recover 115 lost objects by resubmitting their tasks... [2026-10-22 10:16:18,618 I ...] Cannot recover object abf8e6489a7fc95e...0200000002000000: OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED ... (13 objects total) ... ray.exceptions.RayTaskError(ObjectReconstructionFailedError): ray::Filter(<lambda>)() (pid=..., ip=<worker-ip>) [OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED] The object cannot be reconstructed because its lineage has been evicted to reduce memory pressure. To prevent this error, set the environment variable RAY_max_lineage_bytes=<bytes> (default 1GB) during `ray start`. ... SystemException ``` ### Root cause `ReferenceCounter::EvictLineage()` accumulates the callback result and stops only when the accumulator reaches a positive target: ```cpp int64_t lineage_bytes_evicted = 0; while (!reconstructable_owned_objects_.empty() && lineage_bytes_evicted < min_bytes_to_evict) { ... lineage_bytes_evicted += ReleaseLineageReferences(it); } ``` `ReleaseLineageReferences()` calls `TaskManager::RemoveLineageReference()` and adds its return value. That callback was returning the net change of `total_lineage_footprint_bytes_` (`new - prev`). Releasing lineage can only decrease the total, so the value is always `<= 0`. Since `min_bytes_to_evict = total - max / 2` is positive, the accumulator could never reach the target, and the only way out of the loop was an empty queue. The accounting error is only half of the impact. Each popped object is also marked `INELIGIBLE_LINEAGE_EVICTED` if it is still in scope and eligible, even when its task spec cannot be freed yet (for example, another return is still in scope). The queue was therefore drained — every in-flight eligible object lost lineage — while only the task specs whose last in-scope return was in the queue were actually freed. The failure is latent: it surfaces on the next node death for an object with no other copy, when reconstruction is refused with `OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED`. ### Fix Return `prev - current`, the non-negative number of bytes released, matching the `LineageReleasedCallback` contract. ### Test plan - [x] `bazel build //src/ray/core_worker/tests:task_manager_test` - [x] `bazel-bin/src/ray/core_worker/tests/task_manager_test --gtest_filter=TaskManagerLineageEvictionTest.TestEvictLineageStopsAtTarget` - `[ PASSED ] 1 test.` - [x] Reverting the return to `current - prev` makes the test fail. The new test uses two completed retryable tasks. `EvictLineage(1)` must report positive released bytes, free only the oldest task's lineage, and leave the newer object `ELIGIBLE` — proving the queue was not drained. ### Follow-up This fixes the sign error, not the footprint/queue accounting. `EvictLineage()` can still drain the queue when `total_lineage_footprint_bytes_` and `reconstructable_owned_objects_` are out of sync (e.g. streaming-generator return IDs re-inserted at completion after consumption; see the TODO in `task_manager.cc`). That should be tracked separately. ### Note The `OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED` message does suggest increasing `RAY_max_lineage_bytes`, but `python/ray/exceptions.py` hardcodes `(default 1GB)` regardless of the configured value (20GiB in this incident). That makes the guidance misleading during diagnosis. It will be fixed in a separate PR and is intentionally not changed here. Signed-off-by: dragongu <[email protected]> Co-authored-by: gulonglong <[email protected]>
elliot-barn
added a commit
that referenced
this pull request
Nov 2, 2026
MSVC rejects the lambda's implicit use of the local const max_retries (C3493: cannot be implicitly captured), so task_manager_test fails to build on Windows since #67271. Pass -1 directly instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: elliot-barn <[email protected]>
elliot-barn
added a commit
that referenced
this pull request
Nov 8, 2026
MSVC rejects the lambda's implicit use of the local const max_retries (C3493: cannot be implicitly captured), so task_manager_test fails to build on Windows since #67271. Pass -1 directly instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: elliot-barn <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The lineage-release callback returned the byte delta with the wrong sign, so eviction never reached its target and removed the entire reconstructable-object lineage. Under memory pressure, one eviction wiped lineage for every in-flight object while freeing only ~835MB; a node death seven minutes later left 13 objects unrecoverable and failed the job with
OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED.The fix reports released bytes with the correct sign so eviction stops once it has released enough lineage.
Related issues
N/A.
Additional information
Production evidence
RAY_max_lineage_byteswas set to 20GiB. The job failed with this sequence:Root cause
ReferenceCounter::EvictLineage()accumulates the callback result and stops only when the accumulator reaches a positive target:ReleaseLineageReferences()callsTaskManager::RemoveLineageReference()and adds its return value. That callback was returning the net change oftotal_lineage_footprint_bytes_(new - prev). Releasing lineage can only decrease the total, so the value is always<= 0. Sincemin_bytes_to_evict = total - max / 2is positive, the accumulator could never reach the target, and the only way out of the loop was an empty queue.The accounting error is only half of the impact. Each popped object is also marked
INELIGIBLE_LINEAGE_EVICTEDif it is still in scope and eligible, even when its task spec cannot be freed yet (for example, another return is still in scope). The queue was therefore drained — every in-flight eligible object lost lineage — while only the task specs whose last in-scope return was in the queue were actually freed.The failure is latent: it surfaces on the next node death for an object with no other copy, when reconstruction is refused with
OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTED.Fix
Return
prev - current, the non-negative number of bytes released, matching theLineageReleasedCallbackcontract.Test plan
bazel build //src/ray/core_worker/tests:task_manager_testbazel-bin/src/ray/core_worker/tests/task_manager_test --gtest_filter=TaskManagerLineageEvictionTest.TestEvictLineageStopsAtTarget[ PASSED ] 1 test.current - prevmakes the test fail.The new test uses two completed retryable tasks.
EvictLineage(1)must report positive released bytes, free only the oldest task's lineage, and leave the newer objectELIGIBLE— proving the queue was not drained.Follow-up
This fixes the sign error, not the footprint/queue accounting.
EvictLineage()can still drain the queue whentotal_lineage_footprint_bytes_andreconstructable_owned_objects_are out of sync (e.g. streaming-generator return IDs re-inserted at completion after consumption; see the TODO intask_manager.cc). That should be tracked separately.Note
The
OBJECT_UNCONSTRUCTABLE_LINEAGE_EVICTEDmessage does suggest increasingRAY_max_lineage_bytes, butpython/ray/exceptions.pyhardcodes(default 1GB)regardless of the configured value (20GiB in this incident). That makes the guidance misleading during diagnosis. It will be fixed in a separate PR and is intentionally not changed here.