Skip to content

The agent that grows with you

fix(cron): observe a fire whose submit failed after the owner committed it

Teknium3e35f5e944da
diff --git a/cron/scheduler_authority.py b/cron/scheduler_authority.py
index cd2f4c2dd8e..cbd9fdb60ce 100644
--- a/cron/scheduler_authority.py
+++ b/cron/scheduler_authority.py
@@ -59,7 +59,12 @@ def run_canonical_job(job, *, extra_prompt=None, cancel_event=None, execution_id
record['job'] = dict(job)
save()
return tuple(result)
- raise
+ if state['status'] not in {'queued', 'started', 'terminal'}:
+ raise
+ # Admitted before the answer was lost: observe it through the recovered receipt.
+ receipt = {'session_id': state['session_id'], 'admission_id': state['admission_id']}
+ else:
+ raise
record['receipt'] = receipt
save()
delay, progress = .1, None
diff --git a/gateway/session_cron.py b/gateway/session_cron.py
index bc0bbf0c7a2..6e98d37ca83 100644
--- a/gateway/session_cron.py
+++ b/gateway/session_cron.py
@@ -134,6 +134,8 @@ async def operation(authority, name, params, actor=None):
if frozen['extra_prompt'] != params['extra_prompt']:
raise RuntimeStoreError('admission_conflict')
state['job'] = frozen['cron_job']
+ # The receipt a firer whose submit answer was lost polls, exactly as if it had arrived.
+ state.update(session_id=sid, admission_id=row['admission_id'])
return state
if name == 'submit':
authority._require_admission_open()
diff --git a/tests/cron/test_cron_recover_after_commit.py b/tests/cron/test_cron_recover_after_commit.py
new file mode 100644
index 00000000000..ede472c5dbe
--- /dev/null
+++ b/tests/cron/test_cron_recover_after_commit.py
@@ -0,0 +1,47 @@
+"""A cron submit that fails after the owner committed the admission is observed, not paused (N61).
+
+The firer's ``submit`` raised after the admission row committed (a lost answer / an owner error
+past the commit). ``recover`` found the run, but the firer re-raised anyway: CronExecutionUnknown
+paused the job and gave up a run the owner then completed. Real SessionAuthority over SQLite.
+"""
+import asyncio
+
+from cron import executions, jobs, scheduler
+from gateway import session_cron
+from hermes_state_runtime import claim_session_input, settle_session_input
+from tests.cron.test_cron_recovery import _owner
+
+
+def test_submit_error_after_commit_observes_the_admitted_run(tmp_path, monkeypatch):
+ with jobs.use_cron_store(tmp_path / 'cron'):
+ job = jobs.create_job(prompt='report', schedule='every 1h', deliver='local')
+ authority, db = _owner(tmp_path, monkeypatch)
+ fire = executions.create_execution(job['id'], source='test')['id']
+ real = session_cron.operation
+
+ async def lossy(owner, name, params, actor=None):
+ answer = await real(owner, name, params, actor)
+ if name != 'submit':
+ return answer
+ # The owner admitted (and here, ran) the fire; the firer never sees the receipt.
+ row = claim_session_input(db, epoch=authority.epoch, session_id=answer['session_id'])
+ settle_session_input(db, epoch=authority.epoch, admission_id=row['admission_id'],
+ generation=row['generation'], outcome='completed',
+ result={'result': {'cron_result': [True, 'document', 'answer', None]}, 'usage': {}})
+ raise RuntimeError('owner answer lost after commit')
+
+ monkeypatch.setattr(session_cron, 'operation', lossy)
+
+ async def probe():
+ session_cron.bind_owner(authority)
+ try:
+ return await asyncio.to_thread(
+ scheduler._run_one_job_body, dict(jobs.get_job(job['id']), execution_id=fire))
+ finally:
+ session_cron.unbind_owner(authority)
+ try:
+ asyncio.run(probe())
+ finally:
+ db.close()
+ assert jobs.get_job(job['id'])['state'] != 'paused'
+ assert executions.get_execution(fire)['status'] == 'completed'