Skip to content

[Bugfix] Handle absent BestFit constraints - #1204

Open
gbwzzy218 wants to merge 2 commits into
ome-projects:mainfrom
gbwzzy218:fix/bestfit-nil-constraints
Open

gbwzzy218 wants to merge 2 commits into
ome-projects:mainfrom
gbwzzy218:fix/bestfit-nil-constraints

Conversation

@gbwzzy218

@gbwzzy218 gbwzzy218 commented Oct 7, 2026 •

Copy link
Copy Markdown

What this PR does

Treats omitted constraints the same as an explicitly empty constraints object during BestFit scoring. This prevents nil-pointer panics in the memory and compute scoring helpers without changing scoring weights, candidate filtering, precision fallback, or tie handling. The caller’s configuration is not modified.

Adds regression tests for both helpers and the public GetAcceleratorClass path with multiple candidates, covering omitted and empty constraints with and without performance data.

Why we need it

BestFit selection without constraints panics when multiple candidates reach scoring. Zero- and single-candidate paths return before scoring and do not reproduce the issue.

Fixes #627

How to test

Run the selector tests and static checks:

go test -race -count=1 ./pkg/acceleratorclassselector
go vet ./pkg/acceleratorclassselector

TestBestFitWithoutConstraints exercises the public selection path with multiple candidates, omitted and empty constraints, and both missing and positive performance data. The helper regression tests reproduce the memory and compute nil-pointer panics on the base revision.

For full CI validation, run make test and make coverage with the required Rust/Xet and envtest dependencies installed.

Validation:

  • Regression tests reproduce both panics before the fix and pass afterward
  • All 24 selector-package top-level tests pass with the race detector; package vet, pinned lint, formatting, and diff checks pass
  • Related consumer race suites and selected broader non-race suites also pass
  • Full make test passes locally on macOS arm64 with Go 1.26.0, Rust 1.99.0, and Kubernetes 1.30.3 envtest binaries, including the Xet-dependent cmd/ome-agent tests. Xet was built from the existing Cargo.lock revision db2a0e722bcd80ea7f5cf339a0b550d01e6321b2.
  • make coverage passes the default 50% gate: CMD 40.8%, PKG 83.8%, Internal 71.1%; average 65.23%.
  • No live-cluster or GPU validation was performed

Checklist

  • Tests added/updated
  • Docs updated (not applicable; no API or configuration schema change)
  • make test passes locally

Summary by CodeRabbit

  • Bug Fixes
    • Best-fit accelerator selection now handles omitted or empty constraints without errors. Candidates with available performance data are scored and can be preferred, while candidates without it remain eligible.
    • When memory requirements are not specified, candidates receive a full memory fit score. Performance data is also scored correctly when compute constraints are omitted, helping selection compare available candidates consistently.

Treat omitted constraints as empty during BestFit scoring.
Cover both scoring helpers and multi-candidate public selection.

Signed-off-by: Zhenyu Zhu <25193860+gbwzzy218@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 304ae9d8-23b1-4587-b92e-b653de167a28
📥 Commits

Reviewing files that changed from the base of the PR and between 6b9aa26 and 819db58.

📒 Files selected for processing (1)
  • pkg/acceleratorclassselector/bestfit_constraints_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/acceleratorclassselector/bestfit_constraints_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The BestFit memory and compute scoring helpers now handle nil constraints. Tests cover scoring and candidate selection when constraints are omitted or empty.

Changes

BestFit nil-constraint handling

Layer / File(s) Summary
Nil-constraint scoring and selection
pkg/acceleratorclassselector/policy_helpers.go, pkg/acceleratorclassselector/bestfit_constraints_test.go
The memory score returns 1 when constraints or MinMemory are nil. The compute score replaces nil constraints with empty constraints after checking for missing performance data. Tests cover scoring and candidate selection with omitted or empty constraints.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 819db

The supplied changes show no actionable merge-blocking risk; merge after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #627 requires that BestFit without constraints does not panic. The change gives nil memory constraints a valid score and initializes nil compute constraints before scoring. The added public sele…
Out of Scope Changes check ✅ Passed The changes are limited to BestFit scoring nil handling and focused regression tests in pkg/acceleratorclassselector. They support issue #627 and do not change scoring weights, candidate filtering, pr…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing failures when BestFit constraints are absent.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions github-actions Bot added accelerator Accelerator class changes tests Test changes labels Oct 7, 2026
@gbwzzy218
gbwzzy218 marked this pull request as ready for review October 7, 2026 20:28
Signed-off-by: Zhenyu Zhu <25193860+gbwzzy218@users.noreply.github.com>

This branch has not been deployed

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

Labels

accelerator Accelerator class changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] BestFit accelerator policy without constraints causes controller panic

1 participant