Skip to content

The agent that grows with you

fix(terminal): background launches on env-backed backends honour workdir

Teknium7666f4f1f2a0
diff --git a/tests/tools/test_process_registry_env_spawn_cwd.py b/tests/tools/test_process_registry_env_spawn_cwd.py
new file mode 100644
index 00000000000..6432f4396c1
--- /dev/null
+++ b/tests/tools/test_process_registry_env_spawn_cwd.py
@@ -0,0 +1,30 @@
+"""Background launches on environment-backed backends run in the requested cwd."""
+
+import shutil
+import time
+
+import pytest
+
+from tools.environments.local import LocalEnvironment
+from tools.process_registry import ProcessRegistry
+
+
[email protected](not shutil.which("bash"), reason="needs bash")
+def test_spawn_via_env_runs_command_in_requested_cwd(tmp_path):
+ default_dir = tmp_path / "env-default"
+ workdir = tmp_path / "requested"
+ default_dir.mkdir()
+ workdir.mkdir()
+ env = LocalEnvironment(cwd=str(default_dir), timeout=30)
+ registry = ProcessRegistry()
+ try:
+ session = registry.spawn_via_env(env, "pwd -P", cwd=str(workdir), task_id="bg-cwd")
+ deadline = time.monotonic() + 30
+ while not session.exited and time.monotonic() < deadline:
+ time.sleep(0.2)
+
+ assert session.exited and session.exit_code == 0, session.output_buffer
+ assert session.output_buffer.strip() == str(workdir.resolve())
+ finally:
+ registry.kill_all()
+ env.cleanup()
diff --git a/tools/process_registry.py b/tools/process_registry.py
index 944a8742944..f1884286ffd 100644
--- a/tools/process_registry.py
+++ b/tools/process_registry.py
@@ -1291,7 +1291,7 @@ class ProcessRegistry(ProcessTerminationMixin, ProcessCheckpointMixin, ProcessOu
f"( nohup bash -lc {q(command)} > {q(log_path)} 2>&1; "
f"rc=$?; printf '%s\\n' \"$rc\" > {q(exit_path)} ) & "
f"echo $! > {q(pid_path)} && cat {q(pid_path)}")
- result = env.execute(bg_command, timeout=timeout, rewrite_compound_background=False)
+ result = env.execute(bg_command, cwd=cwd or "", timeout=timeout, rewrite_compound_background=False)
output = result.get("output", "").strip()
session.pid = next((int(ln) for ln in map(str.strip, output.splitlines()) if ln.isdigit()), None)
# No PID from the wrapper (no bash in the image, sandbox gone, broken redirect): the