fix: bound task handoff and preserve native writer ownership

This commit is contained in:
阿白叔 committed 2026-11-16 18:57:36 +08:00
1 parent 0440b2efbf
commit ddff6bd857
18 files changed
+1397 -118

No files matched your search

+27 -3
View File
@@ -264,15 +264,34 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
job_path = root/'repair-request.json'
cancel = root/'cancel-repair.signal'
desktop = 'CbbRepair_'+uuid4().hex[:12]
job_path.write_text(json.dumps({'project': str(target.project), 'database': str(target.database),
from .operation_queue import current_context
context = current_context()
library = (maintenance_context or {}).get('library') or (context.library if context else str(target.project))
job = {'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, 'inspection_only': inspection_only},
ensure_ascii=False), encoding='utf-8')
'maintenance_context': maintenance_context, 'inspection_only': inspection_only,
'library': library, 'operation_id': root.name+'-'+uuid4().hex[:8],
'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_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)]
from .operation_queue import native_channel, task_stop
with native_channel(inspection_only=inspection_only is True):
return _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress, task_stop(stop), job)
def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress, stop, job):
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
check_active()
Path(job['start_gate']).touch()
# 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
@@ -307,4 +326,9 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
result['status'] = 'UNCONFIRMED'
return {**result, 'evidence_path': str(root)}
finally:
if worker.poll() is None and getattr(worker, 'session_record_path', None):
from .session_record import handoff_session
from .operation_queue import hold_native_handoff
handoff_session(worker.session_record_path, evidence_root=root, process=worker)
hold_native_handoff(worker, worker.session_record_path)
worker.close()