fix(dsh): reconcile resumed progress with checkpoint evidence
This commit is contained in:
1 parent
d3bdff81e5
commit
5cb8b6ac83
8 files changed
+187
-3
No files matched your search
@@ -51,6 +51,10 @@ class CadVerificationAdapter:
|
||||
'interrupted': bool(getattr(context, 'interrupted', True))}
|
||||
if row['interrupted']:
|
||||
blockers.append('interrupted')
|
||||
if type(row['failed_items']) is not int or row['failed_items'] != 0:
|
||||
blockers.append('failed_items')
|
||||
if row['queue_complete'] is not True:
|
||||
blockers.append('queue_incomplete')
|
||||
except Exception as error:
|
||||
row = {'task_id': task_id, 'saved_items': None, 'failed_items': None,
|
||||
'no_match_items': None, 'queue_complete': None, 'interrupted': True,
|
||||
|
||||
@@ -24,16 +24,35 @@ def resume_diff(service, inspected_run, *, current_plan_hashes=None):
|
||||
remaining = list(inspected_run.get('remaining_task_ids', ids))
|
||||
completed = [key for key in ids if key not in remaining]
|
||||
baseline = {row['task_id']: row for row in (inspected_run.get('result') or {}).get('tasks', [])}
|
||||
previous_entries = {row['task_id']: row.get('state')
|
||||
for row in (inspected_run.get('result') or {}).get('entries', [])}
|
||||
evidence_changes = []
|
||||
for task_id, context in contexts.items():
|
||||
saved = baseline.get(task_id, {})
|
||||
actual = {'interrupted': context.interrupted,
|
||||
**{field: getattr(context.progress, field, None) for field in
|
||||
('saved_items', 'failed_items', 'no_match_items', 'queue_complete')}}
|
||||
# A resumed run can crash after verified progress has landed, before
|
||||
# its final receipt. The old pause receipt remains a useful baseline,
|
||||
# but is immutable only for tasks that were already terminal then.
|
||||
progressing = (
|
||||
inspected_run.get('status') == 'running'
|
||||
and inspected_run.get('queue_available') is True
|
||||
and previous_entries.get(task_id) in {'pending', 'paused', 'running', 'blocked'}
|
||||
and inspected_run.get('checkpoint_states', {}).get(task_id) in {'running', 'paused', 'completed'}
|
||||
and saved.get('interrupted') is False and actual['interrupted'] is False
|
||||
and saved.get('queue_complete') is False and type(actual['queue_complete']) is bool
|
||||
and type(saved.get('failed_items')) is int and saved['failed_items'] == 0
|
||||
and type(actual['failed_items']) is int and actual['failed_items'] == 0
|
||||
and all(type(saved.get(key)) is int and type(actual[key]) is int
|
||||
and 0 <= saved[key] <= actual[key] for key in ('saved_items', 'no_match_items')))
|
||||
for field, value in actual.items():
|
||||
if saved.get(field) is not None and value != saved[field]:
|
||||
evidence_changes.append({'task_id': task_id, 'field': field, 'saved': saved[field], 'current': value})
|
||||
if evidence_changes:
|
||||
change = {'task_id': task_id, 'field': field, 'saved': saved[field], 'current': value}
|
||||
if progressing:
|
||||
change['expected_progress'] = True
|
||||
evidence_changes.append(change)
|
||||
if any(not row.get('expected_progress') for row in evidence_changes):
|
||||
blockers.append('evidence_changed')
|
||||
blockers = list(dict.fromkeys(blockers))
|
||||
return {'safe': bool(inspected_run.get('resume_ready')) and not blockers,
|
||||
|
||||
@@ -193,6 +193,11 @@ class RunJournal:
|
||||
blockers.append("interrupted")
|
||||
if getattr(progress, "failed_items", 0):
|
||||
blockers.append("failed_items")
|
||||
if queue and queue['entries'][task_id]['state'] == 'completed' and not (
|
||||
context.has_evidence and progress.queue_complete is True
|
||||
and type(progress.failed_items) is int and progress.failed_items == 0
|
||||
and context.interrupted is False):
|
||||
blockers.append('checkpoint_evidence_mismatch')
|
||||
from ..trial_task_center.task_queue import _plan_hash
|
||||
current_hashes[task_id] = _plan_hash(service.for_project_task(task_id), task_id)
|
||||
if current_hashes[task_id] != row["plan_hashes"][task_id]:
|
||||
@@ -210,7 +215,7 @@ class RunJournal:
|
||||
if remaining:
|
||||
try:
|
||||
from .task_lifecycle import preflight
|
||||
if not preflight(service, remaining)["ready"]:
|
||||
if not preflight(service, remaining, allow_completed=True)["ready"]:
|
||||
blockers.append("preflight_blocked")
|
||||
except Exception:
|
||||
blockers.append("preflight_unavailable")
|
||||
@@ -218,6 +223,7 @@ class RunJournal:
|
||||
blockers.append("resources_pending")
|
||||
blockers = list(dict.fromkeys(blockers))
|
||||
value = {**row, "queue_available": queue is not None, "tasks": tasks, "counters": counters,
|
||||
"checkpoint_states": {key: entry['state'] for key, entry in queue['entries'].items()} if queue else {},
|
||||
"remaining_task_ids": remaining, "blockers": blockers, "resume_ready": not blockers,
|
||||
"requires_confirmation": True,
|
||||
"cad_execution_started": False, "original_scope": {"task_ids": row["task_ids"], "plan_hashes": row["plan_hashes"]}}
|
||||
|
||||
Reference in new issue
Block a user