Skip to content

fix(deploy): class-based @remote handler with smart method dispatch#245

Open
deanq wants to merge 1 commit intomainfrom
deanq/ae-2306-flash-deploy-broken-for-class-based-remote
Open

fix(deploy): class-based @remote handler with smart method dispatch#245
deanq wants to merge 1 commit intomainfrom
deanq/ae-2306-flash-deploy-broken-for-class-based-remote

Conversation

@deanq
Copy link
Member

@deanq deanq commented Mar 4, 2026

Summary

  • Fix flash deploy for class-based @remote by generating a handler that dispatches to methods by name instead of calling MyClass(**job_input)
  • Single-method classes default to that method (payload matches Swagger UI exactly, no method_name needed)
  • Multi-method classes default to __call__ (requires explicit method_name for routing)
  • Propagate class_methods from scanner metadata into manifest function entries

Changes

  • handler_generator.py: Add DEPLOYED_CLASS_HANDLER_TEMPLATE with {default_method} placeholder; compute default from class_methods count
  • manifest.py: Include class_methods in manifest function entries when is_class=True
  • Tests: 6 handler generation tests + 3 manifest entry tests

Payload consistency

Swagger UI (flash run) — single method class

POST /worker/predict/runsync
Body: {"input": {"text": "hello"}}

Deployed endpoint (flash deploy) — single method class

POST /v2/{endpoint_id}/runsync
Body: {"input": {"text": "hello"}}

No method_name needed — default inferred from single public method.

Deployed endpoint — multi-method class

POST /v2/{endpoint_id}/runsync
Body: {"input": {"method_name": "predict", "text": "hello"}}

Test plan

  • All 2009 tests pass
  • make quality-check passes (format, lint, coverage)
  • Manual: generated handler for single-method class defaults to that method
  • Manual: generated handler for multi-method class requires method_name

Class-based @Remote deploy now generates a handler that dispatches to
methods by name instead of calling MyClass(**job_input). Single-method
classes default to that method (matching Swagger UI payload exactly),
multi-method classes default to __call__ requiring explicit method_name.

- Add class_methods to manifest function entries when is_class=True
- Add default_method param to DEPLOYED_CLASS_HANDLER_TEMPLATE
- Compute default from class_methods count in handler generator
- Add 6 tests for handler generation and 3 for manifest entries
Copy link
Contributor

@runpod-Henrik runpod-Henrik left a comment

Choose a reason for hiding this comment

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

Review by Henrik's AI-Powered Bug Finder

1. Class handler template — clean fix for AE-2306

The DEPLOYED_CLASS_HANDLER_TEMPLATE correctly:

  • Creates a module-level instance (_instance = MyModel())
  • Dispatches by method_name via getattr instead of calling the class as a function
  • Strips method_name from kwargs before passing to the method
  • Handles async methods with the same asyncio.run / thread pool pattern as the function template

Smart default logic is well-designed: single-method classes default to that method (matching Swagger UI payload), multi-method classes default to __call__.

2. Manifest propagation

class_methods correctly included only when is_class and class_methods — empty lists and non-class entries excluded. Tests cover all three cases.

3. Tests — good coverage

11 handler tests + 3 manifest tests covering instance creation, method dispatch, async handling, single/multi method defaults, syntax validation.

Nits

Nit 1 — pre-existing input=None bug carried forward

The new template has the same pattern as the function template:

job_input = job.get("input", {})

If job["input"] is explicitly None, .get() returns None (not {}), and job_input.get("method_name", ...) crashes with AttributeError. Fix: job_input = job.get("input") or {}. Not introduced by this PR, but worth fixing in both templates.

Nit 2 — __call__ default for multi-method classes

If a class has ["predict", "embed"] but no __call__, the default dispatches to a non-existent method. The except AttributeError returns a good error, but could hint at available methods to save the user a round-trip.

Verdict

PASS — Clean fix for AE-2306 (class-based @remote deploy handler). Smart method dispatch logic is correct, test coverage is solid. Two pre-existing/cosmetic nits.

🤖 Reviewed by Henrik's AI-Powered Bug Finder

@deanq deanq changed the title fix(deploy): class-based @remote handler with smart method dispatch fix(deploy): class-based @remote handler with smart method dispatch Mar 5, 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.

2 participants