fix: acknowledge diagnostic prompt ownership before native close
This commit is contained in:
1 parent
de81bbf293
commit
4402486baa
5 files changed
+232
-16
No files matched your search
@@ -413,11 +413,39 @@ def phase_for_event(event, current=None):
|
||||
|
||||
|
||||
def _diagnostic_close_event(job, event, target_pid):
|
||||
return (job.get('diagnostic_only') is True and event.get('stage') == 'diagnostic_wm_close'
|
||||
close_id = event.get('close_id')
|
||||
return (job.get('diagnostic_only') is True and event.get('stage') == 'diagnostic_close_requested'
|
||||
and target_pid is not None and event.get('pcb_pid') == target_pid
|
||||
and type(event.get('hwnd')) is int and event['hwnd'] > 0
|
||||
and isinstance(close_id, str) and len(close_id) == 32 and all(c in '0123456789abcdef' for c in close_id)
|
||||
and bool(job.get('operation_id')) and event.get('operation_id') == job['operation_id']
|
||||
and all(event.get(key) == job.get(key) for key in ('project', 'pcb', 'desktop')))
|
||||
and all(job.get(key) and event.get(key) == job[key] for key in ('project', 'pcb', 'desktop')))
|
||||
|
||||
|
||||
def _acknowledge_diagnostic_close(job, event, stop):
|
||||
from .operation_queue import check_active
|
||||
check_active()
|
||||
if stop is not None and stop.is_set() or Path(job['cancel_signal']).exists():
|
||||
raise InterruptedError('VERIFY_CANCELLED: diagnostic handoff cancelled')
|
||||
ack = Path(job['root'])/'diagnostic-close-ack.json'
|
||||
pending = ack.with_suffix('.pending')
|
||||
pending.write_text(json.dumps({key: event[key] for key in
|
||||
('pcb_pid', 'hwnd', 'operation_id', 'desktop', 'project', 'pcb', 'close_id')}), encoding='utf-8')
|
||||
check_active()
|
||||
if stop is not None and stop.is_set() or Path(job['cancel_signal']).exists():
|
||||
raise InterruptedError('VERIFY_CANCELLED: diagnostic handoff cancelled')
|
||||
pending.replace(ack)
|
||||
|
||||
|
||||
def _close_intent_after_poll(job, events, offset, target_pid):
|
||||
if not job.get('diagnostic_only') or not events.exists(): return None
|
||||
with events.open(encoding='utf-8') as stream:
|
||||
stream.seek(offset)
|
||||
for line in stream:
|
||||
try: event = json.loads(line)
|
||||
except json.JSONDecodeError: break
|
||||
if _diagnostic_close_event(job, event, target_pid): return event
|
||||
return None
|
||||
|
||||
|
||||
def classify_verify_dispatch(*, verify_invoked, invoke_returned, target_pid, observation):
|
||||
@@ -1055,6 +1083,7 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
break
|
||||
timing.record(event)
|
||||
if _diagnostic_close_event(job, event, target_pid):
|
||||
_acknowledge_diagnostic_close(job, event, stop)
|
||||
diagnostic_closing = True
|
||||
if event.get('pcb_pid'): target_pid = event['pcb_pid']
|
||||
if event.get('launcher_pid'): launcher_pid = event['launcher_pid']
|
||||
@@ -1116,6 +1145,13 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
dialog_result = dialog_supervisor.poll()
|
||||
else:
|
||||
dialog_result = dialog_supervisor.poll()
|
||||
if not diagnostic_closing:
|
||||
intent = _close_intent_after_poll(job, events, offset, target_pid)
|
||||
if intent is not None:
|
||||
_acknowledge_diagnostic_close(job, intent, stop)
|
||||
diagnostic_closing = True
|
||||
from .dialog_supervisor import DialogPollResult
|
||||
dialog_result = DialogPollResult(activity=False)
|
||||
if (version_prompt is not None and consent is None and dialog_agent is not None
|
||||
and not request.diagnostic_only and not request.native_lm_verify
|
||||
and dialog_result.error_code == 'DATABASE_RECOVERY_REQUIRED'
|
||||
|
||||
Reference in new issue
Block a user