The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): allow cold external worker startup
KoNit-Ka7810a7a6e7c
diff --git a/cron/scheduler.py b/cron/scheduler.pyindex 498f2a40abe..302e7d9fffd 100644--- a/cron/scheduler.py+++ b/cron/scheduler.py@@ -3084,6 +3084,9 @@ def _wait_for_external_cron_worker(pass+_EXTERNAL_WORKER_COLD_START_ACK_TIMEOUT_SECONDS = 12.0++def _launch_external_cron_worker(job: dict) -> bool:"""Launch *job* outside the managed gateway process when required.@@ -3193,7 +3196,7 @@ def _launch_external_cron_worker(job: dict) -> bool:with _running_lock:_restart_safe_waiter_job_ids.add(job_id)- deadline = time.monotonic() + 5.0+ deadline = time.monotonic() + _EXTERNAL_WORKER_COLD_START_ACK_TIMEOUT_SECONDSwhile time.monotonic() < deadline:if ack_path.exists():try:@@ -3257,9 +3260,10 @@ def _launch_external_cron_worker(job: dict) -> bool:# handoff: that could duplicate side effects. The execution owner/dead-owner# recovery ledger remains the authority.logger.warning(- "Cron external worker for job '%s' did not acknowledge within 5s; "+ "Cron external worker for job '%s' did not acknowledge within %.0fs; ""leaving the durable execution claim untouched",job_id,+ _EXTERNAL_WORKER_COLD_START_ACK_TIMEOUT_SECONDS,)return _wait_for_external_cron_worker(process,diff --git a/tests/cron/test_restart_safe_worker.py b/tests/cron/test_restart_safe_worker.pyindex 446384f4059..8c6cdaf4049 100644--- a/tests/cron/test_restart_safe_worker.py+++ b/tests/cron/test_restart_safe_worker.py@@ -304,6 +304,65 @@ def test_launch_external_worker_uses_restart_safe_scope_and_acknowledges(assert not (tmp_path / "cron/external-workers/exec-1.json").exists()+def test_launch_external_worker_allows_delayed_cold_start_acknowledgement(+ tmp_path, monkeypatch+):+ import cron.scheduler as scheduler++ job = {"id": "job-cold", "execution_id": "exec-cold", "prompt": "work"}+ monkeypatch.setattr(scheduler, "_get_hermes_home", lambda: tmp_path)+ monkeypatch.setattr(+ "tools.process_registry.restart_safe_gateway_child_argv",+ lambda command, *, unit_suffix: ["scope", "--", *command],+ )+ monkeypatch.setattr(+ scheduler,+ "mark_execution_handoff_pending",+ lambda _execution_id: {"id": "exec-cold", "handoff_pending": 1},+ )++ class FakeClock:+ now = 0.0++ def monotonic(self):+ return self.now++ def sleep(self, seconds):+ self.now += seconds+ if self.now >= 6.0 and not ack_path.exists():+ ack_path.write_text(+ json.dumps({"pid": 4321, "execution_id": "exec-cold"}),+ encoding="utf-8",+ )++ clock = FakeClock()+ ack_path = tmp_path / "cron/external-workers/exec-cold.ready"++ class FakeProcess:+ returncode = None++ def poll(self):+ return self.returncode++ def wait(self, timeout=None):+ assert clock.now >= 6.0, "scheduler stopped waiting before cold-start ack"+ raise subprocess.TimeoutExpired(cmd="worker", timeout=timeout)++ monkeypatch.setattr(+ scheduler.subprocess, "Popen", lambda *_args, **_kwargs: FakeProcess()+ )+ monkeypatch.setattr(+ scheduler,+ "get_execution",+ lambda _execution_id: {"id": "exec-cold", "status": "completed"},+ )+ monkeypatch.setattr(scheduler.time, "monotonic", clock.monotonic)+ monkeypatch.setattr(scheduler.time, "sleep", clock.sleep)++ assert scheduler._launch_external_cron_worker(job) is True+ assert clock.now >= 6.0++def test_external_worker_exit_rechecks_exact_execution_before_failure(monkeypatch):import cron.scheduler as scheduler