Skip to content

The agent that grows with you

fix(cron): retain bounded history after targeted worker recovery

unsupportedpastels96982d628442
diff --git a/cron/executions.py b/cron/executions.py
index dd3d7c8f642..4f40500bfc3 100644
--- a/cron/executions.py
+++ b/cron/executions.py
@@ -436,6 +436,7 @@ def terminalize_dead_owner(execution_id: str, *, reason: str) -> bool:
if cur.rowcount != 1:
return False
record = _fetch(conn, execution_id)
+ _prune_unlocked(conn)
_emit_execution_state(record)
return True
diff --git a/tests/cron/test_restart_safe_worker_death_evidence.py b/tests/cron/test_restart_safe_worker_death_evidence.py
index 4a77ba259d5..8bb05f3712b 100644
--- a/tests/cron/test_restart_safe_worker_death_evidence.py
+++ b/tests/cron/test_restart_safe_worker_death_evidence.py
@@ -92,6 +92,11 @@ else:
"tools.process_registry.restart_safe_gateway_child_argv", dispatch
)
with use_cron_store(home):
+ # A lost worker must obey the same bounded history as normal finishes.
+ monkeypatch.setattr(executions, "MAX_TERMINAL_EXECUTIONS", 2)
+ for index in range(executions.MAX_TERMINAL_EXECUTIONS):
+ old = executions.create_execution(f"old-{index}", source="direct")
+ executions.finish_execution(old["id"], success=True)
job = create_job(prompt="Reply OK", schedule="every 1h", deliver="local")
claimed = claim_job_for_fire(job["id"], manual=True, return_job=True)
assert claimed
@@ -117,6 +122,7 @@ else:
assert result["claim_released"], result
assert "worker-probe-startup-sentinel" in (result["job_error"] or ""), result
assert len(delivered) == 1, result
+ assert len(executions.list_executions()) <= executions.MAX_TERMINAL_EXECUTIONS
from cron.scheduler_worker_failure import record_unknown_worker_outcome
# Re-observing an old terminal row cannot notify twice or erase a newer fire.