fix: resume orphan cleanup after a startup prompt

This commit is contained in:
阿白叔 committed 2026-11-25 14:44:06 +08:00
1 parent 33a41b25fb
commit 4e7efe4f41
2 files changed
+33 -13

No files matched your search

+19 -10
View File
@@ -974,7 +974,7 @@ def _orphan_prewrite_client(path, job, session, state, identities):
clients = [p for p in identities if p.get('role') == 'native' and p['pid'] == pid]
if len(clients) != 1 or not is_reusable_circuit_pcb(clients[0]['image'], started['command'], job['pcb']):
return None
return clients[0]
return clients[0], ready.get('baseline')
def recoverable_orphan_session(path):
@@ -1102,8 +1102,11 @@ def finish_owned_idle_session(path, *, stop=None):
workers = [p for p in identities if p.get('role') in ('worker','helper')]
clients = [p for p in identities if p.get('role') == 'native' and Path(p['image']).name.casefold() == client_name]
orphan_client = None
orphan_baseline = None
if operation == 'verify' and result is None and not _saved_and_closed(_worker_save_facts(state, identities)):
orphan_client = _orphan_prewrite_client(path, job, session, state, identities)
orphan = _orphan_prewrite_client(path, job, session, state, identities)
if orphan is not None:
orphan_client, orphan_baseline = orphan
clients = [orphan_client] if orphan_client is not None else []
if not workers or len(clients) != 1: return False
if any(r.get('operation_id') != session['operation_id'] for r in active_write_records(session['library'])):
@@ -1135,19 +1138,15 @@ def finish_owned_idle_session(path, *, stop=None):
target, _ = close_target(client_name, windows, incomplete=_window_error(snapshot, client['pid']))
if target is None or not any(w.get('documents') for w in windows):
return target
if orphan_client is None:
if not isinstance(orphan_baseline, dict) or not {'started_ns', 'files'} <= orphan_baseline.keys():
return None
# PCB can finish loading after its worker has stopped. Close
# only the design independently bound by this launch's logs.
from .diagnostic_open import _load_evidence, _target_frame
from .failed_session import cancelled_prewrite_startup
baseline = cancelled_prewrite_startup(job, client['pid'])
if baseline is None:
return None
frames = _legacy_diagnostic_windows(dict(client, cleanup_desktop=desktop))
frame = _target_frame(frames, Path(job['pcb']).stem)
if (frame and frame['hwnd'] == target['hwnd']
and _load_evidence(job, client['pid'], baseline, require_autosave=False) is not None):
and _load_evidence(job, client['pid'], orphan_baseline, require_autosave=False) is not None):
return target
return None
def startup_prompt():
@@ -1160,6 +1159,8 @@ def finish_owned_idle_session(path, *, stop=None):
modals = [w for w in windows if w['class'] == '#32770']
if len(modals) != 1:
return None
if session.get('owned_startup_prompt') == modals[0]['hwnd']:
return None
with _window_desktop(desktop):
modal = modals[0]
observed = _startup_snapshot(modal['hwnd'], client['pid'])
@@ -1172,10 +1173,10 @@ def finish_owned_idle_session(path, *, stop=None):
and event.get('hwnd') == modal['hwnd'])
for event in read('events.jsonl', lines=True)):
return None
return observed, tip.handle, 'tip'
return observed, tip.handle, 'tip', modal['hwnd']
target = _cancel_target(observed)
if target is not None and (orphan_client is not None or target[0] == 'database_load_log'):
return observed, target[1].handle, target[0]
return observed, target[1].handle, target[0], modal['hwnd']
return None
if not same_client(): return False
@@ -1238,6 +1239,14 @@ def finish_owned_idle_session(path, *, stop=None):
break
if stop is not None and stop.is_set():
break
elif prompt is not None:
# Allow a later close after the confirmed startup prompt
# disappears and the design completes loading.
latest = read('session.json')
if latest.get('owned_idle_cleanup') == claim:
latest.pop('owned_idle_cleanup')
latest['owned_startup_prompt'] = prompt[3]
write_session_record(path, latest)
exited = win32event.WaitForSingleObject(handle,0) == win32con.WAIT_OBJECT_0
write_session_record(path.with_name('owned-idle-cleanup-result.json'),dict(
operation_id=session['operation_id'],library=session['library'],