Skip to content

The agent that grows with you

refactor(cron): let _record_fire_ownership_lost derive ladder_rung from the job

kshitijk4poor037a7059745b
diff --git a/cron/scheduler.py b/cron/scheduler.py
index 1b6a2163a9e..e2dd3296a39 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -2900,17 +2900,19 @@ _OWNERSHIP_LOST_INTERRUPTED = "Interrupted by shutdown before terminal completio
def _record_fire_ownership_lost(
- job_id: str, fire_owner: Optional[str], execution_id: str, *, ladder_rung: bool = False,
+ job: dict, fire_owner: Optional[str], execution_id: str,
) -> None:
"""Bookkeeping after fire-claim ownership loss. A transport-level cancel (dashboard drain) is
not a real loss — we still own the claim, so record the interruption via the owner-fenced
terminal write instead of leaving fire_claim/last_status stale; otherwise discard.
- ``ladder_rung``: the interrupted run re-ran an occurrence that already counted, so its
- terminal write must not spend another repeat slot (same as every other terminal path)."""
+ An interrupted ladder re-run re-ran an occurrence that already counted, so its terminal
+ write must not spend another repeat slot (same as every other terminal path)."""
+ from cron.unreachable_retry import is_retry_run
+ job_id = job["id"]
if fire_owner is not None and heartbeat_fire_claim(job_id, expected_owner=fire_owner):
mark_job_run(
job_id, False, _OWNERSHIP_LOST_INTERRUPTED, expected_fire_owner=fire_owner,
- **({"ladder_rung": True} if ladder_rung else {}),
+ **({"ladder_rung": True} if is_retry_run(job) else {}),
)
finish_execution(execution_id, success=False, error=_OWNERSHIP_LOST_INTERRUPTED)
else:
@@ -3307,7 +3309,6 @@ def _run_one_job_body(
transport_cancel: Optional[_CancelEventLike] = None,
execution_token: Optional[object] = None,
) -> bool:
- from cron.unreachable_retry import is_retry_run
fence = _FireOwnership(job, claim_lost, transport_cancel)
fire_owner = fence.owner
_side_effect_fence = fence.side_effect_fence
@@ -3402,8 +3403,7 @@ def _run_one_job_body(
if _fire_claim_ownership_lost():
_teardown_deferred()
- _record_fire_ownership_lost(
- job["id"], fire_owner, execution_id, ladder_rung=is_retry_run(job))
+ _record_fire_ownership_lost(job, fire_owner, execution_id)
return True
# An agent can finish its own turn after a delegated child has failed. Let it explicitly
@@ -3431,8 +3431,7 @@ def _run_one_job_body(
if d.side_effect_ownership_lost:
# The claim died inside a side-effect fence: the side effect did NOT complete.
- _record_fire_ownership_lost(
- job["id"], fire_owner, execution_id, ladder_rung=is_retry_run(job))
+ _record_fire_ownership_lost(job, fire_owner, execution_id)
return True
# Empty final_response is a soft failure so last_status is not "ok".
@@ -3457,8 +3456,7 @@ def _run_one_job_body(
"Job '%s': transport cancellation arrived before terminal completion; "
"recording the interrupted run",
job["id"])
- _record_fire_ownership_lost(
- job["id"], fire_owner, execution_id, ladder_rung=is_retry_run(job))
+ _record_fire_ownership_lost(job, fire_owner, execution_id)
return True
if _consume_interrupted_flag(job["id"], execution_token):