Skip to content

fix(device): use len(devices) for GenReason in kunlun and awsneuron - #2292

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
blackdragoon26:fix/genreason-len-devices-kunlun-awsneuron
Aug 4, 2026
Merged

fix(device): use len(devices) for GenReason in kunlun and awsneuron#2292
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
blackdragoon26:fix/genreason-len-devices-kunlun-awsneuron

Conversation

@blackdragoon26

@blackdragoon26 blackdragoon26 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:

Kunlun XPU, Kunlun VXPU, and one AWS Neuron Fit failure path called common.GenReason(reason, len(reason)), so the denominator was the number of reason keys (usually 1) instead of candidate devices. That produced strings like 1/1 NumaNotFit instead of 1/8 NumaNotFit.
Other backends already use len(devices) after #2238; the AWS Neuron single-device fail path in the same file already did too. This PR updates the three remaining call sites and adds unit coverage.

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

Special notes for your reviewer:

  • Reason-string only; no allocation-policy change.
  • Verified with go test ./pkg/device/kunlun/ ./pkg/device/awsneuron/ -count=1 -short and make verify.

Does this PR introduce a user-facing change?:
No

AI Assistance Disclosure: Used Cursor to help locate matching call sites and draft the initial test cases. I reviewed the change against the issue, ran the unit tests and make verify myself, and confirmed the reason-string behaviour before opening this PR.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected device allocation failure messages to report the total number of requested devices.
    • Improved NUMA-related allocation reasons for AWS Neuron and Kunlun devices.
    • Allocation conflicts now consistently report clear, accurate failure details.
  • Tests

    • Added coverage for multi-device and NUMA-incompatible allocation failures.
    • Strengthened validation of allocation conflict reasons.

Align Fit failure reason denominators with other backends so reports
reflect candidate card count rather than the number of reason keys.

Signed-off-by: blackdragoon26 <sankalp.jha9643@gmail.com>
@hami-robot
hami-robot Bot requested review from DSFans2014 and lengrongfu August 3, 2026 09:57
@github-actions github-actions Bot removed the kind/bug Something isn't working label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a17292d1-3752-4e8b-a39a-6af6c9effcb5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

AWS Neuron and Kunlun allocation failure reasons now use the total device count as the denominator. Tests cover NUMA-incompatible allocation and exact conflict reasons.

Changes

Device allocation failure reasons

Layer / File(s) Summary
Update failure reason generation
pkg/device/awsneuron/device.go, pkg/device/kunlun/device.go, pkg/device/kunlun/vdevice.go
Failure paths now pass the total device count to common.GenReason.
Add failure reason regression coverage
pkg/device/awsneuron/device_test.go, pkg/device/kunlun/device_test.go
Tests verify exact NUMA and mutex allocation failure reasons. The unused import was removed.

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

Possibly related PRs

Suggested reviewers: archlitchi

Poem

A rabbit counts cards in a row,
Now failure reasons clearly show.
NUMA says “one of two,”
Mutex conflicts state it true,
Clean tests guard the flow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #2291 by fixing all three GenReason call sites and adding unit assertions for corrected failure reasons.
Out of Scope Changes check ✅ Passed The changes are limited to the requested GenReason fixes, related tests, and removal of an unused import.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change to use len(devices) for GenReason in Kunlun and AWS Neuron.
✨ 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.

@hami-robot hami-robot Bot added the size/M label Aug 3, 2026
@blackdragoon26 blackdragoon26 changed the title Xfix(device): use len(devices) for GenReason in kunlun and awsneuron fix(device): use len(devices) for GenReason in kunlun and awsneuron Aug 3, 2026
@github-actions github-actions Bot added the kind/bug Something isn't working label Aug 3, 2026
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 60.88% <100.00%> (+0.22%) ⬆️

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

Files with missing lines Coverage Δ
pkg/device/awsneuron/device.go 76.05% <100.00%> (ø)
pkg/device/kunlun/device.go 18.48% <100.00%> (+7.56%) ⬆️
pkg/device/kunlun/vdevice.go 100.00% <100.00%> (+1.85%) ⬆️

... and 8 files with indirect coverage changes

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

@blackdragoon26
blackdragoon26 marked this pull request as ready for review August 3, 2026 10:21
@hami-robot
hami-robot Bot requested review from FouoF and mesutoezdil August 3, 2026 10:21
@coderabbitai
coderabbitai Bot requested a review from archlitchi August 3, 2026 10:21

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@pkg/device/awsneuron/device_test.go`:
- Around line 863-889: Update the “fit fail: NumaNotFit with multiple devices”
fixture so its devices have distinct DeviceUsage.Numa values rather than relying
on Index, and adjust the node-type/custom info and request fields to select a
graphSelect path that reaches NUMA-aware allocation for Nums == 2. Preserve the
expected 1/2 NumaNotFit result while ensuring the test genuinely exercises NUMA
incompatibility.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33b81add-9c2c-432b-8d6c-621bd2e18e02

📥 Commits

Reviewing files that changed from the base of the PR and between 85192de and 4ac93e8.

📒 Files selected for processing (5)
  • pkg/device/awsneuron/device.go
  • pkg/device/awsneuron/device_test.go
  • pkg/device/kunlun/device.go
  • pkg/device/kunlun/device_test.go
  • pkg/device/kunlun/vdevice.go

Comment thread pkg/device/awsneuron/device_test.go
Comment thread pkg/device/kunlun/vdevice.go
Signed-off-by: blackdragoon26 <sankalp.jha9643@gmail.com>
@blackdragoon26

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mesutoezdil

Copy link
Copy Markdown
Contributor

@CodeRabbit review

There is a limited number of tokens available for coderrabbit every day.
Please do not run this manually.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@mesutoezdil Understood. I will not run manual @CodeRabbit review actions on this pull request.


✏️ Learnings added
Learnt from: mesutoezdil
URL: https://github.com/Project-HAMi/HAMi/pull/2292

Timestamp: 2026-08-03T12:36:34.234Z
Learning: For Project-HAMi/HAMi pull requests, do not run manual `CodeRabbit review` actions. The repository has a limited daily CodeRabbit token budget. Use automatic reviews only unless a maintainer explicitly requests a manual review.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@archlitchi archlitchi 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 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, blackdragoon26

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 Aug 4, 2026
@hami-robot
hami-robot Bot merged commit bb0ddc9 into Project-HAMi:master Aug 4, 2026
17 checks passed
@blackdragoon26
blackdragoon26 deleted the fix/genreason-len-devices-kunlun-awsneuron branch August 4, 2026 08:52
Eshiv-Pandey added a commit to Eshiv-Pandey/HAMi that referenced this pull request Aug 4, 2026
Resolve conflict in pkg/device/awsneuron/device_test.go by keeping both
the CardNotHealth test case (ours) and the NumaNotFit with multiple
devices test case (theirs from Project-HAMi#2292). Apply makeAWSDeviceUsage helper
to the merged NumaNotFit case for consistency with the refactor.

Signed-off-by: Eshiv Pandey <eshivpandey18@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.

fix(device): GenReason uses len(reason) instead of len(devices) in kunlun/awsneuron

3 participants