fix: allow same-window retry after early PCB cancellation
This commit is contained in:
1 parent
806c1696ab
commit
6aed02d26b
4 files changed
+84
-12
No files matched your search
@@ -755,9 +755,15 @@ def execute_job(job, emit):
|
||||
command=list(command), strategy='reusable_circuit_direct')
|
||||
pcb_deadline = (dispatch_deadline if job.get('native_lm_verify') else
|
||||
time.monotonic()+pcb_startup_timeout_seconds(job['timeout']))
|
||||
cancelled_startup = False
|
||||
while time.monotonic() < pcb_deadline:
|
||||
if job.get('cancel_signal') and Path(job['cancel_signal']).exists():
|
||||
raise RuntimeError('VERIFY_CANCELLED: PCB 启动期间收到停止请求')
|
||||
if not cancelled_startup and job.get('cancel_signal') and Path(job['cancel_signal']).exists():
|
||||
if not prewrite_eligible or launcher_process is None:
|
||||
raise RuntimeError('VERIFY_CANCELLED: PCB 启动期间收到停止请求')
|
||||
cancelled_startup = True
|
||||
# Cancellation after CreateProcess may precede discovery of its
|
||||
# child. Bind the exact client for cleanup without attaching COM.
|
||||
pcb_deadline = min(pcb_deadline, time.monotonic()+5)
|
||||
records = _process_details('ExpeditionPCB.exe')
|
||||
worker = select_reusable_circuit_worker(
|
||||
records,
|
||||
@@ -786,6 +792,8 @@ def execute_job(job, emit):
|
||||
pass
|
||||
break
|
||||
time.sleep(.2)
|
||||
if cancelled_startup or job.get('cancel_signal') and Path(job['cancel_signal']).exists():
|
||||
raise RuntimeError('VERIFY_CANCELLED: PCB 启动期间收到停止请求')
|
||||
if worker_pid is None:
|
||||
if job.get('native_lm_verify'):
|
||||
raise RuntimeError('VERIFY_DISPATCH_FAILED: LM 菜单返回但未观察到目标 PCB,未执行校验')
|
||||
@@ -1021,14 +1029,15 @@ def worker_main(request_path):
|
||||
|
||||
def emit(**event):
|
||||
from .session_record import update_worker_state
|
||||
stage = event.get('stage')
|
||||
phase = {'save_start': 'NATIVE_CALL', 'integration_action': 'NATIVE_CALL',
|
||||
'integration_action_complete': 'POSTCALL', 'saved_and_closed': 'RELEASE_CHECK',
|
||||
'complete': 'FINISHED', 'failed': 'UNCONFIRMED'}.get(event.get('stage'))
|
||||
if (event.get('stage') == 'pcb_worker_started' and job.get('diagnostic_only') is False
|
||||
'complete': 'FINISHED', 'failed': 'UNCONFIRMED'}.get(stage)
|
||||
if (stage in ('pcb_launch', 'pcb_worker_started') and job.get('diagnostic_only') is False
|
||||
and not (job.get('native_lm_verify') or job.get('post_repair_consent')
|
||||
or job.get('interactive_input'))):
|
||||
# The watchdog may retire this worker before its first native write.
|
||||
phase = 'PRECALL'
|
||||
# Keep the worker alive through PID registration after supervisor loss.
|
||||
phase = 'UNCONFIRMED' if stage == 'pcb_launch' else 'PRECALL'
|
||||
identities = [(role, event.get(key)) for role, key in
|
||||
(('native', 'pcb_pid'), ('native', 'lm_pid'))
|
||||
if event.get(key)]
|
||||
@@ -1046,13 +1055,16 @@ def worker_main(request_path):
|
||||
# Save and Close run in one already admitted helper.
|
||||
continuing_save = event.get('helper_exited') is not True
|
||||
phase = 'NATIVE_CALL' if continuing_save else 'POSTCALL'
|
||||
if phase or identities:
|
||||
registered_startup = stage == 'pcb_worker_started' and phase == 'PRECALL'
|
||||
if (phase or identities) and not registered_startup:
|
||||
update_worker_state(job, phase or 'UNCONFIRMED', identities=identities,
|
||||
write_outcome=facts, continuation=continuing_save)
|
||||
event.update(time=time.strftime('%Y-%m-%d %H:%M:%S'), block=job['block_name'],
|
||||
monotonic_seconds=time.monotonic())
|
||||
with (root/'events.jsonl').open('a', encoding='utf-8') as stream:
|
||||
stream.write(json.dumps(event, ensure_ascii=False) + '\n')
|
||||
if registered_startup:
|
||||
update_worker_state(job, phase, identities=identities)
|
||||
|
||||
try:
|
||||
if job.get('supervisor_pid'):
|
||||
|
||||
@@ -1004,7 +1004,8 @@ class MainWindow(QWidget):
|
||||
def _eligible_names(self, *, checked_only=False, require_status=False):
|
||||
records = self.selected_records() if checked_only else self.visible_records()
|
||||
return [r.name for r in records if r.status != 'READY' and r.name not in self.skipped_names
|
||||
and (not require_status or self.catalog_reader is None or r.status == 'PENDING')]
|
||||
and (not require_status or self.catalog_reader is None or r.status == 'PENDING'
|
||||
or r.status_source == 'cancelled_verify')]
|
||||
|
||||
def _maintenance_names(self):
|
||||
records = self.selected_records() or self.visible_records()
|
||||
@@ -2003,7 +2004,7 @@ class MainWindow(QWidget):
|
||||
finally:
|
||||
pythoncom.CoUninitialize()
|
||||
|
||||
def _apply_refreshed_records(self, payload):
|
||||
def _apply_refreshed_records(self, payload, *, cancelled_retries=()):
|
||||
names, statuses, reasons, error = payload
|
||||
self._publish_check_statuses(self.mentor_lmc_path or self.loaded_path,
|
||||
{name: statuses.get(name, 'UNKNOWN') for name in names})
|
||||
@@ -2015,7 +2016,10 @@ class MainWindow(QWidget):
|
||||
status = statuses.get(name, 'UNKNOWN')
|
||||
if status not in STATUS_LABELS:
|
||||
status = 'UNKNOWN'
|
||||
self._records_by_name[name] = replace(self._records_by_name[name], status=status)
|
||||
record = self._records_by_name[name]
|
||||
source = ('cancelled_verify' if name in cancelled_retries else
|
||||
'unknown' if status == 'UNKNOWN' else 'authoritative')
|
||||
self._records_by_name[name] = replace(record, status=status, status_source=source)
|
||||
self.ready_names.discard(name)
|
||||
if reasons is not None:
|
||||
self.skip_reasons.pop(name, None)
|
||||
@@ -2227,7 +2231,11 @@ class MainWindow(QWidget):
|
||||
elif affected:
|
||||
reason = ('状态尚未复核,请重新读取。' if all(r.safe_to_continue for r in results)
|
||||
else '会话或数据库安全未确认;暂缓原生状态复核,请确认释放后重新读取。')
|
||||
self._defer_status_refresh(affected, reason)
|
||||
cancelled = {request.block_name for request, result in zip(self._batch_requests, results)
|
||||
if result.status == 'CANCELLED' and request.block_name in self._records_by_name
|
||||
and (self._records_by_name[request.block_name].status == 'PENDING'
|
||||
or self._records_by_name[request.block_name].status_source == 'cancelled_verify')}
|
||||
self._apply_refreshed_records((tuple(affected), {}, None, reason), cancelled_retries=cancelled)
|
||||
from shiboken6 import isValid
|
||||
summary = getattr(self, 'summary', None)
|
||||
self.status_label.setText(summary.text().replace('\n', ' ') if summary is not None and isValid(summary)
|
||||
|
||||
Reference in new issue
Block a user