Skip to content

[Data] Fix incorrect input of request_remaining in _send_resource_request from rate based autoscaler - #66366

Closed
owenowenisme wants to merge 1 commit into
ray-project:masterfrom
owenowenisme:data/fix-wrong-input-of-send-resource-req-in-rb-autocsaler
Closed

owenowenisme wants to merge 1 commit into
ray-project:masterfrom
owenowenisme:data/fix-wrong-input-of-send-resource-req-in-rb-autocsaler

Conversation

@owenowenisme

@owenowenisme owenowenisme commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Description

#66001 changed the autoscaling coordinator's request_remaining param from a bool to a list of resource types, and get_reserved_resources() from a list of bundles to a dict keyed by node ID. The rate-based autoscaler (#65954) merged in between and was never updated, the two PRs never coexisted in a CI run, so every resource request from the rate-based autoscaler now dies in the coordinator actor with TypeError: 'bool' object is not iterable, and get_total_resources() crashes iterating node-ID strings.

This PR fixes that.

Fix both call sites to match the new API (same as default_cluster_autoscaler_v2.py).

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

Signed-off-by: You-Cheng Lin <[email protected]>
@owenowenisme
owenowenisme marked this pull request as ready for review September 22, 2026 09:36
@owenowenisme
owenowenisme requested a review from a team as a code owner September 22, 2026 09:36
@owenowenisme owenowenisme added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Sep 22, 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 updates rate_based_cluster_autoscaler.py to import and use STANDARD_RESOURCE_TYPES for the request_remaining parameter in resource requests, and fixes a bug in get_total_resources by iterating over resources.values() instead of resources. The review feedback suggests optimizing get_total_resources by using ExecutionResources.combine_sum instead of a manual loop to avoid intermediate allocations.

@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member

Closed as a duplicate

matthewdeng pushed a commit that referenced this pull request Sep 22, 2026
… from input to output (#66369)

## Description

A Ray Train job dies before it reads a single row. Its input pipeline
shuffles a dataset that was already materialized:

```python
ds = ray.data.range(100, override_num_blocks=10).materialize()
ds = ds.randomize_block_order()
(it,) = ds.streaming_split(1, equal=True)
list(it.iter_rows())
```

```
(SplitCoordinator pid=42263) Split 0 epoch 0 get() failed after 0 rows: Cannot register
an out-of-scope/freed callback for object 6f1bcddfc6570c62…: it is not owned by this
worker (it may be owned by another worker, or have no ownership record). These callbacks
can only be registered by the owner.
```

### Why it happens

`BlockRefCounter` tracks object-store memory. To do that, it asks Ray
Core to call it back when a block is freed. Only the block's owner may
register that callback, and the owner is the process that created the
block.

`streaming_split` runs the plan inside a `SplitCoordinator` actor. But
the blocks were created earlier, by `materialize()` on the caller. The
same holds for any `InputData` source, such as `from_arrow` or
`from_pandas`.

```
  caller                        SplitCoordinator actor
  ──────────────                ──────────────────────
  materialize()   ── refs ──▶   randomize_block_order → … → split(N)
  owns B1..B10                  owns nothing it was handed
```

`AllToAllOperator.all_inputs_done` registered a callback for every block
it sent downstream. That is right for sort, shuffle and repartition.
Their output blocks come from reduce tasks the operator itself
submitted, so it owns them.

It is wrong for `RandomizeBlocks`. That operator creates no blocks. It
reorders its input bundles and returns the same refs. So the actor asks
Ray Core to watch blocks the caller owns, Ray Core refuses, and the
execution fails.

### The fix

Register a block only when its ref was not among the operator's inputs:

```python
input_refs = {entry.ref for b in input_bundles for entry in b.blocks}
...
for bundle in output_buffer:
    for entry in bundle.blocks:
        if entry.ref in input_refs:
            continue
        self._block_ref_counter.on_block_produced(...)
```

Returned refs are skipped. New ones are still registered.
`OutputSplitter` already uses the same test on `_split_block` output.

**Why not `RefBundle.owns_blocks`?** That flag says whether the blocks
may be destroyed, not who made them. The shuffle, sort and
split-repartition schedulers copy it from their input onto blocks their
own reduce tasks made (`input_owned = all(b.owns_blocks for b in refs)`
at `pull_based_shuffle_task_scheduler.py:50`, used at `:145`). A filter
on that flag would drop real blocks from the counter whenever the source
is `from_*` or `materialize`, and under-report their memory. Bugbot
caught this in the first version of this PR.

### Where it came from

#64157 added `BlockRefCounter` to the operators in 2.57, and the crash
has been there since. It was reported from a Ray Train job on 2.58.0.
That job's input pipeline is `from_arrow → repartition → materialize →
randomize_block_order → map_batches → repartition → streaming_split`,
and all four splits fail at 0 rows.

## Related issues

None open. I searched ray-project/ray for open PRs and issues mentioning
`BlockRefCounter`, `owns_blocks`, `streaming_split materialized`, and
the error text "Cannot register an out-of-scope callback". Two open PRs
touch the counter: #65878 (consumer-held bytes) and #65220 (deferring
gRPC frees). Neither changes this registration path, and no open issue
tracks the crash, so this is not duplicate work.

## Additional information

**Tests.** `test_streaming_split_over_materialized_all_to_all`
reproduces the failure end to end. The two tests in `test_operators.py`
cover both sides of the check; the second fails if the check uses
`owns_blocks`, which is what the first version of this PR did.

```
$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_streaming_integration.py \
    -k test_streaming_split_over_materialized_all_to_all -q
1 passed, 25 deselected in 9.28s        # fails on master with the error above

$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_operators.py \
    python/ray/data/tests/test_randomize_block_order.py \
    python/ray/data/tests/unit/test_block_ref_counter.py \
    python/ray/data/tests/unit/test_resource_manager.py -q
29 passed in 16.10s

$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_streaming_integration.py -k streaming_split -q
13 passed, 13 deselected in 68.67s
```

The last command needs #66366 applied locally. On master,
`request_remaining=True` in `rate_based_cluster_autoscaler.py` raises
`TypeError: 'bool' object is not iterable` in the autoscaling
coordinator, which makes these tests flaky.

**CI.** The `buildkite/premerge` failure here is that same master bug.
All three pyrefly errors are in `rate_based_cluster_autoscaler.py`, a
file this PR does not touch. #66366 and #66370 both fix it, and this PR
is unblocked once either one lands.

**AI assistance was used** for the diagnosis, the patch, and this
description.

---------

Signed-off-by: Marwan Sarieddine <[email protected]>
Co-authored-by: Ayush Kumar <[email protected]>
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
… from input to output (ray-project#66369)

## Description

A Ray Train job dies before it reads a single row. Its input pipeline
shuffles a dataset that was already materialized:

```python
ds = ray.data.range(100, override_num_blocks=10).materialize()
ds = ds.randomize_block_order()
(it,) = ds.streaming_split(1, equal=True)
list(it.iter_rows())
```

```
(SplitCoordinator pid=42263) Split 0 epoch 0 get() failed after 0 rows: Cannot register
an out-of-scope/freed callback for object 6f1bcddfc6570c62…: it is not owned by this
worker (it may be owned by another worker, or have no ownership record). These callbacks
can only be registered by the owner.
```

### Why it happens

`BlockRefCounter` tracks object-store memory. To do that, it asks Ray
Core to call it back when a block is freed. Only the block's owner may
register that callback, and the owner is the process that created the
block.

`streaming_split` runs the plan inside a `SplitCoordinator` actor. But
the blocks were created earlier, by `materialize()` on the caller. The
same holds for any `InputData` source, such as `from_arrow` or
`from_pandas`.

```
  caller                        SplitCoordinator actor
  ──────────────                ──────────────────────
  materialize()   ── refs ──▶   randomize_block_order → … → split(N)
  owns B1..B10                  owns nothing it was handed
```

`AllToAllOperator.all_inputs_done` registered a callback for every block
it sent downstream. That is right for sort, shuffle and repartition.
Their output blocks come from reduce tasks the operator itself
submitted, so it owns them.

It is wrong for `RandomizeBlocks`. That operator creates no blocks. It
reorders its input bundles and returns the same refs. So the actor asks
Ray Core to watch blocks the caller owns, Ray Core refuses, and the
execution fails.

### The fix

Register a block only when its ref was not among the operator's inputs:

```python
input_refs = {entry.ref for b in input_bundles for entry in b.blocks}
...
for bundle in output_buffer:
    for entry in bundle.blocks:
        if entry.ref in input_refs:
            continue
        self._block_ref_counter.on_block_produced(...)
```

Returned refs are skipped. New ones are still registered.
`OutputSplitter` already uses the same test on `_split_block` output.

**Why not `RefBundle.owns_blocks`?** That flag says whether the blocks
may be destroyed, not who made them. The shuffle, sort and
split-repartition schedulers copy it from their input onto blocks their
own reduce tasks made (`input_owned = all(b.owns_blocks for b in refs)`
at `pull_based_shuffle_task_scheduler.py:50`, used at `:145`). A filter
on that flag would drop real blocks from the counter whenever the source
is `from_*` or `materialize`, and under-report their memory. Bugbot
caught this in the first version of this PR.

### Where it came from

ray-project#64157 added `BlockRefCounter` to the operators in 2.57, and the crash
has been there since. It was reported from a Ray Train job on 2.58.0.
That job's input pipeline is `from_arrow → repartition → materialize →
randomize_block_order → map_batches → repartition → streaming_split`,
and all four splits fail at 0 rows.

## Related issues

None open. I searched ray-project/ray for open PRs and issues mentioning
`BlockRefCounter`, `owns_blocks`, `streaming_split materialized`, and
the error text "Cannot register an out-of-scope callback". Two open PRs
touch the counter: ray-project#65878 (consumer-held bytes) and ray-project#65220 (deferring
gRPC frees). Neither changes this registration path, and no open issue
tracks the crash, so this is not duplicate work.

## Additional information

**Tests.** `test_streaming_split_over_materialized_all_to_all`
reproduces the failure end to end. The two tests in `test_operators.py`
cover both sides of the check; the second fails if the check uses
`owns_blocks`, which is what the first version of this PR did.

```
$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_streaming_integration.py \
    -k test_streaming_split_over_materialized_all_to_all -q
1 passed, 25 deselected in 9.28s        # fails on master with the error above

$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_operators.py \
    python/ray/data/tests/test_randomize_block_order.py \
    python/ray/data/tests/unit/test_block_ref_counter.py \
    python/ray/data/tests/unit/test_resource_manager.py -q
29 passed in 16.10s

$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_streaming_integration.py -k streaming_split -q
13 passed, 13 deselected in 68.67s
```

The last command needs ray-project#66366 applied locally. On master,
`request_remaining=True` in `rate_based_cluster_autoscaler.py` raises
`TypeError: 'bool' object is not iterable` in the autoscaling
coordinator, which makes these tests flaky.

**CI.** The `buildkite/premerge` failure here is that same master bug.
All three pyrefly errors are in `rate_based_cluster_autoscaler.py`, a
file this PR does not touch. ray-project#66366 and ray-project#66370 both fix it, and this PR
is unblocked once either one lands.

**AI assistance was used** for the diagnosis, the patch, and this
description.

---------

Signed-off-by: Marwan Sarieddine <[email protected]>
Co-authored-by: Ayush Kumar <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
… from input to output (ray-project#66369)

## Description

A Ray Train job dies before it reads a single row. Its input pipeline
shuffles a dataset that was already materialized:

```python
ds = ray.data.range(100, override_num_blocks=10).materialize()
ds = ds.randomize_block_order()
(it,) = ds.streaming_split(1, equal=True)
list(it.iter_rows())
```

```
(SplitCoordinator pid=42263) Split 0 epoch 0 get() failed after 0 rows: Cannot register
an out-of-scope/freed callback for object 6f1bcddfc6570c62…: it is not owned by this
worker (it may be owned by another worker, or have no ownership record). These callbacks
can only be registered by the owner.
```

### Why it happens

`BlockRefCounter` tracks object-store memory. To do that, it asks Ray
Core to call it back when a block is freed. Only the block's owner may
register that callback, and the owner is the process that created the
block.

`streaming_split` runs the plan inside a `SplitCoordinator` actor. But
the blocks were created earlier, by `materialize()` on the caller. The
same holds for any `InputData` source, such as `from_arrow` or
`from_pandas`.

```
  caller                        SplitCoordinator actor
  ──────────────                ──────────────────────
  materialize()   ── refs ──▶   randomize_block_order → … → split(N)
  owns B1..B10                  owns nothing it was handed
```

`AllToAllOperator.all_inputs_done` registered a callback for every block
it sent downstream. That is right for sort, shuffle and repartition.
Their output blocks come from reduce tasks the operator itself
submitted, so it owns them.

It is wrong for `RandomizeBlocks`. That operator creates no blocks. It
reorders its input bundles and returns the same refs. So the actor asks
Ray Core to watch blocks the caller owns, Ray Core refuses, and the
execution fails.

### The fix

Register a block only when its ref was not among the operator's inputs:

```python
input_refs = {entry.ref for b in input_bundles for entry in b.blocks}
...
for bundle in output_buffer:
    for entry in bundle.blocks:
        if entry.ref in input_refs:
            continue
        self._block_ref_counter.on_block_produced(...)
```

Returned refs are skipped. New ones are still registered.
`OutputSplitter` already uses the same test on `_split_block` output.

**Why not `RefBundle.owns_blocks`?** That flag says whether the blocks
may be destroyed, not who made them. The shuffle, sort and
split-repartition schedulers copy it from their input onto blocks their
own reduce tasks made (`input_owned = all(b.owns_blocks for b in refs)`
at `pull_based_shuffle_task_scheduler.py:50`, used at `:145`). A filter
on that flag would drop real blocks from the counter whenever the source
is `from_*` or `materialize`, and under-report their memory. Bugbot
caught this in the first version of this PR.

### Where it came from

ray-project#64157 added `BlockRefCounter` to the operators in 2.57, and the crash
has been there since. It was reported from a Ray Train job on 2.58.0.
That job's input pipeline is `from_arrow → repartition → materialize →
randomize_block_order → map_batches → repartition → streaming_split`,
and all four splits fail at 0 rows.

## Related issues

None open. I searched ray-project/ray for open PRs and issues mentioning
`BlockRefCounter`, `owns_blocks`, `streaming_split materialized`, and
the error text "Cannot register an out-of-scope callback". Two open PRs
touch the counter: ray-project#65878 (consumer-held bytes) and ray-project#65220 (deferring
gRPC frees). Neither changes this registration path, and no open issue
tracks the crash, so this is not duplicate work.

## Additional information

**Tests.** `test_streaming_split_over_materialized_all_to_all`
reproduces the failure end to end. The two tests in `test_operators.py`
cover both sides of the check; the second fails if the check uses
`owns_blocks`, which is what the first version of this PR did.

```
$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_streaming_integration.py \
    -k test_streaming_split_over_materialized_all_to_all -q
1 passed, 25 deselected in 9.28s        # fails on master with the error above

$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_operators.py \
    python/ray/data/tests/test_randomize_block_order.py \
    python/ray/data/tests/unit/test_block_ref_counter.py \
    python/ray/data/tests/unit/test_resource_manager.py -q
29 passed in 16.10s

$ PYTHONPATH=python/ray/data/tests python -m pytest \
    python/ray/data/tests/test_streaming_integration.py -k streaming_split -q
13 passed, 13 deselected in 68.67s
```

The last command needs ray-project#66366 applied locally. On master,
`request_remaining=True` in `rate_based_cluster_autoscaler.py` raises
`TypeError: 'bool' object is not iterable` in the autoscaling
coordinator, which makes these tests flaky.

**CI.** The `buildkite/premerge` failure here is that same master bug.
All three pyrefly errors are in `rate_based_cluster_autoscaler.py`, a
file this PR does not touch. ray-project#66366 and ray-project#66370 both fix it, and this PR
is unblocked once either one lands.

**AI assistance was used** for the diagnosis, the patch, and this
description.

---------

Signed-off-by: Marwan Sarieddine <[email protected]>
Co-authored-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.

Ray fails to serialize self-reference objects

2 participants