Skip to content

The agent that grows with you

fix(processes): a managed worker's background jobs outlive the worker again

kshitijk4poorf27b0104f624
diff --git a/tests/tools/test_terminal_owned_jobs.py b/tests/tools/test_terminal_owned_jobs.py
index 36c0b77d6af..5f77cafd9c2 100644
--- a/tests/tools/test_terminal_owned_jobs.py
+++ b/tests/tools/test_terminal_owned_jobs.py
@@ -207,3 +207,16 @@ def test_unowned_jobs_are_never_handed_to_the_supervisor(monkeypatch, tmp_path):
recovered_host_job = registry.spawn_local("exit 0", cwd=str(tmp_path))
wait_until(lambda: persisted.exited and recovered_host_job.exited, timeout=15, what="both jobs to exit")
assert calls == [], calls
+
+
+def test_a_managed_workers_jobs_are_never_handed_to_the_supervisor(monkeypatch, tmp_path):
+ """A managed worker is a per-turn interpreter: the next turn's worker adopts its jobs from the
+ checkpoint and reads their output log, so the jobs must outlive the worker that started them."""
+ from agent import runtime_session_store
+ from tools.process_registry import ProcessRegistry
+
+ calls = _record_calls(monkeypatch)
+ monkeypatch.setattr(runtime_session_store, "_worker_process", True)
+ job = ProcessRegistry().spawn_local("exit 0", cwd=str(tmp_path))
+ wait_until(lambda: job.exited, timeout=15, what="the worker's job to exit")
+ assert calls == [], calls
diff --git a/tools/process_registry_ownership.py b/tools/process_registry_ownership.py
index 22341ce825d..f9e6969382b 100644
--- a/tools/process_registry_ownership.py
+++ b/tools/process_registry_ownership.py
@@ -23,12 +23,14 @@ class ProcessOwnershipMixin:
def _owns_job(self, persist_on_release: bool) -> bool:
"""Not owned, on purpose: ``persist_on_release`` jobs, which must outlive the agent (#41225);
every job of a gateway, which re-adopts its jobs from the checkpoint after a crash (flagged by
- recover_from_checkpoint; a supervised gateway also before it gets there); and Windows, where
- the layer-3 job object covers ownership."""
+ recover_from_checkpoint; a supervised gateway also before it gets there); every job of a
+ managed worker, a per-turn interpreter whose jobs the next turn's worker adopts with their
+ output log (worker_output_log); and Windows, where the layer-3 job object covers ownership."""
+ from agent.runtime_session_store import is_worker_process
from tools.process_registry import _IS_WINDOWS, _is_supervised_gateway_process
return not (_IS_WINDOWS or persist_on_release or self._jobs_outlive_host
- or _is_supervised_gateway_process())
+ or is_worker_process() or _is_supervised_gateway_process())
def _spawn_job(self, session: Any, argv: list[str], persist_on_release: bool, **popen_kwargs) -> subprocess.Popen:
"""Start a pipe job in its own session, owned unless ``_owns_job`` says it must outlive us."""