fix(deploy): class-based @remote handler with smart method dispatch#245
fix(deploy): class-based @remote handler with smart method dispatch#245
@remote handler with smart method dispatch#245Conversation
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
runpod-Henrik
left a comment
There was a problem hiding this comment.
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_nameviagetattrinstead of calling the class as a function - Strips
method_namefrom 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
@remote handler with smart method dispatch
Summary
flash deployfor class-based@remoteby generating a handler that dispatches to methods by name instead of callingMyClass(**job_input)method_nameneeded)__call__(requires explicitmethod_namefor routing)class_methodsfrom scanner metadata into manifest function entriesChanges
handler_generator.py: AddDEPLOYED_CLASS_HANDLER_TEMPLATEwith{default_method}placeholder; compute default fromclass_methodscountmanifest.py: Includeclass_methodsin manifest function entries whenis_class=TruePayload consistency
Swagger UI (
flash run) — single method classDeployed endpoint (
flash deploy) — single method classNo
method_nameneeded — default inferred from single public method.Deployed endpoint — multi-method class
Test plan
make quality-checkpasses (format, lint, coverage)method_name