fix: publish management receipt before orphan-exitable terminal state

This commit is contained in:
阿白叔 committed 2026-11-09 14:44:09 +08:00
1 parent 74a45eb5cf
commit a045683c8a
3 files changed
+24 -2

No files matched your search

@@ -36,4 +36,6 @@ The unreadable-window poisoning and oversized repeated-output findings target th
The final focused integration run passed 211 tests. New tests were first observed failing for missing dispatch/receipt facts, dispatch veto after accepted Remove, missing queue explanations, changed wait reasons, stale mapping cleanup and dialog lifecycle boundaries. Independent review's two queue timing findings were corrected and re-reviewed with no remaining important introduced finding.
The first full run exposed one terminal-publication race (1,773 passed, one failed): management wrote FINISHED before its result receipt, allowing the orphan watchdog to exit between them. The result is now flushed before FINISHED. The regression accepts either the normal failure exit or orphan exit only after checking the saved result and the absence of a subsequent native action. A new test first reproduced the missing receipt at the FINISHED transition; 159 focused lifecycle/management tests then passed. The failed full XML is preserved separately, and the full suite is rerun on the corrected tree.
Full-suite counts, source hashes and immutable XML copies are in the accompanying validation JSON. Compilation/diff checks and icon equality are checked on the integrated tree. No frozen package was rebuilt; the old iconfix package does not contain this revision. No real Mentor Save/Close/Add/Remove or shared/network/cross-machine acceptance was performed. ICDB automatic Repair remains off. No merge to main, formal release, issue closure, native address/lock deletion, foreground mouse control, or native process termination is authorized by this validation.
+2 -1
View File
@@ -1303,6 +1303,7 @@ def management_worker_main(request_path):
result['exception'] = _exception_details(error)
finally:
from .session_record import update_worker_state
update_worker_state(job, 'FINISHED' if result.get('safe_to_continue') is True else 'UNCONFIRMED')
_write_json(root/'result.json', result)
# FINISHED permits the orphan watchdog to exit immediately.
update_worker_state(job, 'FINISHED' if result.get('safe_to_continue') is True else 'UNCONFIRMED')
return 0 if result['success'] and result['safe_to_continue'] else 2
+20 -1
View File
@@ -103,7 +103,9 @@ def test_real_management_worker_parent_loss_waits_for_native_boundary(tmp_path):
while not cancel.exists() and time.monotonic()<deadline:
time.sleep(.02)
assert cancel.exists() and worker.poll() is None
assert worker.wait(5) == 2
# Either the normal failed result or orphan exit may win after return;
# both require the receipt to have been durably published already.
assert worker.wait(5) in (2, 75)
assert not continued.exists()
assert (tmp_path/'supervisor-lost.json').is_file()
assert json.loads((tmp_path/'result.json').read_text())['safe_to_continue'] is True
@@ -146,3 +148,20 @@ def test_remove_timeout_keeps_worker_observing_until_native_returns(tmp_path, mo
thread.join(3)
assert done.is_set()
assert json.loads((tmp_path/'result.json').read_text())['safe_to_continue'] is True
def test_terminal_management_state_cannot_precede_its_result_receipt(tmp_path, monkeypatch):
job = tmp_path/'request.json'
job.write_text(json.dumps(dict(operation='catalog', library=str(tmp_path/'lib.lmc'),
desktop='CbbManagement_expected', operation_id='terminal-order')))
monkeypatch.setattr(native, '_current_desktop', lambda: (None, 'wrong_desktop'))
from cbb_refresh_verify import session_record
observed = []
def terminal(job, phase, **kwargs):
if phase == 'FINISHED':
receipt = json.loads((tmp_path/'result.json').read_text('utf-8'))
assert receipt['safe_to_continue'] is True and receipt['success'] is False
observed.append(phase)
monkeypatch.setattr(session_record, 'update_worker_state', terminal)
assert native.management_worker_main(job) == 2
assert observed == ['FINISHED']