Skip to content

feat(apps): run prebuilt worker images as queue endpoints - #804

Open
deanq wants to merge 1 commit into
mainfrom
deanq/SLS-1191-worker-image-resource
Open

deanq wants to merge 1 commit into
mainfrom
deanq/SLS-1191-worker-image-resource

Conversation

@deanq

@deanq deanq commented Dec 4, 2026

Copy link
Copy Markdown
Member

What

Adds App.worker_image(...), which deploys an existing worker image as a queue endpoint without a decorated function. The image's own handler serves the jobs. args replaces the image's start command; leave it out to keep the image's own.

echo = app.worker_image(
    name="echo",
    image="runpod/mock-worker:latest",
    args="python3 -u /handler.py --generator",
    gpu="ADA_24",
    workers=(0, 3),
)

echo.remote(mock_return="hello")

The returned handle has the queue surface: remote, spawn, stream, job, with_options. Keyword arguments become the job input as plain {"input": kwargs}, which is the shape a standard runpod.serverless handler reads. rp flash dev, rp flash deploy and rp flash undeploy manage it like any other queue resource.

Why

Before 2.x, a prebuilt worker image could be deployed as an endpoint directly. The runpod.apps model only supported decorated functions run through the Flash runtime, so there was no way to put an existing worker image on an endpoint from an app.

How

  • ResourceSpec gains image_only and docker_args. Validation: image-only resources must be queues and need a non-blank image, and docker_args is only allowed on image-only resources.
  • Deploy and dev payloads skip the runtime launcher and RUNPOD_RUNTIME_KIND for image-only resources and set dockerArgs from args (empty keeps the image command).
  • Dev sessions do not inject RUNPOD_API_KEY into image-only resources, since the image is not the Flash runtime and does not need the account key.
  • LiveTarget has a raw mode that returns worker output unchanged instead of unwrapping the Flash result envelope.
  • The Queue stub now resolves its target through an async _resolve_target() hook, which WorkerImageHandle overrides to resolve through the app (deployed target, or the dev live target).
  • The manifest entry carries imageOnly and dockerArgs.

Test plan

  • tests/test_apps/test_worker_image.py: registration and validation, deploy and dev payloads, manifest fields, no account key in dev, raw live target, remote/spawn/with_options payloads, resolution through the app, sync remote
  • ruff and mypy clean
  • Live run against a real endpoint (not run yet)

The current main CI failure (opentelemetry-api 1.46 deprecates opentelemetry._logs, which pytest's filterwarnings=error turns into collection errors in 3 test files) affects this branch too. It is unrelated to this change.

App.worker_image declares an existing worker image as a queue endpoint
with no decorated function. The image's own handler serves jobs; args
replaces its start command. Calls send plain {"input": kwargs}.

- ResourceSpec gains image_only and docker_args, validated
- deploy and dev skip the runtime launcher for image-only resources
- dev does not hand RUNPOD_API_KEY to the image
- LiveTarget raw mode returns worker output unchanged
- Queue stub resolves its target through an overridable hook

SLS-1191
Copilot AI balanced review requested due to automatic review settings December 4, 2026 21:55
@deanq deanq self-assigned this Dec 4, 2026
@deanq
deanq requested a review from KAJdev December 4, 2026 21:55
Comment thread runpod/apps/app.py
from .errors import EndpointNotFound, InvalidResourceError
from .gpu import GpuLike
from .handles import ApiHandle, FunctionHandle
from .handles import ApiHandle, FunctionHandle, WorkerImageHandle
Comment thread runpod/apps/app.py
from .errors import EndpointNotFound, InvalidResourceError
from .gpu import GpuLike
from .handles import ApiHandle, FunctionHandle
from .handles import ApiHandle, FunctionHandle, WorkerImageHandle
Comment thread runpod/apps/app.py
from .errors import EndpointNotFound, InvalidResourceError
from .gpu import GpuLike
from .handles import ApiHandle, FunctionHandle
from .handles import ApiHandle, FunctionHandle, WorkerImageHandle

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.

🟡 Changes recommended

Streaming and nested calls still mishandle raw worker outputs, while image-only resources can cause bundled Torch to shadow GPU images’ CUDA-compatible version.

3 open issues
What changed in this PR

Adds App.worker_image() to run prebuilt worker images as queue endpoints within the existing app lifecycle.

Changes:

  • Adds worker-image registration, validation, and queue handles.
  • Updates deploy/dev payloads and introduces raw worker-output handling.
  • Documents the API and adds focused tests.
File Description
tests/​test_apps/​test_worker_image.py Tests registration, payloads, and invocation.
runpod/​apps/​targets.py Adds raw output mode.
runpod/​apps/​stubs.py Adds overridable target resolution and cloning.
runpod/​apps/​spec.py Validates and serializes image-only settings.
runpod/​apps/​handles.py Adds WorkerImageHandle.
runpod/​apps/​dev.py Configures image-only endpoints without account-key injection.
runpod/​apps/​deploy.py Preserves or overrides image startup commands.
runpod/​apps/​app.py Adds App.worker_image() registration.
runpod/​apps/​__init__.py Exports the new handle.
README.md Documents worker-image usage.

Review effort: Balanced

Comment thread runpod/apps/app.py
mounts=mounts,
env=env,
datacenter=datacenter,
image=image,
Comment thread runpod/apps/handles.py
async def _resolve_target(self):
if in_discovery():
raise DiscoveryInvocationError(self.spec.name)
return await self._app._resolve(self.spec)
Comment thread runpod/apps/targets.py
Comment on lines +760 to +761
if self.raw:
return output

@KAJdev KAJdev left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This API feels weird to me, Stubs already exist and are the better fit here, something like:

app = App("inference")

endpoint = Queue(
    app=app,
    name="endpoint",
    image="someones/worker:latest",
    gpu="ADA_24",
    workers=(0, 3),
)

endpoint.remote()

which extends the current stub api with an image parameter that would change the target to an actual deployed endpoint

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants