fix: preserve blocked state after rebuild cleanup failure

This commit is contained in:
阿白叔 committed 2026-10-30 08:51:00 +08:00
1 parent 12895e9868
commit 7da623d055
5 files changed
+154 -3

No files matched your search

@@ -101,6 +101,8 @@ class BatchCadRuntime:
self._project_attempts = {}
self._logging = None
self._active_evidence = None
self._close_failure = None
self._close_failure_rebuild = False
def bind_logs(self, context, task_ids):
"""Keep every participating task's final release outcome visible."""
@@ -381,13 +383,22 @@ class BatchCadRuntime:
if self.record['state'] == 'released':
return
reason = reason or ('rebuild' if rebuilding else 'batch_end')
if self._close_failure is not None and self._close_failure_rebuild and reason != 'manual_retry':
raise BatchResourceCleanupError(str(self._close_failure), completed_result=self.result,
cleanup_error=self._close_failure)
if reason == 'manual_retry':
self._close_failure = None
started = time.monotonic()
self._release_log('started', reason=reason)
try:
self._close_resources(rebuilding=rebuilding)
except Exception as error:
self._close_failure = error
self._close_failure_rebuild = rebuilding
self._release_log('failed', reason=reason, elapsed=time.monotonic() - started, error=error)
raise
self._close_failure = None
self._close_failure_rebuild = False
self._release_log('succeeded', reason=reason, elapsed=time.monotonic() - started)
def _close_resources(self, *, rebuilding=False):
@@ -404,8 +415,10 @@ class BatchCadRuntime:
except Exception as error:
if rebuilding:
self.record['shutdown_warning'] = str(error)
else:
errors.append(str(error))
# A rebuild must not proceed while the previous CAD owner has
# an unconfirmed shutdown. Keep the warning for diagnostics,
# but retain the failure in the resource gate as well.
errors.append(str(error))
finally:
cad_record = getattr(cad, 'record', {})
cad_record = cad_record if isinstance(cad_record, dict) else {}
@@ -68,7 +68,11 @@ def wait_for_resolution(control, root, error):
resolution_error=str(error), stop_requested=True, safe_stop=False)
_publish_progress(root / 'worker-progress.json', record)
while True:
if control.force_event.wait(.1):
# Keep the retry latency short. The caller may have already requested
# force while the initial protection write was failing; a long polling
# interval makes the UI appear stuck and widens the window in which a
# forced-stop request can be observed before its evidence is retried.
if control.force_event.wait(.01):
try:
protect()
except OSError as failure: