Skip to content

feat: SLS-494 run users' worker initialization code - #567

Draft
jasonwang-runpod wants to merge 4 commits into
mainfrom
jasonwang/sls-494-sdk-initializer
Draft

feat: SLS-494 run users' worker initialization code#567
jasonwang-runpod wants to merge 4 commits into
mainfrom
jasonwang/sls-494-sdk-initializer

Conversation

@jasonwang-runpod

@jasonwang-runpod jasonwang-runpod commented Aug 13, 2026

Copy link
Copy Markdown

A worker whose model load or engine start fails or hangs should fail fast and report the error.

This PR adds an optional initializer and init_timeout to the serverless config. The SDK runs it before the worker takes any job. On failure or timeout it:

  • Emits a structured init_failed log
  • Makes a best effort to report the failure reason to the platform
  • Exits non-zero, so existing mechanisms can respawn the worker.

Testing

  • Unit tests for sync and async initializers, error wrapping, timeout, and loop gating (the job loop starts only after init succeeds)

Add optional `initializer` and `init_timeout` to the serverless config.
The worker runs the initializer (e.g. model load / engine start) before
it starts taking jobs. On failure or timeout it emits a structured
`init_failed` log line, best-effort reports the reason to the platform,
and exits non-zero so the existing backoff respawns it — instead of a
broken worker sitting silently IN_QUEUE until the request times out.

Opt-in and a no-op when no initializer is configured.
Sync and async initializers, InitializerError wrapping, init_timeout via
SIGALRM, loop-gating (the job loop starts only after init succeeds), the
init_failed payload shape, and the best-effort POST URL derivation.
Comment thread tests/test_serverless/test_initializer.py Fixed
Comment thread tests/test_serverless/test_initializer.py Fixed

Copilot AI 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.

Pull request overview

This PR introduces a supervised startup phase for serverless workers by adding an optional initializer callable and init_timeout to the serverless worker config, ensuring model/engine startup failures (or hangs) are surfaced quickly and the worker exits before taking jobs.

Changes:

  • Added rp_initializer module to run an initializer with timeout handling, structured init_failed logging, and best-effort platform reporting.
  • Updated the worker startup sequence to run initialization before starting the job loop.
  • Added unit tests covering sync/async initializers, error wrapping, timeouts, reporting, and job-loop gating.

Reviewed changes

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

File Description
tests/test_serverless/test_initializer.py Adds unit tests for initializer execution, failure/timeout behavior, reporting, and gating before the job loop.
runpod/serverless/worker.py Runs supervised initialization before starting the JobScaler/job loop.
runpod/serverless/modules/rp_initializer.py Implements supervised initializer execution, timeout/error wrapping, structured logging, and best-effort reporting.
runpod/serverless/init.py Documents new initializer and init_timeout config options in the serverless start() docstring.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread runpod/serverless/modules/rp_initializer.py
Comment thread runpod/serverless/modules/rp_initializer.py Outdated
Comment thread runpod/serverless/modules/rp_initializer.py Outdated
@jasonwang-runpod

Copy link
Copy Markdown
Author

bugbot run

- detect functools.partial and async __call__ initializers (were run on the
  sync path and never awaited, silently skipping init)
- catch Exception, not BaseException, so KeyboardInterrupt/SystemExit from
  user code propagate instead of being reported as init failures
- use a single unittest import style (CodeQL)
@jasonwang-runpod jasonwang-runpod changed the title feat: SLS-494 supervised initializer for serverless workers feat: SLS-494 run users' worker initialization code Aug 14, 2026
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