[BUG] [v2] `flyte deploy` never records `_F_SYS_PATH`, breaking code-bundle imports under `src/`
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_PATHenvironment 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_PATHfrom the localsys.pathand injects it as a run-level env var —_RunLauncher._build_env_dictinflyte/_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, andtrigger_serde.pynever referencesync_local_sys_pathsorFLYTE_SYS_PATH;translate_task_to_wireserializes only the user-declaredenv_varsintocontainer.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
-
uv init --lib myproj(code lands insrc/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() -
flyte run src/myproj/wf.py main— succeeds; the run's env shows_F_SYS_PATH=./src:.... -
flyte deploy src/myproj/wf.py envand wait for the trigger to fire — the run fails withModuleNotFoundError: 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
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!
Hi, I'd like to work on this. I'll submit a PR shortly.