fix: preserve async writer ownership and bounded handoff

This commit is contained in:
阿白叔 committed 2026-11-16 19:51:21 +08:00
1 parent ddff6bd857
commit 8374cabe5c
12 files changed
+692 -47

No files matched your search

+14 -6
View File
@@ -278,9 +278,8 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
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)
from .operation_queue import task_stop
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):
@@ -289,15 +288,19 @@ def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress,
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()
from .operation_queue import check_active, native_channel
native = native_channel(inspection_only=job.get('inspection_only') is True)
entered = False
# 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:
check_active()
native.__enter__()
entered = True
Path(job['start_gate']).touch()
while worker.poll() is None and time.monotonic()<deadline:
if not cancelled and stop is not None and stop.is_set():
worker.request_stop()
@@ -313,6 +316,9 @@ def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress,
break
event_count += 1
time.sleep(.2)
if worker.poll() is not None:
native.__exit__(None, None, None)
entered = False
outcome = root/'repair-result.json'
if worker.poll() is None or not outcome.is_file():
worker.request_stop()
@@ -326,6 +332,8 @@ def _supervise_repair(command, desktop, cancel, root, timeout_seconds, progress,
result['status'] = 'UNCONFIRMED'
return {**result, 'evidence_path': str(root)}
finally:
if entered:
native.__exit__(None, None, None)
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