Skip to content

serverless: sanitize concurrency_modifier output in JobScaler#476

Open
StanByriukov02 wants to merge 1 commit intorunpod:mainfrom
StanByriukov02:fix-jobscaler-concurrency
Open

serverless: sanitize concurrency_modifier output in JobScaler#476
StanByriukov02 wants to merge 1 commit intorunpod:mainfrom
StanByriukov02:fix-jobscaler-concurrency

Conversation

@StanByriukov02
Copy link

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

@deanq deanq requested a review from Copilot March 18, 2026 22:08
Copy link

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

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 catch concurrency_modifier exceptions and sanitize the resulting concurrency value.
  • Introduce _sanitize_concurrency() to coerce/validate concurrency to an integer >= 1.
  • Add unit tests covering several invalid concurrency_modifier return 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)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants