From 8eb0358c0149d9ba9380aa9f92f0796ec2f7aa3d Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 29 Jun 2026 21:32:25 +0200 Subject: [PATCH] fix(loop): put project root on PYTHONPATH for train.py subprocess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit train.py is copied into runs// by autoresearch_start.py, so when loop.py executes it, sys.path[0] is the run dir — which has no scripts/. train.py's frozen VaR-eval block does `from scripts.var_breach import ...`, which then fails with ModuleNotFoundError: No module named 'scripts' on every loop run (CI and the documented manual launch alike). Fix in the harness, not the frozen train.py/scripts boundary: prepend the project root (loop.py's own dir, where scripts/ lives) to the subprocess PYTHONPATH. Verified red→green locally: the import fails without it and resolves with it (scripts/ is an implicit namespace package, no __init__.py). --- loop.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/loop.py b/loop.py index 659bc3e..db783d8 100644 --- a/loop.py +++ b/loop.py @@ -84,6 +84,10 @@ def run_train() -> "tuple[float | None, float, str]": t0 = time.time() env = dict(os.environ) env["METRICS_OUT"] = str(METRICS_JSON.resolve()) + # train.py is copied into the run dir, so sys.path[0] is that run dir — which + # has no scripts/. Put the project root (where loop.py + scripts/ live) on + # PYTHONPATH so train.py's `from scripts.var_breach import ...` resolves. + env["PYTHONPATH"] = str(Path(__file__).resolve().parent) + os.pathsep + env.get("PYTHONPATH", "") try: r = subprocess.run( [sys.executable, str(TRAIN_PY.resolve())],