Skip to content

fix(stubs): resolve in-function @remote imports for cross-endpoint dispatch#224

Merged
deanq merged 2 commits intomainfrom
fix/ae-2265-cross-endpoint-bug
Feb 26, 2026
Merged

fix(stubs): resolve in-function @remote imports for cross-endpoint dispatch#224
deanq merged 2 commits intomainfrom
fix/ae-2265-cross-endpoint-bug

Conversation

@deanq
Copy link
Member

@deanq deanq commented Feb 26, 2026

Summary

  • Fix dependency resolver to detect @remote functions imported inside function bodies (not just module-level)
  • Add resolve_in_function_imports() to discover @remote deps via in-body from X import Y statements
  • Add strip_remote_imports() to remove stale import statements from source sent to workers
  • Update both LiveServerlessStub and LoadBalancerSlsStub to use the new resolution pipeline

Root cause: Pipeline functions like classify() use from gpu_worker import gpu_inference inside the function body. The dependency resolver only checked func.__globals__ (module-level namespace), missing these imports entirely. No dispatch stubs were generated, causing ModuleNotFoundError on the remote worker.

Test plan

  • 16 new tests covering discovery, stripping, aliasing, and exec integration
  • All 1253 tests pass
  • 73.04% coverage (above 65% threshold)
  • Verified end-to-end with 03_mixed_workers via flash deploy --use-local-flash

…spatch

The dependency resolver only checked func.__globals__ (module-level namespace),
missing @Remote functions imported inside function bodies. Pipeline functions
like classify() that use `from gpu_worker import gpu_inference` inside the body
would fail with ModuleNotFoundError on the remote worker.

- Add resolve_in_function_imports() to discover @Remote deps via in-body imports
- Add strip_remote_imports() to remove stale import statements from sent source
- Update both LiveServerlessStub and LoadBalancerSlsStub to use new functions
- Add 16 tests covering discovery, stripping, aliasing, and exec integration
Copy link
Contributor

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 fixes a critical bug in the dependency resolver where @remote functions imported inside function bodies (rather than at module level) were not detected, causing ModuleNotFoundError on remote workers. The fix adds two new functions to discover and handle in-function imports:

Changes:

  • Added resolve_in_function_imports() to discover @remote dependencies via in-body from X import Y statements
  • Added strip_remote_imports() to remove stale import statements from source sent to workers
  • Updated both LiveServerlessStub and LoadBalancerSlsStub to use the new resolution pipeline

Reviewed changes

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

File Description
src/runpod_flash/stubs/dependency_resolver.py Adds resolve_in_function_imports() to detect in-function imports and strip_remote_imports() to remove them from source
src/runpod_flash/stubs/live_serverless.py Integrates new resolution pipeline: augment globals → resolve deps → strip imports → build stubs
src/runpod_flash/stubs/load_balancer_sls.py Integrates new resolution pipeline (same pattern as live_serverless.py)
tests/unit/test_dependency_resolver.py Adds 16 comprehensive tests covering discovery, stripping, aliasing, and exec integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… resolver

Address PR review feedback:
- Skip relative imports (module=None) in strip_remote_imports to avoid TypeError
- Preserve first discovered import when same name imported from multiple modules
- Add tests for both cases
@deanq deanq merged commit 7f168f7 into main Feb 26, 2026
6 checks passed
@deanq deanq deleted the fix/ae-2265-cross-endpoint-bug branch February 26, 2026 00:58
@promptless
Copy link

promptless bot commented Mar 23, 2026

📝 Documentation updates detected!

New suggestion: Add code example for cross-endpoint dispatch


Tip: Set up a GitHub Issues trigger in Projects to enable @Promptless mentions in issues 🐙

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