The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): settle the receipt best-effort on the unwritable-store claim skip
kshitijk4poor9c733eaa3f8b
diff --git a/cron/scheduler.py b/cron/scheduler.pyindex c1992df141a..b2e9434c187 100644--- a/cron/scheduler.py+++ b/cron/scheduler.py@@ -4266,8 +4266,8 @@ def _process_due_job(job: dict, adapters, loop, verbose: bool) -> bool:claimed = claim_job_for_fire(job["id"], return_job=True)except OSError as exc:warn_store_unwritable(exc, f"skipped job '{job.get('name') or job['id']}'", "claim")- finish_execution(- job["execution_id"], success=False, error=f"Cron store unwritable; not started: {exc}")+ settle_unstarted_execution(+ job["execution_id"], job["id"], f"Cron store unwritable; not started: {exc}")return Falseexcept BaseException as exc: # settle first, then surface the real errorsettle_unstarted_execution(diff --git a/tests/cron/test_due_scan_save_failure.py b/tests/cron/test_due_scan_save_failure.pyindex 67a857803b7..d5469c2497c 100644--- a/tests/cron/test_due_scan_save_failure.py+++ b/tests/cron/test_due_scan_save_failure.py@@ -16,6 +16,7 @@ dispatch (no durable advance) without raising or mutating the store.import errnoimport jsonimport logging+import sqlite3import pytestfrom datetime import datetime, timezone@@ -128,21 +129,37 @@ def test_tick_on_unwritable_store_returns_cleanly_without_dispatch(cron_store, massert row is None[email protected]("site", ["claim_job_for_fire", "note_cron_execution"])-def test_dispatch_failure_after_receipt_never_leaves_it_claimed(cron_store, monkeypatch, caplog, site):[email protected]("site,exc,ledger_fails", [+ ("claim_job_for_fire", RuntimeError, False),+ ("note_cron_execution", RuntimeError, False),+ # Full disk: the executions.db write fails too; the store-unwritable skip must not raise.+ ("claim_job_for_fire", OSError, True),+])+def test_dispatch_failure_after_receipt_never_leaves_it_claimed(+ cron_store, monkeypatch, caplog, site, exc, ledger_fails):"""A non-OSError fire-claim failure, or a failure after create_execution in _submit_with_guard,must settle the receipt: a ``claimed`` row never resolves and reads forever as in flight."""from cron import executions, schedulerdef boom(*_a, **_k):- raise RuntimeError("boom")+ raise exc("boom")++ def ledger_full(*_a, **_k):+ raise sqlite3.OperationalError("database or disk is full")save_jobs([_due_job()])monkeypatch.setattr(executions, "EXECUTIONS_FILE", cron_store / "cron" / "executions.db")monkeypatch.setattr(scheduler, "run_one_job", lambda job, **k: True)monkeypatch.setattr(scheduler, "_should_yield_tick_to_fresh_gateway", lambda: None)monkeypatch.setattr(scheduler, site, boom)+ if ledger_fails:+ monkeypatch.setattr(executions, "finish_execution", ledger_full)+ monkeypatch.setattr(scheduler, "finish_execution", ledger_full)scheduler.tick(verbose=False, sync=True) # a worker failure is logged, never raised+ if ledger_fails: # the skip settles best-effort instead of raising out of the worker+ assert "failed to close execution receipt" in caplog.text+ assert "Cron job future failed" not in caplog.text+ returnrow = executions.latest_execution("due-job")assert row is not None and row["status"] == "failed"if site == "note_cron_execution": # the receipt exists, so creation did not fail