fix: retry incomplete native window observations within deadlines

This commit is contained in:
阿白叔 committed 2026-11-17 00:57:45 +08:00
1 parent 07206ce0d1
commit 36ff964230
2 files changed
+98 -3

No files matched your search

+17 -3
View File
@@ -301,6 +301,20 @@ def check_target_window(job, pcb_pid, *, emit, error_reader, launcher_process=No
if not isinstance(baseline, dict) or 'started_ns' not in baseline or 'files' not in baseline:
raise RuntimeError('DIAGNOSTIC_BASELINE_REQUIRED: snapshot before native launch')
session = _NativeSession(job, int(pcb_pid), launcher_process)
def scan(deadline, *, closing=False):
while True:
if not closing:
_cancel(job)
try:
return _windows(int(pcb_pid))
except RuntimeError as error:
if str(error) != 'DIAGNOSTIC_WINDOW_LIMIT: window scan exceeded 0.2s':
raise
# Discard the incomplete snapshot; no control action may use it.
emit(stage='diagnostic_window_retry', detail=str(error))
if time.monotonic() >= deadline:
raise
time.sleep(min(.1, max(0, deadline-time.monotonic())))
try:
deadline = time.monotonic() + max(.01, float(job['timeout']))
while True:
@@ -310,7 +324,7 @@ def check_target_window(job, pcb_pid, *, emit, error_reader, launcher_process=No
raise RuntimeError(str(error))
if not session.pcb_alive():
raise RuntimeError('DIAGNOSTIC_OPEN_UNCONFIRMED: target PCB exited before loaded evidence')
windows = _windows(int(pcb_pid))
windows = scan(deadline)
if any(window['pid'] != int(pcb_pid) for window in windows):
raise RuntimeError('DIAGNOSTIC_PID_MISMATCH')
frame = _target_frame(windows, Path(job['pcb']).stem)
@@ -328,7 +342,7 @@ def check_target_window(job, pcb_pid, *, emit, error_reader, launcher_process=No
time.sleep(.1)
# Re-read the exact PID/frame before the sole close request.
_cancel(job)
windows = _windows(int(pcb_pid))
windows = scan(deadline)
_pending_prompt(windows, frame=frame, pcb_name=Path(job['pcb']).name)
current = _target_frame(windows, Path(job['pcb']).stem)
if current is None or current['hwnd'] != frame['hwnd']:
@@ -341,7 +355,7 @@ def check_target_window(job, pcb_pid, *, emit, error_reader, launcher_process=No
while session.pcb_alive() or session.launcher_alive():
# Cancellation stops future work; an accepted normal close must
# still finish before its queue slot can be safely released.
windows = _windows(int(pcb_pid)) if session.pcb_alive() else []
windows = scan(close_deadline, closing=True) if session.pcb_alive() else []
previous_clicks = set(clicked)
pending_error = None
try: