Skip to content

Conversation

@DeborahOlaboye
Copy link
Contributor

Description

Move env_integer, env_float, and env_bool utility functions from ray._private.ray_constants to ray._common.utils. Update all Ray Data imports to use the new location.

Related issues

Fixes #60516

Signed-off-by: DeborahOlaboye <deboraholaboye@gmail.com>
@DeborahOlaboye DeborahOlaboye requested review from a team, edoakes and jjyao as code owners February 1, 2026 08:17
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 refactors the env_integer, env_float, and env_bool utility functions by moving them from ray._private.ray_constants to ray._common.utils. The changes across the codebase correctly update the import paths to reflect this move.

My review focuses on the implementation of the moved functions. I've identified a correctness issue in env_integer where it fails to handle negative integer values from environment variables. I've also suggested a minor improvement to env_bool for better readability and to avoid redundant lookups. The implementation of env_float looks good.

Comment on lines +24 to +36
def env_integer(key, default):
if key in os.environ:
value = os.environ[key]
if value.isdigit():
return int(os.environ[key])

logger.debug(
f"Found {key} in environment, but value must "
f"be an integer. Got: {value}. Returning "
f"provided default {default}."
)
return default
return default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of value.isdigit() to check if an environment variable is an integer is not robust as it doesn't handle negative numbers (e.g., "-1".isdigit() is False). This will cause the function to incorrectly fall back to the default value for negative integers. It's better to use a try-except ValueError block for conversion, which is more robust and consistent with the implementation of env_float.

Suggested change
def env_integer(key, default):
if key in os.environ:
value = os.environ[key]
if value.isdigit():
return int(os.environ[key])
logger.debug(
f"Found {key} in environment, but value must "
f"be an integer. Got: {value}. Returning "
f"provided default {default}."
)
return default
return default
def env_integer(key, default):
if key in os.environ:
value = os.environ[key]
try:
return int(value)
except ValueError:
logger.debug(
f"Found {key} in environment, but value must "
f"be an integer. Got: {value}. Returning "
f"provided default {default}."
)
return default
return default
Comment on lines +54 to +61
def env_bool(key, default):
if key in os.environ:
return (
True
if os.environ[key].lower() == "true" or os.environ[key] == "1"
else False
)
return default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation accesses os.environ[key] multiple times within the conditional logic. This can be slightly improved for efficiency and readability by storing the value in a local variable before performing comparisons.

def env_bool(key, default):
    if key in os.environ:
        val = os.environ[key].lower()
        return val == "true" or val == "1"
    return default
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

ResourceRequestPriority,
)
from ray.autoscaler._private.constants import env_integer
from ray._common.utils import env_integer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong env_integer implementation imported, losing inf support

Medium Severity

The import of env_integer changed from ray.autoscaler._private.constants to ray._common.utils, but these have different implementations. The autoscaler version supports "inf" (returning sys.maxsize), accepts negative numbers via direct int() conversion, and raises ValueError on invalid input. The common utils version uses isdigit() which rejects negative numbers and "inf", silently falling back to the default. If users previously set RAY_DATA_AUTOSCALING_COORDINATOR_REQUEST_GET_TIMEOUT_S=inf for example, this would now silently use the default value instead.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant