fix: fence final worker admission against UI shutdown

This commit is contained in:
阿白叔 committed 2026-11-17 00:00:50 +08:00
1 parent dbc685b9a5
commit eabf61c73b
13 files changed
+356 -46

No files matched your search

+8 -4
View File
@@ -275,6 +275,7 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
'operation': 'inspect' if inspection_only else 'repair',
'block': (maintenance_context or {}).get('block'),
'session_record_path': str(root/'session.json'), 'start_gate': str(root/'start-repair.signal')}
job['start_gate_protocol'] = 'event-v1'
job_path.write_text(json.dumps(job, ensure_ascii=False), encoding='utf-8')
command = ([sys.executable] if getattr(sys, 'frozen', False) else
[sys.executable, '-m', 'cbb_refresh_verify']) + ['--repair-worker', str(job_path)]
@@ -286,9 +287,7 @@ def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress,
from .desktop_worker import DesktopWorker
worker = DesktopWorker(command, desktop)
worker.bind_cancellation(cancel)
if hasattr(worker, 'bind_session'):
worker.bind_session(job)
from .operation_queue import check_active, native_channel
from .operation_queue import check_active, native_channel, commit_worker_start
native = native_channel(inspection_only=job.get('inspection_only') is True)
entered = False
# Worker admission includes filesystem/ownership checks before the native
@@ -297,10 +296,12 @@ def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress,
event_count = 0
cancelled = False
try:
if hasattr(worker, 'bind_session'):
worker.bind_session(job)
check_active()
native.__enter__()
entered = True
Path(job['start_gate']).touch()
commit_worker_start(worker, job)
while worker.poll() is None and time.monotonic()<deadline:
if not cancelled and stop is not None and stop.is_set():
worker.request_stop()
@@ -331,6 +332,9 @@ def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress,
if worker.returncode != 0 and result.get('status') in ('REPAIRED', 'NOT_IN_USE', 'IN_USE'):
result['status'] = 'UNCONFIRMED'
return {**result, 'evidence_path': str(root)}
except BaseException:
worker.request_stop()
raise
finally:
if entered:
native.__exit__(None, None, None)