Skip to content

The agent that grows with you

fix(tools): register readers atomically with completion

maximilliangrand17708254819e
diff --git a/tools/process_registry.py b/tools/process_registry.py
index 222326d78dd..1a428f89477 100644
--- a/tools/process_registry.py
+++ b/tools/process_registry.py
@@ -785,13 +785,15 @@ class ProcessRegistry(ProcessCheckpointMixin):
return env
def _track_started(self, session: ProcessSession, reader_target, reader_name: str, extra_args=()) -> None:
- """Register before starting the reader: an already-exited child can finish immediately."""
+ """Register before the reader can publish completion, even for an exited child."""
reader = threading.Thread(target=reader_target, args=(session, *extra_args), daemon=True, name=reader_name)
session._reader_thread = reader
with self._lock:
self._prune_if_needed()
+ # Completion takes this lock too. Starting here also leaves no
+ # ghost entry if the interpreter cannot start another thread.
+ reader.start()
self._running[session.id] = session
- reader.start()
self._write_checkpoint()
def _spawn_local_pty(self, session: ProcessSession, safe_command: str, env_vars: dict) -> ProcessSession: