Skip to content

feat: migrate from AST to import + inspect#265

Open
KAJdev wants to merge 5 commits intomainfrom
zeke/ae-2438-migrate-from-ast-walking-to-import-parse-objects-in-memory
Open

feat: migrate from AST to import + inspect#265
KAJdev wants to merge 5 commits intomainfrom
zeke/ae-2438-migrate-from-ast-walking-to-import-parse-objects-in-memory

Conversation

@KAJdev
Copy link
Contributor

@KAJdev KAJdev commented Mar 11, 2026

Replace AST-based resource discovery with runtime import scanning

the old scanner (RemoteDecoratorScanner, ResourceDiscovery) used Python's AST module to statically parse source files and find @remote decorated functions and resource configurations. This worked for simple cases but broke on any dynamic Python pattern (computed decorators, conditional definitions, programmatic resource construction, class inheritance, etc.)

this approach imports each user module via importlib and inspects live objects. The @remote decorator and Endpoint class stamp a __remote_config__ dict on decorated functions, so the scanner just walks module members looking for that attribute. this means anything that runs at import time is discovered correctly, regardless of how it was constructed.

How it works

RuntimeScanner in scanner.py:

  1. Collects .py files in the project (respecting .flashignore)
  2. Imports each file as a module via importlib.util
  3. Walks module members for __remote_config__ attributes
  4. Extracts RemoteFunctionMetadata from the live objects (resource config, function signature, dependencies, paths)
  5. Runs a lightweight AST pass on function bodies only for cross-call analysis (detecting when one @remote function calls another)

Import failures are collected and surfaced clearly in both flash run and flash deploy. Syntax errors, missing dependencies, and validation errors (e.g. forgetting name= on a load-balanced endpoint) show the filename and error message. The build stops immediately on fatal errors instead of silently continuing with zero discovered functions.

Fixes AE-2321

Other fixes bundled in

  • idleTimeout missing from deploy pipeline: _extract_config_properties() in manifest.py and create_resource_from_manifest() in resource_provisioner.py were not passing idleTimeout through, so all endpoints got the default 60s regardless of what the user specified.
  • _wrapped_class on RemoteClassWrapper: Added a class-level attribute so the scanner can recover the original class name and method definitions from wrapped classes.

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 migrates Flash’s project scanning and resource discovery from AST-based parsing to runtime importing + object inspection, enabling detection of dynamically constructed endpoints/resources while also fixing missing idleTimeout propagation.

Changes:

  • Replace RemoteDecoratorScanner/ResourceDiscovery patterns with RuntimeScanner-driven import+inspect scanning across build/run flows.
  • Update Endpoint to support nameless QB decorator mode (derive name from decorated target) while requiring name/id only for image= client mode and enforcing name for LB route registration.
  • Propagate idleTimeout through manifest generation and runtime provisioning; update/trim tests accordingly.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/unit/test_p2_remaining_gaps_2.py Updates scanner references from RemoteDecoratorScanner to RuntimeScanner for empty-project behavior.
tests/unit/test_p2_remaining_gaps.py Updates nested-class/conditional scanning tests to use RuntimeScanner.
tests/unit/test_p2_gaps.py Updates docstring extraction test to use RuntimeScanner.
tests/unit/test_endpoint.py Adjusts validation expectations and adds coverage for nameless QB decorator mode.
tests/unit/test_discovery_endpoint.py Removes ResourceDiscovery endpoint pattern tests (scanner/discovery migration).
tests/unit/test_discovery.py Removes ResourceDiscovery unit tests (scanner/discovery migration).
tests/unit/cli/test_run.py Updates mocks for _scan_project_workers new return shape.
tests/unit/cli/commands/test_run_endpoint.py Updates _scan_project_workers call sites for new return shape.
tests/unit/cli/commands/test_run.py Updates _scan_project_workers call sites for new return shape.
tests/unit/cli/commands/test_build.py Updates test fixtures to construct valid Live* resources under runtime import scanning (adds name=).
tests/unit/cli/commands/build_utils/test_scanner_load_balancer.py Removes AST-scanner FastAPI detection tests (scanner migration).
tests/unit/cli/commands/build_utils/test_scanner_endpoint.py Removes AST-scanner Endpoint pattern tests (scanner migration).
tests/unit/cli/commands/build_utils/test_scanner.py Removes AST-scanner test suite (scanner migration).
tests/unit/cli/commands/build_utils/test_path_utilities.py Updates scanner import to RuntimeScanner for LB/QB flags and init exclusion tests.
tests/integration/test_lb_remote_execution.py Updates integration assertions for RuntimeScanner and name normalization (-fb suffix).
tests/integration/test_build_pipeline.py Updates scanner import and expected resource naming (-fb suffix); minor docstring normalization.
src/runpod_flash/runtime/resource_provisioner.py Passes idleTimeout from manifest into deployment kwargs.
src/runpod_flash/execute_class.py Adds _wrapped_class to RemoteClassWrapper for scanner/introspection to recover original class metadata.
src/runpod_flash/endpoint.py Allows nameless QB decorator mode (derive name in __call__), tightens LB route validation, clarifies image-mode requirement.
src/runpod_flash/core/discovery.py Removes AST-based ResourceDiscovery implementation.
src/runpod_flash/cli/commands/run.py Switches runtime worker scan/discovery to import+inspect; surfaces scanner import errors; updates worker scanning API.
src/runpod_flash/cli/commands/build_utils/scanner.py Introduces RuntimeScanner import+inspect discovery with AST-only cross-call analysis pass.
src/runpod_flash/cli/commands/build_utils/manifest.py Ensures idleTimeout is included in manifest resource config extraction.
src/runpod_flash/cli/commands/build.py Uses RuntimeScanner in build; prints import failures and exits when none are discovered.

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

You can also share your feedback on Copilot code review. Take the survey.

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