flyte icon indicating copy to clipboard operation
flyte copied to clipboard

[BUG] [v2] `flyte deploy` never records `_F_SYS_PATH`, breaking code-bundle imports under `src/`

Open earlybard opened this issue 4 months ago • 2 comments

Describe the bug

The deploy command docs document sys.path synchronization as the default behavior of flyte deploy:

Default behavior (path synchronization enabled): Flyte captures local sys.path entries that are under the root directory. These paths are passed to the remote container via the _F_SYS_PATH environment variable. At runtime, the remote container adds these paths to its sys.path, maintaining the same import environment.

This is not implemented. The deploy code path never computes or records _F_SYS_PATH; only the run path does.

flyte run and flyte deploy handle code-bundle import paths asymmetrically:

  • run: the client computes _F_SYS_PATH from the local sys.path and injects it as a run-level env var — _RunLauncher._build_env_dict in flyte/_run.py:

    # These paths will be appended to sys.path at runtime.
    if cfg.sync_local_sys_paths:
        root_dir_abs = pathlib.Path(cfg.root_dir).resolve()
        env[FLYTE_SYS_PATH] = ":".join(
            f"./{pathlib.Path(p).relative_to(root_dir_abs)}"
            for p in sys.path
            if pathlib.Path(p).is_relative_to(root_dir_abs)
        )
    
  • deploy: nothing equivalent exists. flyte/_deploy.py, task_serde.py, and trigger_serde.py never reference sync_local_sys_paths or FLYTE_SYS_PATH; translate_task_to_wire serializes only the user-declared env_vars into container.env. The deployed task spec and its triggers carry no record of the sys.path entries the code bundle needs.

At runtime, adjust_sys_path (flyte/_utils/module_loader.py) puts only ., the code-bundle destination, and whatever _F_SYS_PATH contains onto sys.path. For a client-launched run, _F_SYS_PATH arrives via the run envs and imports work. For a run of a deployed task fired by a trigger/schedule, there is no client, _F_SYS_PATH is unset, and only the bundle root is importable.

Note flyte deploy even accepts --no-sync-local-sys-paths and stores it in the init config, but the deploy code path never reads it — the flag is a no-op, suggesting this was intended but never wired up.

Consequence

Any project with a src/ layout (the uv init --lib default and standard modern packaging) using a with_uv_project image is broken for scheduled runs: project_install_mode defaults to dependencies_only, so the project's own package exists only in the code bundle at ./src/<pkg>. flyte run injects _F_SYS_PATH=./src:... and works; the identical deployed task fired by a Cron trigger fails every time with ModuleNotFoundError: No module named '<pkg>'. The workaround is to compute the paths yourself and set TaskEnvironment(env_vars={"_F_SYS_PATH": ...}) — verified to reach the pod on trigger-fired runs. (Trigger(env_vars=...) does not reach the pod; reported separately.)

Steps to reproduce

  1. uv init --lib myproj (code lands in src/myproj/), add a task:

    # src/myproj/wf.py
    import flyte
    from myproj import hello  # any first-party import
    
    env = flyte.TaskEnvironment(
        "myproj",
        image=flyte.Image.from_debian_base().with_uv_project("pyproject.toml"),
    )
    
    @env.task(triggers=flyte.Trigger("minutely", automation=flyte.Cron("* * * * *")))
    async def main() -> str:
        return hello()
    
  2. flyte run src/myproj/wf.py main — succeeds; the run's env shows _F_SYS_PATH=./src:....

  3. flyte deploy src/myproj/wf.py env and wait for the trigger to fire — the run fails with ModuleNotFoundError: No module named 'myproj'. The run has no _F_SYS_PATH.

Expected behavior

deploy should capture the same bundle-relative sys.path entries run computes (the code bundle is built from the same workspace, so they're known at deploy time) and persist them in the deployed task so every run of the task — trigger-fired or otherwise — resolves imports identically to flyte run.

Environment

  • flyte SDK 2.5.9 (Python 3.14), self-hosted Flyte v2 backend

earlybard avatar Jul 20 '26 04:07 earlybard

You are correct: according to the deploy command documentation, the default behavior should synchronize local sys.path entries to the remote container via the _F_SYS_PATH environment variable. However, the deploy code path does not actually compute or record _F_SYS_PATH; only the run path does. This means that deployed tasks triggered by schedules or triggers lack the necessary sys.path configuration, leading to import errors for code-bundle packages under src/—as you described.

This is a known gap: while flyte run injects _F_SYS_PATH and imports work, flyte deploy does not, so scheduled or triggered runs fail unless you manually set env_vars={"_F_SYS_PATH": ...} in the TaskEnvironment. The --no-sync-local-sys-paths flag is present but not functional in the deploy path, confirming this is an unimplemented feature. See deploy command options and the relevant code in flyte/_run.py for details.

Would you like a step-by-step breakdown of the technical root cause or possible workarounds?

Sources:


This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not.

Mention @herald to ask follow-up questions. See runllm.com for more!

runllm avatar Jul 20 '26 04:07 runllm

Hi, I'd like to work on this. I'll submit a PR shortly.

nightcityblade avatar Jul 22 '26 03:07 nightcityblade