fix: preserve async writer ownership and bounded handoff
This commit is contained in:
1 parent
ddff6bd857
commit
8374cabe5c
12 files changed
+692
-47
No files matched your search
@@ -965,6 +965,11 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
worker_launch_attempted = False
|
||||
native = native_channel()
|
||||
phase_entered = False
|
||||
def end_native_phase():
|
||||
nonlocal phase_entered
|
||||
if phase_entered:
|
||||
native.__exit__(None, None, None)
|
||||
phase_entered = False
|
||||
try:
|
||||
timing.begin('worker_setup')
|
||||
with (root/'worker.log').open('w', encoding='utf-8') as log:
|
||||
@@ -1186,6 +1191,7 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
return finish(VerifyResult(status, stderr=detail, safe_to_continue=False))
|
||||
return finish(VerifyResult('TIMEOUT', stderr='操作超时,当前项未完成。', error_stage=phase.value, safe_to_continue=False))
|
||||
time.sleep(.2)
|
||||
end_native_phase() # Exact worker exit precedes all optional outcome/evidence I/O.
|
||||
worker_result = root/'outcome.json'
|
||||
if not worker_result.exists():
|
||||
return finish(VerifyResult('FAIL', stderr=f'执行器异常退出 ({process.returncode}),见 worker.log', safe_to_continue=False))
|
||||
@@ -1215,6 +1221,10 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
close_errors = []
|
||||
worker_exited = False
|
||||
automation_release = {'safe_to_continue': False}
|
||||
if 'process' not in locals() or process.poll() is not None or getattr(process, 'session_record_path', None):
|
||||
# A gated worker owns its writer barrier and inherited sidecar.
|
||||
# Parent admission must not block controls needed for its exit.
|
||||
end_native_phase()
|
||||
if 'dialog_agent' in locals() and dialog_agent is not None:
|
||||
try:
|
||||
dialog_agent.close()
|
||||
@@ -1238,10 +1248,8 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
{'stage': 'session_observation', 'block': request.block_name, **state}))
|
||||
_notify_progress(progress, {'stage': 'session_handoff', 'block': request.block_name,
|
||||
'detail': '已转后台观察,可查看状态'})
|
||||
if getattr(process, 'native_write_pending', lambda: None)() is not False:
|
||||
from .operation_queue import hold_native_handoff
|
||||
hold_native_handoff(process, process.session_record_path)
|
||||
worker_exited = process.poll() is not None
|
||||
from .operation_queue import hold_native_handoff
|
||||
hold_native_handoff(process, process.session_record_path)
|
||||
except Exception as error:
|
||||
close_errors.append(str(error))
|
||||
if 'process' in locals():
|
||||
@@ -1333,8 +1341,7 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
if phase_entered:
|
||||
native.__exit__(None, None, None)
|
||||
end_native_phase()
|
||||
|
||||
if result.status == 'PASS' and not request.diagnostic_only:
|
||||
timing.begin('library_flag')
|
||||
|
||||
Reference in new issue
Block a user