Skip to content

fix(scheduler): guard against zero-value division in ComputeScore (#1… - #1820

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
lin121291:fix/scheduler-compute-score-panic
May 6, 2026
Merged

fix(scheduler): guard against zero-value division in ComputeScore (#1…#1820
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
lin121291:fix/scheduler-compute-score-panic

Conversation

@lin121291

Copy link
Copy Markdown

What type of PR is this?

bug

What this PR does / why we need it:

ComputeScore (gpu_policy.go:78-80) and ComputeDefaultScore
(node_policy.go:90-92) divide by device capacity fields (Count,
Totalcore, Totalmem) without zero-checks. When any field is 0,
float32 division produces NaN/Inf, which breaks sort.Sort's
total-ordering requirement — causing an index-out-of-range panic
that kills the entire scheduler extender process.

Since the offending pod stays Pending, kube-scheduler retries it on
every restart, creating a CrashLoopBackOff loop that halts all GPU
scheduling cluster-wide.

This PR adds zero-value guards to both functions so they return
score 0 instead of panicking, letting the scheduler gracefully
mark devices/nodes as unschedulable.

Note: fitInDevices already guards against "request more GPUs than
the node has" at score.go:65, but that check runs after
ComputeScore. The trigger is a device reporting zero-value
capacity, not an empty device list.

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

Special notes for your reviewer:

  • ComputeDefaultScore in node_policy.go has the same unguarded
    division pattern — fixed in this PR as well
  • Unit tests added for both zero-capacity scenarios
  • This PR was written with assistance from Claude Code

Does this PR introduce a user-facing change?:

Scheduler no longer panics when a device reports zero-value capacity
fields. Pods that cannot be satisfied are correctly marked as
unschedulable instead of crashing the scheduler.

…oject-HAMi#1780)

ComputeScore and ComputeDefaultScore divide by device capacity fields
(Count, Totalcore, Totalmem) without zero-checks. When any field is 0,
float32 division produces NaN/Inf, which breaks sort.Sort's ordering
requirement and causes an index-out-of-range panic — crashing the
entire scheduler extender and halting all GPU scheduling cluster-wide.

Return score 0 for devices/nodes with zero capacity so the scheduler
can gracefully mark them as unschedulable instead of panicking.

Signed-off-by: lin121291 <4jp33f9e@gmail.com>
@hami-robot

hami-robot Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Welcome @lin121291! It looks like this is your first PR to Project-HAMi/HAMi 🎉

@github-actions github-actions Bot added the kind/bug Something isn't working label Apr 29, 2026
@hami-robot hami-robot Bot added the size/M label Apr 29, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces safety checks in the GPU and node policy scoring functions to prevent division-by-zero errors when device capacity metrics are zero. It also includes comprehensive unit tests covering these edge cases. A review comment suggests an additional nil-pointer check for the device object to further enhance the robustness of the scoring logic.

Comment thread pkg/scheduler/policy/gpu_policy.go Outdated
@archlitchi

Copy link
Copy Markdown
Member

please resolve the AI comments

@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 58.04% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/scheduler/policy/gpu_policy.go 100.00% <100.00%> (ø)
pkg/scheduler/policy/node_policy.go 85.00% <100.00%> (+1.21%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: lin121291 <4jp33f9e@gmail.com>
@lin121291
lin121291 force-pushed the fix/scheduler-compute-score-panic branch from 1741e5b to e50c98a Compare April 30, 2026 08:15

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

/lgtm

@hami-robot hami-robot Bot added the lgtm label May 6, 2026
@hami-robot

hami-robot Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lin121291, Shouren

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

The pull request process is described 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 added the approved label May 6, 2026
@hami-robot
hami-robot Bot merged commit 1c5069e into Project-HAMi:master May 6, 2026
6 checks passed
mesutoezdil pushed a commit to mesutoezdil/HAMi that referenced this pull request Jun 14, 2026
…oject-HAMi#1… (Project-HAMi#1820)

* fix(scheduler): guard against zero-value division in ComputeScore (Project-HAMi#1780)

ComputeScore and ComputeDefaultScore divide by device capacity fields
(Count, Totalcore, Totalmem) without zero-checks. When any field is 0,
float32 division produces NaN/Inf, which breaks sort.Sort's ordering
requirement and causes an index-out-of-range panic — crashing the
entire scheduler extender and halting all GPU scheduling cluster-wide.

Return score 0 for devices/nodes with zero capacity so the scheduler
can gracefully mark them as unschedulable instead of panicking.

Signed-off-by: lin121291 <4jp33f9e@gmail.com>

* fix(scheduler): add nil check for Device pointer in ComputeScore

Signed-off-by: lin121291 <4jp33f9e@gmail.com>

---------

Signed-off-by: lin121291 <4jp33f9e@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vgpu-scheduler-extender panics in ComputeScore when no node can satisfy pod GPU request — cluster-wide GPU scheduling goes down

3 participants