The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): a cron fire the owner refuses is booked as a failed run instead of pausing the job forever
Teknium9d33bee56def
diff --git a/cron/scheduler_authority.py b/cron/scheduler_authority.pyindex a20006a084e..cb9d08a8c35 100644--- a/cron/scheduler_authority.py+++ b/cron/scheduler_authority.py@@ -17,8 +17,9 @@ def journal_path(job_id, request_id):def run_canonical_job(job, *, extra_prompt=None, cancel_event=None, execution_id=None):from gateway.session_cron import owner_for_home, operation- from hermes_cli.gateway_client import connect_gateway+ from hermes_cli.gateway_client import GatewayClientError, connect_gatewayfrom hermes_constants import get_hermes_home+ from hermes_state_runtime import RuntimeStoreErrorfrom utils import atomic_json_writeparams = {'job_id': job['id'], 'request_id': execution_id or job.get('execution_id') or uuid.uuid4().hex,@@ -37,11 +38,25 @@ def run_canonical_job(job, *, extra_prompt=None, cancel_event=None, execution_idroot.mkdir(parents=True, exist_ok=True)atomic_json_write(journal, record, mode=0o600)+ async def refused(call, exc):+ # A lost reply may still have been admitted. Only the owner's own verdict (a bounded+ # reason code, never a disconnect/timeout) that its ledger holds no admission for this+ # fire is a refusal: book it as an ordinary failed run, never unknown.+ verdict = isinstance(exc, RuntimeStoreError) or (+ isinstance(exc, GatewayClientError) and str(exc).replace('_', '').isalnum())+ return verdict and (await call('recover', params))['status'] == 'missing'+async def observe(call):nonlocal attemptedattempted = Truesave()- receipt = await call('submit', params)+ try:+ receipt = await call('submit', params)+ except (RuntimeStoreError, GatewayClientError) as exc:+ if await refused(call, exc):+ journal.unlink(missing_ok=True)+ attempted = False+ raiserecord['receipt'] = receiptsave()while True:diff --git a/tests/cron/test_cron_recovery.py b/tests/cron/test_cron_recovery.pyindex 8380a47e049..1d82c6a3879 100644--- a/tests/cron/test_cron_recovery.py+++ b/tests/cron/test_cron_recovery.py@@ -126,3 +126,32 @@ def test_recovered_receipt_settles_the_departed_firers_execution_row(tmp_path, massert executions.recover_interrupted_executions() == 0assert executions.get_execution(fire)['status'] == 'completed'+++def test_owner_refused_fire_is_booked_failed_and_retires_its_journal(tmp_path, monkeypatch):+ """A definite pre-admission refusal (the job's workdir was removed) is an ordinary failed+ run: it must not raise CronExecutionUnknown, keep a journal, or pause the job on every+ later tick after the operator fixes the configuration."""+ from cron import scheduler_authority+ workdir = tmp_path / 'work'+ workdir.mkdir()+ with jobs.use_cron_store(tmp_path / 'cron'):+ job = jobs.create_job(prompt='original', schedule='every 1h', deliver='local', workdir=str(workdir))+ workdir.rmdir()+ authority, db = _owner(tmp_path, monkeypatch)++ async def probe():+ session_cron.bind_owner(authority)+ try:+ result = await asyncio.to_thread(+ scheduler_authority.run_canonical_job, jobs.get_job(job['id']), execution_id='fire')+ assert result[0] is False and 'invalid_params' in result[3]+ assert not scheduler_authority.journal_path(job['id'], 'fire').exists()+ await asyncio.to_thread(scheduler_authority.reconcile_pending)+ finally:+ session_cron.unbind_owner(authority)+ try:+ asyncio.run(probe())+ finally:+ db.close()+ assert jobs.get_job(job['id'])['state'] != 'paused'