[gpu-info, mcp] fix: surface listing enumeration failures - #235
Conversation
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughCUDA/ROCm device enumeration failures via torch.cuda.device_count() are now classified as DeviceEnumerationUnavailableError and propagated through gpu_info.py's fallback chain instead of returning successful empty GPU lists. A new helper wraps torch.cuda.device_count(), error propagation was added to fallback branches, tests were updated/added, and documentation and a plan file were updated accordingly. ChangesEnumeration Unavailable Error Propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request implements a plan to surface CUDA/ROCm visible-device enumeration failures as startup-unavailable errors (DeviceEnumerationUnavailableError) instead of successful empty GPU lists. It modifies gpu_info.py to raise this error when torch.cuda.device_count() fails, propagates it through the query functions, and updates the tests and documentation accordingly. The review feedback highlights potential gaps where unhandled exceptions in torch.cuda.is_available() or torch.cuda.current_device() could still be swallowed by outer try-except blocks in get_gpu_info(), bypassing the intended error propagation. Additionally, a cleaner, more idiomatic exception handling structure is suggested for _torch_cuda_visible_count().
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/keep_gpu/utilities/gpu_info.py (2)
240-243: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
torch.cuda.is_available()is called twice in a row.Minor duplication; caching the result would avoid a redundant call.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/keep_gpu/utilities/gpu_info.py` around lines 240 - 243, The GPU availability check in gpu_info.py is duplicated by calling torch.cuda.is_available() twice in the same flow. Cache that result once in the function that sets current_device and computes count, then reuse the cached boolean for both the current_device assignment and the _visible_torch_device_count() branch to avoid the redundant call.
35-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRedundant double-wrapping of the enumeration error.
_visible_torch_device_count()already converts every failure intoDeviceEnumerationUnavailableError. The surroundingtry/except Exceptionin_torch_cuda_visible_count()then re-checksisinstance(exc, DeviceEnumerationUnavailableError)to re-raise it — this only matters for a failure incuda.is_available()itself. CatchingDeviceEnumerationUnavailableErrorexplicitly first would be clearer:♻️ Simplify exception handling
try: if not cuda.is_available(): return 0 count = _visible_torch_device_count() - except Exception as exc: - if isinstance(exc, DeviceEnumerationUnavailableError): - raise + except DeviceEnumerationUnavailableError: + raise + except Exception as exc: logger.debug("Torch CUDA visible count failed: %s", exc) raise DeviceEnumerationUnavailableError( f"Unable to enumerate visible GPUs: {exc}" ) from exc🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/keep_gpu/utilities/gpu_info.py` around lines 35 - 49, The exception handling in `_torch_cuda_visible_count()` is redundantly re-wrapping `DeviceEnumerationUnavailableError` after calling `_visible_torch_device_count()`. Update this function to catch `DeviceEnumerationUnavailableError` explicitly before the generic `Exception` path, and keep the generic wrapping only for failures from `cuda.is_available()` or other unexpected errors. Use the existing `_torch_cuda_visible_count` and `_visible_torch_device_count` symbols to keep the flow clear and avoid double-handling the same error type.docs/plans/list-gpus-enumeration-unavailable.md (1)
13-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueHeading level skips from h1 to h3.
Static analysis flagged that
### Task 1jumps directly from the document's# Title(h1) without an intervening h2. Purely cosmetic for a plan doc.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/plans/list-gpus-enumeration-unavailable.md` at line 13, The document heading hierarchy skips from the top-level title to a level-3 heading, so update the Task 1 heading in the plan doc to use the appropriate intermediate level. Keep the section label consistent with the surrounding structure by adjusting the heading markup for “Task 1: Propagate Enumeration Failures from GPU Listing” so it follows the document’s h1 title with an h2.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@docs/plans/list-gpus-enumeration-unavailable.md`:
- Line 13: The document heading hierarchy skips from the top-level title to a
level-3 heading, so update the Task 1 heading in the plan doc to use the
appropriate intermediate level. Keep the section label consistent with the
surrounding structure by adjusting the heading markup for “Task 1: Propagate
Enumeration Failures from GPU Listing” so it follows the document’s h1 title
with an h2.
In `@src/keep_gpu/utilities/gpu_info.py`:
- Around line 240-243: The GPU availability check in gpu_info.py is duplicated
by calling torch.cuda.is_available() twice in the same flow. Cache that result
once in the function that sets current_device and computes count, then reuse the
cached boolean for both the current_device assignment and the
_visible_torch_device_count() branch to avoid the redundant call.
- Around line 35-49: The exception handling in `_torch_cuda_visible_count()` is
redundantly re-wrapping `DeviceEnumerationUnavailableError` after calling
`_visible_torch_device_count()`. Update this function to catch
`DeviceEnumerationUnavailableError` explicitly before the generic `Exception`
path, and keep the generic wrapping only for failures from `cuda.is_available()`
or other unexpected errors. Use the existing `_torch_cuda_visible_count` and
`_visible_torch_device_count` symbols to keep the flow clear and avoid
double-handling the same error type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2f6a3af6-a885-4e73-8553-06ff31e5daa4
📒 Files selected for processing (6)
AGENTS.mddocs/plans/list-gpus-enumeration-unavailable.mddocs/reference/cli.mdsrc/keep_gpu/utilities/gpu_info.pytests/mcp/test_server.pytests/utilities/test_gpu_info.py
0282f86 to
4949be1
Compare
4949be1 to
d253f18
Compare
|
Addressed the CodeRabbit nitpick bundle on the current head: |
Summary
DeviceEnumerationUnavailableErrorwhen CUDA/ROCm visible device counts fail during GPU listinglist_gpus//api/gpusaligned with startup-unavailable classification instead of returning successful empty listsTest Plan
PYTHONPATH=src pytest tests/utilities/test_gpu_info.py -q -k 'count_fails or enumeration_unavailable'(RED before fix, green after)PYTHONPATH=src pytest tests/mcp/test_server.py -q -k 'list_gpus and enumeration'(RED before fix, green after)PYTHONPATH=src pytest tests/utilities/test_gpu_info.py -qPYTHONPATH=src pytest tests/mcp/test_server.py -q -k 'list_gpus or DeviceEnumerationUnavailableError or startup_unavailable'PYTHONPATH=src pytest tests/mcp/test_http_api.py -q -k 'api_gpus or list_gpus or startup_unavailable or enumeration_unavailable'PYTHONPATH=src pytest tests -qPYTHONPATH=src mkdocs build --strictpre-commit run --all-files --show-diff-on-failuregit diff --checkSummary by CodeRabbit
New Features
Bug Fixes
Documentation