Skip to content

[Autoscaler] Request ID sharing causes instance starvation due to launch_errors dict collision and request_id reuse #65223

Closed

Description

@daiping8

What happened + What you expected to happen

The Bug

When multiple instances share the same request_id in Ray Autoscaler V2, the launch_errors dictionary construction causes only one instance type to be correctly matched against its error. This leads to situations where:

  • One instance type correctly transitions to ALLOCATION_FAILED
  • Another instance type with the same request_id incorrectly "escapes" the error and continues waiting in REQUESTED state, potentially grabbing Pods that were intended for later instances

The root cause is that when building the launch_errors dict in _handle_cloud_instance_allocation, using request_id as the sole key causes multiple LaunchNodeError objects with the same request_id but different node_types to overwrite each other.

Expected Behavior

Each instance should be correctly matched against its corresponding LaunchNodeError based on both request_id AND node_type. When a batch launch fails with errors for multiple node types, each instance should fail appropriately regardless of whether it shares a request_id with other instances.

Actual Behavior

Consider this concrete timeline from a real deployment:

Time Event
8:42:04 Instance 0de9c5ae... (downstream) and 75b31502... (upstream) both enter REQUESTED state, sharing request_id=306d3b4d-0885-40b6-92aa-0a7c1390793d
8:42:04 cloud_provider.launch() fails because workers_to_be_deleted is non-empty. _add_launch_errors creates TWO errors: one for downstream, one for upstream
8:42:09 Building launch_errors = {error.request_id: error ...} causes the downstream error to be overwritten by the upstream error (same key!)
8:42:09 75b31502... (upstream) matches error_upstream → ALLOCATION_FAILED ✓
8:42:09 0de9c5ae... (downstream) looks for error but gets error_upstream (wrong type!) → no match, stays in REQUESTED ⏸️
8:43:01 KubeRay creates Pod z25wg for downstream group
8:43:06 0de9c5ae... (entered REQUESTED at 8:42:04) is earlier than 3e9d8319... (entered at 8:43:00), so it wins the race via pop() and gets z25wg → ALLOCATED
8:43:06 3e9d8319... (downstream) has no unassigned Pods to claim → stays REQUESTED

Result: Instance 0de9c5ae... (downstream) should have failed along with 75b31502... (upstream) at 8:42:09, but instead "escaped" the error matching due to the dict collision bug. It then went on to grab Pod z25wg that would otherwise have been available for 3e9d8319....

Root Cause Analysis

Bug: launch_errors dict collision (line ~371-375 in reconciler.py)

# Current buggy code
launch_errors: Dict[str, LaunchNodeError] = {
    error.request_id: error  # ← Using only request_id as key!
    for error in cloud_provider_errors
    if isinstance(error, LaunchNodeError)
}

# When cloud_provider_errors contains:
# - LaunchNodeError(request_id="306d3b4d", node_type="downstream", count=1)
# - LaunchNodeError(request_id="306d3b4d", node_type="upstream", count=1)

# Result: {"306d3b4d": error_upstream}  # downstream error is lost!

Fix: Use (request_id, node_type) tuple as the key:

launch_errors: Dict[Tuple[str, str], LaunchNodeError] = {
    (error.request_id, error.node_type): error
    for error in cloud_provider_errors
    if isinstance(error, LaunchNodeError)
}

And update the lookup in _try_resolve_pending_allocation:

# Before
launch_error = launch_errors.get(im_instance.launch_request_id)

# After
launch_error = launch_errors.get((im_instance.launch_request_id, im_instance.instance_type))

Impact

This bug causes:

  • Incorrect error matching: Instances with shared request_id but different node_types are not correctly matched to their corresponding errors
  • Unfair Pod allocation: Instances that should have failed can "escape" and grab Pods intended for other instances
  • Cascading delays: Later instances may starve waiting for Pods that were already allocated to earlier "escaped" instances

Related Code Locations

Component File
launch_errors dict construction reconciler.py:371-375
_try_resolve_pending_allocation reconciler.py:386-442
_add_launch_errors cloud_provider.py:467-493

Versions / Dependencies

Versions / Dependencies

  • Ray: master (development branch)
  • Python: 3.x
  • OS: Linux (tested on Kubernetes with KubeRay provider)

Reproduction script

Reproduction script

While a full reproduction requires a Kubernetes cluster with KubeRay, the bug can be triggered by:

  1. Configure Ray Autoscaler V2 with KubeRay cloud provider
  2. Create a scenario where workers_to_be_deleted is non-empty when new instances are requested
  3. Ensure multiple node_types share the same request_id in a single reconcile loop
  4. Observe that only one node_type gets the ALLOCATION_FAILED treatment while others slip through and continue waiting for Pods

Verification Test

The bug fix can be verified with the following unit test:

@staticmethod
def test_requested_multiple_node_types_same_request_id_to_allocation_failed(setup):
    """
    Test that when multiple instances with different node_types share the same
    request_id and all fail to launch, each instance should be transitioned to
    ALLOCATION_FAILED with its corresponding launch error.

    This tests the scenario where a single scaling request contains multiple
    node_types, and each node_type fails independently.
    """
    instance_manager, instance_storage, _, cloud_resource_monitor = setup

    instances = [
        create_instance(
            "i-1",
            status=Instance.REQUESTED,
            instance_type="type-1",
            launch_request_id="l1",
        ),
        create_instance(
            "i-2",
            status=Instance.REQUESTED,
            instance_type="type-2",
            launch_request_id="l1",
        ),
    ]
    TestReconciler._add_instances(instance_storage, instances)

    # Both node_types failed to launch
    launch_errors = [
        LaunchNodeError(
            request_id="l1",
            count=1,
            node_type="type-1",
            timestamp_ns=1,
            details="Type-1 node failed: workers_to_be_deleted conflict",
        ),
        LaunchNodeError(
            request_id="l1",
            count=1,
            node_type="type-2",
            timestamp_ns=1,
            details="Type-2 node failed: workers_to_be_deleted conflict",
        ),
    ]

    cloud_instances = {}

    Reconciler.reconcile(
        instance_manager,
        scheduler=MockScheduler(),
        cloud_provider=MagicMock(),
        cloud_resource_monitor=cloud_resource_monitor,
        ray_cluster_resource_state=ClusterResourceState(),
        non_terminated_cloud_instances=cloud_instances,
        cloud_provider_errors=launch_errors,
        ray_install_errors=[],
        autoscaling_config=MockAutoscalingConfig(),
    )

    result_instances, _ = instance_storage.get_instances()

    # Both instances should be ALLOCATION_FAILED
    assert result_instances["i-1"].status == Instance.ALLOCATION_FAILED
    assert result_instances["i-2"].status == Instance.ALLOCATION_FAILED

Expected behavior after fix: Both instances i-1 and i-2 should transition to ALLOCATION_FAILED because each has a corresponding LaunchNodeError with matching (request_id, node_type).

Current buggy behavior: Only i-2 (type-2) will transition to ALLOCATION_FAILED, while i-1 (type-1) remains in REQUESTED because its error was overwritten in the launch_errors dict.

Issue Severity

High: It blocks me from completing my task.

Activity

  1. added
    bug
    triage
    on Aug 5, 2026
  2. adbcodes commented on Aug 5, 2026

    @adbcodes

    Hi, I’d like to work on this if it’s still available

  3. added
    core
    on Aug 5, 2026
  4. moved this from Todo to In progress in Ray Data OSSon Aug 10, 2026
  5. added
    P0
    and removed
    triage
    on Aug 17, 2026
  6. Kunchd commented on Sep 1, 2026

    @Kunchd
    Contributor

    Addressed by #65299. Closing the issue.

  7. moved this from In progress to Done in Ray Data OSSon Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0bugcommunity-backlogcorestability

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions