sched: record resumed stopped results live and idempotently (B3)

This commit is contained in:
lda
2026-09-09 17:27:36 +07:00 Verified
parent ada0239a1c
commit b094385077
5 changed files with 357 additions and 3 deletions
+48
View File
@@ -504,6 +504,54 @@ class Scheduler:
checkpoint_id=stopped.latest_checkpoint_id,
)
def record_resumed_stopped_result(
self,
run_id: str,
*,
status_value: str,
checkpoint_id: str | None,
now: datetime,
) -> bool:
"""Record one live resumed stopped result, idempotently.
The run API persists the resumed stopped checkpoint itself; this
only appends the matching occurrence-history entry through the
same ``(run_id, kind, checkpoint_id)`` idempotency as dispatch
and recovery, so repeated polls and restart recovery never
duplicate it. Schedule flags are deliberately not consulted:
pausing or deleting a schedule never suppresses retained run
history. Returns whether an entry was appended.
"""
self._require_ownership()
kind = {
"completed": "completed",
"interrupted": "interrupted",
"failed": "failed",
}.get(status_value)
if kind is None:
return False
try:
admission = self.run_store.get_admission(run_id)
except KeyError:
return False
sched_id = admission.schedule_id
if sched_id is None:
return False
if self.history.has_terminal(sched_id, run_id, kind, checkpoint_id):
return False
self._record(
kind=kind, # type: ignore[arg-type]
sched_id=sched_id,
intended=admission.scheduled_at,
run_id=run_id,
revision=admission.schedule_revision,
reason="resumed",
now=now,
started_at=now,
checkpoint_id=checkpoint_id,
)
return True
# -- polling --------------------------------------------------------
def poll(self, now: datetime) -> dict[str, str]:
self._require_ownership()