fix(dsh): retain verified resume progress on checkpoint failure

This commit is contained in:
阿白叔 committed 2026-11-01 18:23:40 +08:00
1 parent ec7eab89fb
commit 7c29f72ff7
4 files changed
+143 -3

No files matched your search

+26 -1
View File
@@ -9,6 +9,31 @@ from ..trial_task_center.errors import TaskCenterError
from ..trial_task_center.task_queue import execute_task_queue
def _failure_evidence(service, journal, run_id, baseline):
evidence = {key: baseline[key] for key in ('tasks', 'entries') if key in baseline}
if not baseline:
return evidence
try:
# Inspect while the journal still records this authorized attempt as
# running. Only its verified, monotonic progress may advance the old
# baseline; terminal changes, failed/uncertain results and rollbacks
# must remain visible to the next inspection.
inspected = journal.inspect(service, run_id)
changes = inspected['diff']['evidence_changes']
if (inspected['status'] != 'running' or not inspected['diff']['safe']
or not changes or not all(row.get('expected_progress') is True for row in changes)):
return evidence
tasks = {row['task_id']: dict(row) for row in baseline['tasks']}
for change in changes:
tasks[change['task_id']][change['field']] = change['current']
evidence.update(tasks=list(tasks.values()), verified_progress=changes)
except Exception:
# Readback failure must neither hide the original execution error nor
# replace the last durable evidence with an incomplete snapshot.
pass
return evidence
def execute_confirmed_run(service, root, task_ids, report, stop, run_id, *, resume=None, schedule=None, automatic=False):
prior = RunJournal(root).get(run_id) if resume else None
schedule_id = schedule['schedule_id'] if schedule else (prior or {}).get('schedule_id')
@@ -47,7 +72,7 @@ def _execute_confirmed_run(service, root, task_ids, report, stop, run_id, *, res
queue_id=run_id if resume and resume['queue_available'] else None,
checkpoint_id=None if resume and resume['queue_available'] else run_id)
except Exception as error:
failure = {**{key: baseline[key] for key in ('tasks', 'entries') if key in baseline},
failure = {**(_failure_evidence(service, journal, run_id, baseline) if initialized else {}),
'status': 'interrupted', 'run_id': run_id, 'queue_id': run_id,
'code': getattr(error, 'code', 'execution_interrupted'), 'message': '执行未完成,请按原队列证据核验后接续。'}
if initialized: