Skip to content

Multi-file agent imports fail inside VM — package_agent only copies single source file #97

@tensor-ninja

Description

@tensor-ninja

Problem

package_agent() in src/nightshift/protocol/packaging.py only copies the single agent source file into the VM overlay at /opt/nightshift/agent_pkg/. If an agent imports sibling modules from the same project (e.g. from lib.helpers import foo), those imports fail inside the VM because the rest of the project tree was never injected.

This affects both code paths that provision VMs:

  • One-shot (run_task in task.py:64)
  • Pool cold-start (_cold_start in pool.py:210)

Why it's not caught today

All existing examples are single-file agents with no local imports — they only depend on PyPI packages (installed via uv pip install from pyproject.toml).

Root cause

The deploy CLI (deploy.py) correctly archives the entire project directory and the server stores it at storage_path. But when a run is triggered, _build_registered_agent() constructs a RegisteredAgent pointing into that tree, and then package_agent() throws away the context:

# packaging.py:42-43 — only copies the one file
source_filename = os.path.basename(module_path)
shutil.copy2(module_path, os.path.join(pkg_dir, source_filename))

The manifest module is set to just the basename (e.g. "main"), not a dotted path like "agents.main".

For deployed agents, skip package_agent() entirely. The full project tree already exists on disk at storage_path:

  1. Write manifest.json into storage_path at deploy time (in server.py, after extracting the archive)
  2. Pass storage_path directly as agent_pkg_path to the VM overlay instead of going through package_agent()

This avoids redundant copies and correctly makes all project modules available inside the VM. The one-shot run_task() path can be fixed separately if needed (by enhancing package_agent() to copy the full project tree).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions