Skip to content

fix: remove panic in calculateGPUPairScore - #2229

Closed
shellyco-code wants to merge 3 commits into
Project-HAMi:masterfrom
shellyco-code:fix-scheduler-panic
Closed

fix: remove panic in calculateGPUPairScore#2229
shellyco-code wants to merge 3 commits into
Project-HAMi:masterfrom
shellyco-code:fix-scheduler-panic

Conversation

@shellyco-code

@shellyco-code shellyco-code commented Jul 31, 2026

Copy link
Copy Markdown

What does this PR do?
Fixes a critical reliability issue where the HAMi scheduler pod crashes via panic() if it encounters asymmetrical P2P links between two GPUs (which can happen due to hardware topology issues or driver glitches).

Instead of panicking and crashing the entire scheduler, calculateGPUPairScore now logs the error via klog.ErrorS with the affected GPU UUIDs and gracefully returns a score of 0. This allows the best-effort GPU allocator to continue operating safely with the remaining devices.

Which issue(s) this PR fixes:
Fixes #2228

Testing
✅ Verified go build ./... passes.
✅ Ensured that asymmetrical link conditions result in an error log rather than a process crash.
✅ Added DCO sign-off.
PR Acceptance Criteria
Commits are signed with Signed-off-by (DCO).
Code is properly formatted.
Resolves a crash vulnerability in the scheduler.

This PR was created with the assistance of an AI coding agent

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of asymmetric GPU peer-to-peer link data.
    • Invalid GPU link configurations now generate an error and safely return a zero score instead of terminating unexpectedly.
    • GPU scoring remains stable when peer-to-peer connectivity information is inconsistent.
    • Added safeguards for mismatched NVLink counts in GPU scoring.

Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@hami-robot
hami-robot Bot requested a review from FouoF July 31, 2026 08:51
@hami-robot

hami-robot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shellyco-code
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot
hami-robot Bot requested a review from mesutoezdil July 31, 2026 08:51
@github-actions github-actions Bot added the kind/bug Something isn't working label Jul 31, 2026
@hami-robot hami-robot Bot added the size/XS label Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The NVIDIA GPU pair scorer now documents its heuristic, logs asymmetric P2P link data with both GPU UUIDs, and returns a zero score instead of panicking. A regression test covers both score directions.

Changes

GPU P2P resilience

Layer / File(s) Summary
Log and score P2P mismatches
pkg/device/nvidia/calculate_score.go, pkg/device/nvidia/calculate_score_test.go
The scorer documents its heuristic, uses structured logging, records both GPU UUIDs for asymmetric P2P link counts, and returns zero instead of panicking. The test verifies zero scores in both directions.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related PRs

Suggested reviewers: fouof

Poem

A rabbit checks the GPU pair,
Logs both UUIDs with care.
When P2P links disagree,
Zero keeps the scheduler free.
Hop safely onward!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #2228 by logging asymmetric GPU links, returning a zero score, and adding regression coverage.
Out of Scope Changes check ✅ Passed All changes support the linked issue by modifying error handling, documenting the function, and testing asymmetric GPU links.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: removing the panic from calculateGPUPairScore.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/device/nvidia/calculate_score.go (1)

216-217: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for the P2P mismatch branch.

calculateGPUPairScore returns 0 when one GPU has fewer P2P links to another than vice versa, but pkg/device/nvidia/calculate_score_test.go only defines symmetric link maps. Add a case with different bidirectional link counts and assert that the pair score is 0 without panicking.

🤖 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 `@pkg/device/nvidia/calculate_score.go` around lines 216 - 217, Add a
regression test in calculate_score_test.go targeting calculateGPUPairScore with
asymmetric bidirectional P2P link counts, asserting it returns 0 and does not
panic. Keep the existing symmetric-link cases unchanged and construct the
smallest GPU/link-map setup that reaches the “P2PLinks mismatch” branch.
🤖 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 `@pkg/device/nvidia/calculate_score.go`:
- Around line 216-217: Add a regression test in calculate_score_test.go
targeting calculateGPUPairScore with asymmetric bidirectional P2P link counts,
asserting it returns 0 and does not panic. Keep the existing symmetric-link
cases unchanged and construct the smallest GPU/link-map setup that reaches the
“P2PLinks mismatch” branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 23fdd13b-9187-4246-8390-a87b5c654fc2

📥 Commits

Reviewing files that changed from the base of the PR and between 8fdd928 and f6b7ba6.

📒 Files selected for processing (1)
  • pkg/device/nvidia/calculate_score.go

@mesutoezdil mesutoezdil 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.

no ai assistance disclosure is present. if any ai tool was used, it must be disclosed per CONTRIBUTING.md: https://github.com/Project-HAMi/HAMi/blob/master/CONTRIBUTING.md#ai-assistance-notice

Comment thread pkg/device/nvidia/calculate_score.go
Comment thread pkg/device/nvidia/calculate_score.go
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@hami-robot hami-robot Bot added size/M and removed size/XS labels Jul 31, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/device/nvidia/calculate_score_test.go (1)

109-140: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the P2P-link mismatch logger.

When asymmetric links hits the mismatch branch, calculateGPUPairScore calls klog.ErrorS with "gpu0" and "gpu1". If that structured logging is required, add a logger assertion for both directions so a future change cannot silently remove the diagnostic.

🤖 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 `@pkg/device/nvidia/calculate_score_test.go` around lines 109 - 140, Update the
“asymmetric links” test around calculateGPUPairScore to assert the mismatch
diagnostic emitted by klog.ErrorS, verifying both gpu0 and gpu1 are included for
each direction. Use the test’s existing logging-capture or assertion mechanism,
preserving the current score expectations.
🤖 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 `@pkg/device/nvidia/calculate_score_test.go`:
- Around line 109-140: Update the “asymmetric links” test around
calculateGPUPairScore to assert the mismatch diagnostic emitted by klog.ErrorS,
verifying both gpu0 and gpu1 are included for each direction. Use the test’s
existing logging-capture or assertion mechanism, preserving the current score
expectations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 47cc7064-af7b-43ca-b1d3-bf4bcf47972c

📥 Commits

Reviewing files that changed from the base of the PR and between 3be7525 and 77fc7d0.

📒 Files selected for processing (1)
  • pkg/device/nvidia/calculate_score_test.go

@shellyco-code

Copy link
Copy Markdown
Author

@mesutoezdil yo TAL

@Eshiv-Pandey

Eshiv-Pandey commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

the PR description only mentions go build ./ passing, can you also run make verify and make test locally just so we know CI won't complain?

@DSFans2014 DSFans2014 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please fix the lint error

@mesutoezdil

Copy link
Copy Markdown
Contributor

Closing: same fix as #2174 for the same function, but #2174 propagates the error properly while this silently returns 0 on a P2P link mismatch, and the test file currently has a syntax error (Compile/e2e are skipped).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Scheduler crashes due to panic in calculateGPUPairScore on P2P link mismatch

4 participants