fix: guard against None resource_limit in _max_throughput_from_resources#62602
fix: guard against None resource_limit in _max_throughput_from_resources#62602kuishou68 wants to merge 1 commit intoray-project:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a null check for resource_limit in the throughput solver to prevent a TypeError when calculating maximum throughput. The review feedback points out that a similar TypeError could occur at line 100 if resource requirements are unset, and suggests handling those cases as well as optimizing the check's placement for better efficiency.
| for op in rates | ||
| ) | ||
| if resource_cost_per_unit_throughput > 0: | ||
| if resource_cost_per_unit_throughput > 0 and resource_limit is not None: |
There was a problem hiding this comment.
While this change correctly guards against None in resource_limit, a similar TypeError is likely to occur at line 100. If any operator in resource_requirements has a None value for a resource (which ExecutionResources uses to represent unconstrained or unset fields), the division getattr(resource_requirements[op], resource_name) / rates[op] will fail. Consider handling None values in the sum calculation as well, for example by using (getattr(...) or 0). Additionally, for better efficiency, the resource_limit is not None check could be performed before the sum calculation (lines 99-102) to avoid unnecessary computation for unconstrained resources.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 00f0a40. Configure here.
| for op in rates | ||
| ) | ||
| if resource_cost_per_unit_throughput > 0: | ||
| if resource_cost_per_unit_throughput > 0 and resource_limit is not None: |
There was a problem hiding this comment.
None guard is ineffective due to property coercion
High Severity
The resource_limit is not None guard never triggers because getattr(resource_limits, resource_name) calls the cpu/gpu/memory properties on ExecutionResources, which coerce None to 0.0 via self._cpu or 0.0. So resource_limit is always a float, never None. When a resource is truly unconstrained (_cpu is None), the property returns 0.0, and 0.0 / positive_cost yields 0.0, incorrectly capping max_throughput to zero. The fix needs to check the private _cpu/_gpu/_memory attributes or otherwise detect the unconstrained case.
Reviewed by Cursor Bugbot for commit 00f0a40. Configure here.


Closes #62601
Problem
_max_throughput_from_resources()callsgetattr(resource_limits, resource_name)to get CPU/GPU/memory limits. When a resource is unconstrained,ExecutionResourcesstoresNonefor that field. The divisionresource_limit / resource_cost_per_unit_throughputthen raises:Fix
Add a
resource_limit is not Noneguard — aNonelimit means the resource is unconstrained and should not boundmax_throughput: