Skip to content

fix: reject negative resource slot quantity#11365

Merged
HyeockJinKim merged 2 commits intomainfrom
fix/reject-negative-resource-slot-quantity
Apr 28, 2026
Merged

fix: reject negative resource slot quantity#11365
HyeockJinKim merged 2 commits intomainfrom
fix/reject-negative-resource-slot-quantity

Conversation

@HyeockJinKim
Copy link
Copy Markdown
Collaborator

Summary

  • Negative values for resource slots (e.g. cpu: -1) previously slipped past ResourceSlot.from_user_input / from_policy and were only rejected by the scheduler later in the pipeline.
  • Add a finite-negative guard to ResourceSlot._normalize_value so the API boundary fails fast with HTTP 400 via the new InvalidResourceSlotQuantity exception (BackendAIError + web.HTTPBadRequest).
  • inf ("unlimited") semantics preserved by gating the check on is_finite().

Test plan

  • pants test tests/unit/common/test_types.py (added 3 negative-rejection tests)
  • pants test --changed-since=HEAD --changed-dependents=transitive (all dependent tests pass)
  • pants fmt / lint / check clean
  • Manually verify v2 deployment / legacy service create with cpu: -1 returns HTTP 400 instead of being scheduled

…e_value

Negative values for resource slots (e.g. cpu: -1) previously passed
through ResourceSlot.from_user_input/from_policy without complaint and
were only rejected later by the scheduler. Add a finite-negative check
to _normalize_value so the API boundary fails fast with HTTP 400 via
the new InvalidResourceSlotQuantity exception. Positive infinity
("unlimited") semantics are preserved by gating the check on
is_finite().
Copilot AI review requested due to automatic review settings April 28, 2026 03:10
@github-actions github-actions Bot added size:M 30~100 LoC comp:common Related to Common component labels Apr 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR makes the API reject negative resource slot quantities earlier (at ResourceSlot._normalize_value) by introducing a dedicated InvalidResourceSlotQuantity HTTP 400 error, with accompanying unit tests.

Changes:

  • Add InvalidResourceSlotQuantity (BackendAIError + web.HTTPBadRequest) for negative slot quantities.
  • Enforce a finite-negative guard in ResourceSlot._normalize_value.
  • Add unit tests to ensure negative quantities are rejected.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/unit/common/test_types.py Adds unit tests asserting negative resource slot quantities raise InvalidResourceSlotQuantity.
src/ai/backend/common/types.py Adds finite-negative validation in ResourceSlot._normalize_value and wires in the new exception.
src/ai/backend/common/exception.py Introduces InvalidResourceSlotQuantity as a structured HTTP 400 Backend.AI error.
changes/11365.fix.md Adds a changelog entry describing the new early rejection behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


class InvalidResourceSlotQuantity(BackendAIError, web.HTTPBadRequest):
error_type = "https://api.backend.ai/probs/invalid-resource-slot-quantity"
error_title = "Invalid resource slot quantity."


def test_resource_slot_rejects_negative_bytes() -> None:
with pytest.raises(InvalidResourceSlotQuantity, match="cannot be negative"):
@HyeockJinKim HyeockJinKim merged commit 3a89c9e into main Apr 28, 2026
33 checks passed
@HyeockJinKim HyeockJinKim deleted the fix/reject-negative-resource-slot-quantity branch April 28, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:common Related to Common component size:M 30~100 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants