serverless: sanitize concurrency_modifier output in JobScaler#476
Open
StanByriukov02 wants to merge 1 commit intorunpod:mainfrom
Open
serverless: sanitize concurrency_modifier output in JobScaler#476StanByriukov02 wants to merge 1 commit intorunpod:mainfrom
StanByriukov02 wants to merge 1 commit intorunpod:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the serverless worker’s JobScaler against invalid values returned by a user-provided concurrency_modifier, preventing runtime crashes during scheduling/queue sizing (as described in issue #458).
Changes:
- Add defensive handling in
JobScaler.set_scale()to catchconcurrency_modifierexceptions and sanitize the resulting concurrency value. - Introduce
_sanitize_concurrency()to coerce/validate concurrency to an integer>= 1. - Add unit tests covering several invalid
concurrency_modifierreturn values.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
runpod/serverless/modules/rp_scale.py |
Wraps concurrency_modifier calls with exception handling and sanitizes the updated concurrency value. |
tests/test_serverless/test_modules/test_rp_scale_concurrency_validation.py |
Adds tests for invalid concurrency modifier outputs and a valid-value baseline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+8
to
+11
| def test_concurrency_modifier_none_defaults_to_one(self): | ||
| scaler = JobScaler({"concurrency_modifier": lambda _: None}) | ||
| asyncio.run(scaler.set_scale()) | ||
| self.assertEqual(scaler.current_concurrency, 1) |
| scaler = JobScaler({"concurrency_modifier": lambda _: 4}) | ||
| asyncio.run(scaler.set_scale()) | ||
| self.assertEqual(scaler.current_concurrency, 4) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
This PR hardens JobScaler scaling when a user-provided concurrency_modifier returns an invalid value (None / 0 / negative / non-int), preventing crashes like:
TypeError: '<' not supported between instances of 'int' and 'NoneType'
It validates/coerces the value to a safe int >= 1 and adds unit tests for the invalid-value cases.
Related: #458