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

+19 -3
View File
@@ -2,10 +2,19 @@
from collections.abc import Sequence
def recheck_failed_release(library, block, result):
def recheck_failed_release(library, block, result, *, stop=None, timeout_seconds=10):
"""Refresh resource facts after a late exit; keep the original business failure."""
if result.safe_to_continue or not result.evidence_path:
return result
from .operation_queue import BatchTaskContext, TaskHandoff, current_context, task_stop
if current_context() is None:
context = BatchTaskContext(library=str(library), targets=(block,))
try:
return context.run(lambda: recheck_failed_release(library, block, result, stop=stop),
stop=stop, timeout_seconds=timeout_seconds)
except TaskHandoff:
return result
stop = task_stop(stop)
from pathlib import Path
from dataclasses import replace
import json
@@ -37,9 +46,16 @@ def recheck_failed_release(library, block, result):
bound.append(candidate)
if not bound:
return result # A generic timeout without a bound owner is not an exit fact.
proof = release_retained_library(library, evidence.parent/'late-release', block_name=block)
if proof.get('status') != 'RELEASE_CONFIRMED' or Path(proof.get('library', '')).resolve() != Path(library).resolve():
from .operation_queue import check_active
check_active()
proof = release_retained_library(library, evidence.parent/'late-release', block_name=block, stop=stop)
scope = proof.get('resource_scope')
if (proof.get('status') != 'RELEASE_CONFIRMED' or proof.get('lease_state') != 'RELEASED'
or not isinstance(scope, dict) or scope.get('scope_state') != 'OBSERVED'
or proof.get('blocked_resources') != []
or Path(proof.get('library', '')).resolve() != Path(library).resolve()):
return result
check_active()
evidence.with_name('late-release-result.json').write_text(json.dumps(dict(
business_status=result.status, safe_to_continue=True, release_proof=proof),
ensure_ascii=False, default=str, indent=2), 'utf-8')