fix: inspect native ICDB occupancy before bounded repair

This commit is contained in:
阿白叔 committed 2026-11-04 12:26:09 +08:00
1 parent cb1326688b
commit e14a864b37
17 files changed
+617 -153

No files matched your search

+16 -5
View File
@@ -253,8 +253,10 @@ def repair_release_state(request, target, native_result):
def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progress=None,
maintenance_context=None):
maintenance_context=None, inspection_only=False, stop=None):
"""Supervise the GUI on its own desktop; a repair timeout never kills it."""
if stop is not None and stop.is_set():
return {'status': 'CANCELLED', 'detail': '原生操作启动前已取消', 'release': {'safe_to_continue': True}}
from .desktop_worker import DesktopWorker
root = Path(root)
root.mkdir(parents=True, exist_ok=True)
@@ -264,16 +266,23 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
job_path.write_text(json.dumps({'project': str(target.project), 'database': str(target.database),
'root': str(root), 'mentor_bin': str(mentor_bin or ''), 'timeout': timeout_seconds,
'cancel_signal': str(cancel), 'supervisor_pid': os.getpid(), 'desktop': desktop,
'maintenance_context': maintenance_context},
'maintenance_context': maintenance_context, 'inspection_only': inspection_only},
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)]
worker = DesktopWorker(command, desktop)
worker.bind_cancellation(cancel)
deadline = time.monotonic()+max(1, float(timeout_seconds))+5
# Worker admission includes filesystem/ownership checks before the native
# timeout begins. Bound that preparation separately; never extend on polls.
deadline = time.monotonic()+60+max(1, float(timeout_seconds))+5
event_count = 0
cancelled = False
try:
while worker.poll() is None and time.monotonic()<deadline:
if not cancelled and stop is not None and stop.is_set():
worker.request_stop()
cancelled = True
deadline = min(deadline, time.monotonic()+5)
event_file = root/'repair-events.jsonl'
if progress and event_file.is_file():
lines = event_file.read_text('utf-8').splitlines()
@@ -287,11 +296,13 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
outcome = root/'repair-result.json'
if worker.poll() is None or not outcome.is_file():
worker.request_stop()
return {'status': 'TIMEOUT_UNRELEASED', 'worker_pid': worker.pid, 'desktop': desktop,
return {'status': 'CANCELLED_UNRELEASED' if cancelled else 'TIMEOUT_UNRELEASED', 'worker_pid': worker.pid, 'desktop': desktop,
'release': {'safe_to_continue': False},
'detail': '原生修复尚未确认结束,保留操作并停止批次', 'evidence_path': str(root)}
result = json.loads(outcome.read_text('utf-8'))
if worker.returncode != 0 and result.get('status') == 'REPAIRED':
if cancelled:
result.update(status='CANCELLED', repair_required=False)
if worker.returncode != 0 and result.get('status') in ('REPAIRED', 'NOT_IN_USE', 'IN_USE'):
result['status'] = 'UNCONFIRMED'
return {**result, 'evidence_path': str(root)}
finally: