fix: address PR27 lifecycle, BOM and netlist review findings
Core regression / Python core, intervention UI and release configuration (push) Failing after 4m4s
Core regression / JavaScript syntax (push) Successful in 5s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 4m20s
Core regression / JavaScript syntax (pull_request) Successful in 4s
Core regression / Python core, intervention UI and release configuration (push) Failing after 4m4s
Core regression / JavaScript syntax (push) Successful in 5s
Core regression / Python core, intervention UI and release configuration (pull_request) Failing after 4m20s
Core regression / JavaScript syntax (pull_request) Successful in 4s
This commit is contained in:
1 parent
0ee83e77e2
commit
f9d5e56bb8
58 files changed
+20646
-164
No files matched your search
@@ -13,7 +13,7 @@ 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', 'retry') if key in baseline}
|
||||
evidence = {key: baseline[key] for key in ('tasks', 'entries', 'retry', 'netlist_verification') if key in baseline}
|
||||
if not baseline:
|
||||
return evidence
|
||||
try:
|
||||
@@ -43,14 +43,22 @@ def execute_confirmed_run(service, root, task_ids, report, stop, run_id, *, resu
|
||||
if schedule_id:
|
||||
schedules = ScheduleStore(root)
|
||||
with schedules.execution_lease(schedule_id):
|
||||
if resume:
|
||||
_bound_schedule(schedules, prior)
|
||||
receipt = _execute_confirmed_run(service, root, task_ids, report, stop, run_id,
|
||||
resume=resume, schedule=schedule, automatic=automatic)
|
||||
if resume:
|
||||
schedules.finish(schedule_id, 'interrupted' if receipt['status'] in {'paused', 'blocked'} else receipt['status'],
|
||||
repair_run_id=run_id, run_id=run_id, receipt=receipt)
|
||||
return receipt
|
||||
try:
|
||||
if resume:
|
||||
_bound_schedule(schedules, prior)
|
||||
receipt = _execute_confirmed_run(service, root, task_ids, report, stop, run_id,
|
||||
resume=resume, schedule=schedule, automatic=automatic)
|
||||
if resume:
|
||||
schedules.finish(schedule_id, 'interrupted' if receipt['status'] in {'paused', 'blocked'} else receipt['status'],
|
||||
repair_run_id=run_id, run_id=run_id, receipt=receipt)
|
||||
return receipt
|
||||
except Exception:
|
||||
original = prior or RunJournal(root).get(run_id)
|
||||
if original:
|
||||
if original['schedule_id'] != schedule_id:
|
||||
raise TaskCenterError('schedule_run_conflict', '运行已不再绑定当前排期执行租约。')
|
||||
_finish_failed_schedule(schedules, RunJournal(root), original)
|
||||
raise
|
||||
return _execute_confirmed_run(service, root, task_ids, report, stop, run_id, resume=resume)
|
||||
|
||||
|
||||
@@ -74,6 +82,7 @@ def _execute_confirmed_run(service, root, task_ids, report, stop, run_id, *, res
|
||||
raise TaskCenterError('run_blocked', '原执行范围或证据已变化,请先核验。')
|
||||
baseline = inspected.get('result') or {}
|
||||
journal.resume(run_id)
|
||||
initialized = True
|
||||
journal.repair_retry_checkpoint(service, run_id)
|
||||
else:
|
||||
journal.begin(run_id, task_ids, report['plan_hashes'], schedule_id=schedule['schedule_id'] if schedule else None)
|
||||
@@ -92,10 +101,10 @@ def _execute_confirmed_run(service, root, task_ids, report, stop, run_id, *, res
|
||||
schedules.finish(schedule['schedule_id'], 'interrupted', run_id=run_id, receipt=failure)
|
||||
raise
|
||||
return _finish_execution_run(service, root, task_ids, stop, run_id, result,
|
||||
schedule=schedule if claimed else None)
|
||||
baseline=baseline, schedule=schedule if claimed else None)
|
||||
|
||||
|
||||
def _finish_execution_run(service, root, task_ids, stop, run_id, result, *, schedule=None):
|
||||
def _finish_execution_run(service, root, task_ids, stop, run_id, result, *, baseline, schedule=None):
|
||||
journal = RunJournal(root)
|
||||
schedules = ScheduleStore(root) if schedule is not None else None
|
||||
entries = [{'task_id': e.task_id, 'state': e.state, 'message': e.message} for e in result.entries]
|
||||
@@ -112,7 +121,7 @@ def _finish_execution_run(service, root, task_ids, stop, run_id, result, *, sche
|
||||
if result.netlist_verification:
|
||||
receipt['netlist_verification'] = result.netlist_verification
|
||||
# Persist the executor's known outcome before optional readback/enrichment.
|
||||
journal.finish(run_id, receipt)
|
||||
_persist_execution_receipt(service, journal, run_id, receipt, baseline)
|
||||
try:
|
||||
receipt['cad_verification'] = CadVerificationAdapter(service).after_run(task_ids,
|
||||
netlist_verification=result.netlist_verification)
|
||||
@@ -134,23 +143,42 @@ def _finish_execution_run(service, root, task_ids, stop, run_id, result, *, sche
|
||||
if status == 'completed' and receipt['acceptance']['status'] in {'different', 'unavailable'}:
|
||||
receipt['status'] = 'failed'
|
||||
receipt['message'] = '替换执行已收尾,独立网表验收未通过;保留已保存回执,不重复替换。'
|
||||
try:
|
||||
journal.finish(run_id, receipt)
|
||||
except Exception as error:
|
||||
receipt['reporting_errors'].append({'code': 'receipt_enrichment_unavailable', 'error': type(error).__name__})
|
||||
_persist_execution_receipt(service, journal, run_id, receipt, baseline)
|
||||
if schedule is not None:
|
||||
try:
|
||||
schedules.finish(schedule['schedule_id'], 'interrupted' if receipt['status'] in {'paused', 'blocked'} else receipt['status'],
|
||||
run_id=run_id, receipt=receipt)
|
||||
except Exception as error:
|
||||
receipt['reporting_errors'].append({'code': getattr(error, 'code', 'schedule_receipt_unavailable')})
|
||||
try:
|
||||
journal.finish(run_id, receipt)
|
||||
except Exception:
|
||||
receipt['reporting_errors'].append({'code': 'receipt_enrichment_unavailable'})
|
||||
_persist_execution_receipt(service, journal, run_id, receipt, baseline)
|
||||
raise
|
||||
return receipt
|
||||
|
||||
|
||||
def _persist_execution_receipt(service, journal, run_id, receipt, baseline):
|
||||
try:
|
||||
journal.finish(run_id, receipt)
|
||||
except Exception as error:
|
||||
evidence = _failure_evidence(service, journal, run_id, baseline)
|
||||
failure = {**evidence, **receipt, 'status': 'interrupted', 'code': 'receipt_write_error',
|
||||
'reporting_errors': [*receipt['reporting_errors'],
|
||||
{'code': 'receipt_write_error', 'error': type(error).__name__}]}
|
||||
if not receipt['tasks'] and 'tasks' in evidence:
|
||||
failure['tasks'] = evidence['tasks']
|
||||
journal.finish(run_id, failure)
|
||||
raise
|
||||
|
||||
|
||||
def _finish_failed_schedule(schedules, journal, original):
|
||||
# The lease and both identities remain mandatory even on error paths.
|
||||
_bound_schedule(schedules, original)
|
||||
receipt = (journal.get(original['run_id']) or {}).get('result') or {}
|
||||
failure = {**receipt, 'status': 'interrupted', 'run_id': original['run_id'],
|
||||
'queue_id': original['queue_id'], 'code': receipt.get('code', 'execution_interrupted')}
|
||||
schedules.finish(original['schedule_id'], 'interrupted', repair_run_id=original['run_id'],
|
||||
run_id=original['run_id'], receipt=failure)
|
||||
|
||||
|
||||
def _bound_schedule(schedules, run):
|
||||
row = schedules.get(run['schedule_id'])
|
||||
if (not row or row['run_id'] != run['run_id'] or row['task_ids'] != run['task_ids']
|
||||
@@ -164,13 +192,17 @@ def execute_incident_retry(service, root, task_id, run_id, *, expected_item, sto
|
||||
if original and original['schedule_id']:
|
||||
schedules = ScheduleStore(root)
|
||||
with schedules.execution_lease(original['schedule_id']):
|
||||
_bound_schedule(schedules, original)
|
||||
result = _execute_incident_retry(service, root, task_id, run_id,
|
||||
expected_item=expected_item, stop_event=stop_event, operation_keys=operation_keys)
|
||||
receipt = RunJournal(root).get(run_id)['result']
|
||||
schedules.finish(original['schedule_id'], 'interrupted' if receipt['status'] in {'paused', 'blocked'} else receipt['status'],
|
||||
repair_run_id=run_id, run_id=run_id, receipt=receipt)
|
||||
return result
|
||||
try:
|
||||
_bound_schedule(schedules, original)
|
||||
result = _execute_incident_retry(service, root, task_id, run_id,
|
||||
expected_item=expected_item, stop_event=stop_event, operation_keys=operation_keys)
|
||||
receipt = RunJournal(root).get(run_id)['result']
|
||||
schedules.finish(original['schedule_id'], 'interrupted' if receipt['status'] in {'paused', 'blocked'} else receipt['status'],
|
||||
repair_run_id=run_id, run_id=run_id, receipt=receipt)
|
||||
return result
|
||||
except Exception:
|
||||
_finish_failed_schedule(schedules, RunJournal(root), original)
|
||||
raise
|
||||
return _execute_incident_retry(service, root, task_id, run_id,
|
||||
expected_item=expected_item, stop_event=stop_event, operation_keys=operation_keys)
|
||||
|
||||
@@ -198,67 +230,88 @@ def _execute_incident_retry(service, root, task_id, run_id, *, expected_item, st
|
||||
if (checkpoint.get('task_ids') != original['task_ids'] or checkpoint.get('plan_hashes') != original['plan_hashes']
|
||||
or set(checkpoint['entries']) != set(original['task_ids'])):
|
||||
raise TaskCenterError('run_scope', '原队列检查点身份或范围已变化;不执行重试。')
|
||||
journal.begin_retry(service, run_id, task_id, operation_keys)
|
||||
checkpoint['entries'][task_id].update(state='running', message='仅执行已预约的原失败项重试。')
|
||||
_save(path, checkpoint)
|
||||
token = original['run_id'] if original else sha256(str(run_id).encode('utf-8')).hexdigest()[:32]
|
||||
with NetlistVerification(root, token, stop_event) as checks:
|
||||
# Never capture a partially replaced project as a new "before".
|
||||
checks.before_task(child, task_id, existing_only=True)
|
||||
outcome = service.execute_quick_run_queue(task_id, expected_item=expected_item, stop_event=stop_event)
|
||||
current = service.task_context(task_id)
|
||||
p = current.progress
|
||||
complete = p.queue_complete and not p.failed_items and not current.interrupted and not outcome.paused
|
||||
summary = {key: getattr(p, key, 0) for key in ('saved_items', 'failed_items', 'no_match_items')}
|
||||
if p.saved_items or 'rules' in checks.tasks.get(task_id, {}).get('plan', {}):
|
||||
checks.after_task(task_id, execution_state='completed' if complete else 'failed',
|
||||
execution_summary=summary, refresh=True)
|
||||
reports = checks.finish()
|
||||
if not p.saved_items:
|
||||
reports = {key: report for key, report in reports.items() if report['status'] == 'not_required'}
|
||||
if p.saved_items and task_id not in reports:
|
||||
directory = root / 'tasks' / task_id / 'netlist-checks' / token
|
||||
reports[task_id] = {'status': 'unavailable', 'verified': False,
|
||||
'reason': '原授权执行缺少完整替换前基准,不能事后补造或仅凭保存计数宣称验收通过。',
|
||||
'report_path': str(directory / 'verification.json')}
|
||||
write_record(directory / 'verification.json', reports[task_id])
|
||||
acceptance = verification_summary(reports, required_task_ids=(task_id,) if p.saved_items else ())
|
||||
verification = {'queue_complete': p.queue_complete, 'failed_items': p.failed_items,
|
||||
'saved_items': p.saved_items, 'completed_items': p.completed_items,
|
||||
'interrupted': current.interrupted, 'paused': outcome.paused,
|
||||
'acceptance': acceptance, 'netlist_verification': reports, 'run_receipt_updated': False}
|
||||
if original:
|
||||
# Preserve every other entry/report. This does not resume the parent
|
||||
# queue or dispatch any other engineering task.
|
||||
prior = original.get('result') or {}
|
||||
entries = {row['task_id']: dict(row) for row in prior.get('entries', ())}
|
||||
if set(entries) != set(original['task_ids']):
|
||||
raise TaskCenterError('run_scope', '原执行回执范围不完整,保留本次真实结果等待核验。')
|
||||
state = 'blocked' if current.interrupted else 'paused' if outcome.paused else 'completed' if complete else 'failed'
|
||||
message = 'DSH 已按原失败项范围重试;保存结果与独立验收分别记录。'
|
||||
entries[task_id].update(state=state, message=message)
|
||||
merged = dict(prior.get('netlist_verification') or {})
|
||||
merged.pop(task_id, None)
|
||||
merged.update(reports)
|
||||
candidates = [root / folder / (run_id + '.json') for folder in ('task-queues', 'workspace-queues')]
|
||||
existing = [path for path in candidates if path.is_file()]
|
||||
if len(existing) != 1:
|
||||
raise TaskCenterError('run_scope', '原队列检查点缺失或有歧义;不接续其他任务。')
|
||||
path = existing[0]
|
||||
checkpoint = json.loads(path.read_text(encoding='utf-8'))
|
||||
if (checkpoint.get('task_ids') != original['task_ids'] or checkpoint.get('plan_hashes') != original['plan_hashes']
|
||||
or set(checkpoint['entries']) != set(original['task_ids'])):
|
||||
raise TaskCenterError('run_scope', '原队列检查点身份或范围已变化;保留本次结果。')
|
||||
checkpoint['entries'][task_id].update(state=state, message=message)
|
||||
if path.parent.name == 'workspace-queues':
|
||||
checkpoint['entries'][task_id].update(released=not bool(service.pending_batch_resources()), problems_done=True)
|
||||
if reports:
|
||||
checkpoint['entries'][task_id]['netlist_verification'] = reports[task_id]
|
||||
elif reports:
|
||||
checkpoint.setdefault('netlist_verification', {}).update(reports)
|
||||
_save(path, checkpoint)
|
||||
result = TaskQueueResult(original['queue_id'], tuple(TaskQueueEntry(**entries[key])
|
||||
for key in original['task_ids']), outcome.paused, netlist_verification=merged)
|
||||
receipt = _finish_execution_run(service, root, original['task_ids'], stop_event, run_id, result)
|
||||
verification.update(run_receipt_updated=True, run_status=receipt['status'])
|
||||
return outcome, current, verification
|
||||
retry_run = journal.begin_retry(service, run_id, task_id, operation_keys)
|
||||
baseline = (retry_run.get('result') or {}) if original else {}
|
||||
try:
|
||||
if original:
|
||||
checkpoint['entries'][task_id].update(state='running', message='仅执行已预约的原失败项重试。')
|
||||
_save(path, checkpoint)
|
||||
token = original['run_id'] if original else sha256(str(run_id).encode('utf-8')).hexdigest()[:32]
|
||||
with NetlistVerification(root, token, stop_event) as checks:
|
||||
# Never capture a partially replaced project as a new "before".
|
||||
checks.before_task(child, task_id, existing_only=True)
|
||||
outcome = service.execute_quick_run_queue(task_id, expected_item=expected_item, stop_event=stop_event)
|
||||
current = service.task_context(task_id)
|
||||
p = current.progress
|
||||
complete = p.queue_complete and not p.failed_items and not current.interrupted and not outcome.paused
|
||||
summary = {key: getattr(p, key, 0) for key in ('saved_items', 'failed_items', 'no_match_items')}
|
||||
if p.saved_items or 'rules' in checks.tasks.get(task_id, {}).get('plan', {}):
|
||||
checks.after_task(task_id, execution_state='completed' if complete else 'failed',
|
||||
execution_summary=summary, refresh=True)
|
||||
reports = checks.finish()
|
||||
if not p.saved_items:
|
||||
reports = {key: report for key, report in reports.items() if report['status'] == 'not_required'}
|
||||
if p.saved_items and task_id not in reports:
|
||||
directory = root / 'tasks' / task_id / 'netlist-checks' / token
|
||||
reports[task_id] = {'status': 'unavailable', 'verified': False,
|
||||
'reason': '原授权执行缺少完整替换前基准,不能事后补造或仅凭保存计数宣称验收通过。',
|
||||
'report_path': str(directory / 'verification.json')}
|
||||
write_record(directory / 'verification.json', reports[task_id])
|
||||
acceptance = verification_summary(reports, required_task_ids=(task_id,) if p.saved_items else ())
|
||||
verification = {'queue_complete': p.queue_complete, 'failed_items': p.failed_items,
|
||||
'saved_items': p.saved_items, 'completed_items': p.completed_items,
|
||||
'interrupted': current.interrupted, 'paused': outcome.paused,
|
||||
'acceptance': acceptance, 'netlist_verification': reports, 'run_receipt_updated': False}
|
||||
if original:
|
||||
# Preserve every other entry/report. This does not resume the parent
|
||||
# queue or dispatch any other engineering task.
|
||||
prior = original.get('result') or {}
|
||||
entries = {row['task_id']: dict(row) for row in prior.get('entries', ())}
|
||||
if set(entries) != set(original['task_ids']):
|
||||
raise TaskCenterError('run_scope', '原执行回执范围不完整,保留本次真实结果等待核验。')
|
||||
state = 'blocked' if current.interrupted else 'paused' if outcome.paused else 'completed' if complete else 'failed'
|
||||
message = 'DSH 已按原失败项范围重试;保存结果与独立验收分别记录。'
|
||||
entries[task_id].update(state=state, message=message)
|
||||
merged = dict(prior.get('netlist_verification') or {})
|
||||
merged.pop(task_id, None)
|
||||
merged.update(reports)
|
||||
candidates = [root / folder / (run_id + '.json') for folder in ('task-queues', 'workspace-queues')]
|
||||
existing = [path for path in candidates if path.is_file()]
|
||||
if len(existing) != 1:
|
||||
raise TaskCenterError('run_scope', '原队列检查点缺失或有歧义;不接续其他任务。')
|
||||
path = existing[0]
|
||||
checkpoint = json.loads(path.read_text(encoding='utf-8'))
|
||||
if (checkpoint.get('task_ids') != original['task_ids'] or checkpoint.get('plan_hashes') != original['plan_hashes']
|
||||
or set(checkpoint['entries']) != set(original['task_ids'])):
|
||||
raise TaskCenterError('run_scope', '原队列检查点身份或范围已变化;保留本次结果。')
|
||||
checkpoint['entries'][task_id].update(state=state, message=message)
|
||||
if path.parent.name == 'workspace-queues':
|
||||
checkpoint['entries'][task_id].update(released=not bool(service.pending_batch_resources()), problems_done=True)
|
||||
if reports:
|
||||
checkpoint['entries'][task_id]['netlist_verification'] = reports[task_id]
|
||||
elif reports:
|
||||
checkpoint.setdefault('netlist_verification', {}).update(reports)
|
||||
_save(path, checkpoint)
|
||||
result = TaskQueueResult(original['queue_id'], tuple(TaskQueueEntry(**entries[key])
|
||||
for key in original['task_ids']), outcome.paused, netlist_verification=merged)
|
||||
receipt = _finish_execution_run(service, root, original['task_ids'], stop_event, run_id, result,
|
||||
baseline=baseline)
|
||||
verification.update(run_receipt_updated=True, run_status=receipt['status'])
|
||||
return outcome, current, verification
|
||||
except Exception as error:
|
||||
if original and journal.get(run_id)['status'] == 'running':
|
||||
failure = {**_failure_evidence(service, journal, run_id, baseline),
|
||||
'status': 'interrupted', 'run_id': run_id, 'queue_id': original['queue_id'],
|
||||
'code': getattr(error, 'code', 'execution_interrupted'),
|
||||
'message': '原失败项重试未完成;保留已保存证据,按原范围核验后接续。'}
|
||||
try:
|
||||
observed = service.task_context(task_id)
|
||||
# A raw readback must not replace the baseline after a scope/proof failure.
|
||||
failure['retry_observation'] = dict(task_id=task_id, interrupted=observed.interrupted,
|
||||
**{key: getattr(observed.progress, key) for key in
|
||||
('saved_items', 'failed_items', 'no_match_items', 'queue_complete')})
|
||||
except Exception as readback_error:
|
||||
failure['reporting_errors'] = [{'code': 'context_unavailable',
|
||||
'error': type(readback_error).__name__}]
|
||||
journal.finish(run_id, failure)
|
||||
raise
|
||||
@@ -98,8 +98,9 @@ class RunJournal:
|
||||
started = _now()
|
||||
db.execute("INSERT INTO run_journal VALUES (?, ?, ?, ?, ?, ?, ?, NULL, NULL)",
|
||||
(run_id, run_id, json.dumps(ids), json.dumps(hashes, sort_keys=True), schedule_id, "running", started))
|
||||
current = self._row(db.execute("SELECT * FROM run_journal WHERE run_id = ?", (run_id,)).fetchone())
|
||||
db.execute("COMMIT")
|
||||
return self.get(run_id)
|
||||
return current
|
||||
|
||||
def finish(self, run_id, result):
|
||||
if not isinstance(run_id, str) or not _ID.fullmatch(run_id):
|
||||
@@ -123,21 +124,23 @@ class RunJournal:
|
||||
(run_id, stamp, status, payload))
|
||||
db.execute("UPDATE run_journal SET status = ?, finished_utc = ?, result = ? WHERE run_id = ?",
|
||||
(status, stamp, payload, run_id))
|
||||
current = self._row(db.execute("SELECT * FROM run_journal WHERE run_id = ?", (run_id,)).fetchone())
|
||||
db.execute("COMMIT")
|
||||
return self.get(run_id)
|
||||
return current
|
||||
|
||||
def resume(self, run_id):
|
||||
"""Mark a natively reconfirmed continuation; keep its last durable receipt."""
|
||||
with self._connect() as db:
|
||||
db.execute("BEGIN IMMEDIATE")
|
||||
row = db.execute("SELECT status FROM run_journal WHERE run_id = ?", (run_id,)).fetchone()
|
||||
row = self._row(db.execute("SELECT * FROM run_journal WHERE run_id = ?", (run_id,)).fetchone())
|
||||
if row is None:
|
||||
raise TaskCenterError("run_missing", "run does not exist")
|
||||
if row["status"] not in {"running", "paused", "blocked", "interrupted"}:
|
||||
raise TaskCenterError("run_terminal", "this run has no resumable execution")
|
||||
db.execute("UPDATE run_journal SET status = 'running', finished_utc = NULL WHERE run_id = ?", (run_id,))
|
||||
row.update(status='running', finished_utc=None)
|
||||
db.execute("COMMIT")
|
||||
return self.get(run_id)
|
||||
return row
|
||||
|
||||
def begin_retry(self, service, run_id, task_id, operation_keys):
|
||||
"""Persist one reserved retry baseline before its first CAD dispatch."""
|
||||
@@ -181,8 +184,9 @@ class RunJournal:
|
||||
db.execute('INSERT INTO run_journal_receipts (run_id,finished_utc,status,result) VALUES (?,?,?,?)',
|
||||
(run_id, stamp, 'running', payload))
|
||||
db.execute("UPDATE run_journal SET status='running',finished_utc=NULL,result=? WHERE run_id=?", (payload, run_id))
|
||||
row.update(status='running', finished_utc=None, result=value)
|
||||
db.execute('COMMIT')
|
||||
return self.get(run_id)
|
||||
return row
|
||||
|
||||
@staticmethod
|
||||
def _same_pending_retry(child, task_id, before, after):
|
||||
|
||||
Reference in new issue
Block a user