feat: persist and inspect run step budgets

This commit is contained in:
lda
2026-09-05 21:00:00 +07:00 Verified
parent 344902c17e
commit 7141a8818d
17 changed files with 707 additions and 8 deletions
+22 -2
View File
@@ -25,6 +25,7 @@ from wf_core import (
RunStatus,
dump_run_state,
load_run_state,
load_run_state_with_upgrade,
)
@@ -100,10 +101,29 @@ def persist_stopped_run(
def restore_interrupted_run(
store: RunStore, run_id: str
) -> tuple[WorkflowRunRecord, RunState]:
"""Load a persisted interrupted run and its latest typed runtime state."""
record, run = load_stored_run(store, run_id)
"""Load a persisted interrupted run, persisting a v1 upgrade first.
A pre-budget (v1) checkpoint receives its one-time defaults and is
rewritten as a new v2 interrupted checkpoint under the same run id and
pinned environment *before* the run is returned, so resume dispatch
never runs on unmigrated state and a failed upgrade fails resume before
any handler runs. Ordinary inspection uses :func:`load_stored_run`,
which decodes v1 prospectively without mutating the store.
"""
record = store.get_run(run_id)
if record.status is not StoredRunStatus.INTERRUPTED:
raise ValueError(f"workflow run {run_id!r} is not interrupted")
checkpoint = store.get_latest_checkpoint(run_id)
run, upgraded = load_run_state_with_upgrade(
checkpoint.state.model_dump(mode="json")
)
if upgraded:
record = persist_stopped_run(
store=store,
environment=record.environment,
run=run,
run_id=run_id,
)
return record, run