fix: persist active task before worker launch
This commit is contained in:
1 parent
5ed8444d5d
commit
e5e628de4a
8 files changed
+90
-9
No files matched your search
@@ -279,6 +279,10 @@ class BatchCadRuntime:
|
||||
project, directory, expected = self._prepare_attempts(root, command, attempt_id, generation)
|
||||
self._active_attempts = list(expected)
|
||||
self._ensure_desktop(abort_event)
|
||||
# Make the current task/attempt durable before any worker or CAD
|
||||
# mutation can begin. A crash in the following window must protect
|
||||
# this task rather than a stale completed task from session.json.
|
||||
self._save(active_task=self.record['active_task'], active_attempt=attempt_id)
|
||||
before = project_fingerprint(project, self.root)
|
||||
status = internal_path(root / 'status.tsv')
|
||||
status_before = status.read_bytes() if status.exists() else None
|
||||
|
||||
@@ -24,6 +24,15 @@ _LIVE_SUPERVISORS = {}
|
||||
_WRITE_OPERATIONS = frozenset({'execute_task_queue', 'execute_quick_run_queue', 'execute_quick_run', 'recover_quick_run'})
|
||||
|
||||
|
||||
def _decode_process_output(value):
|
||||
if not isinstance(value, bytes):
|
||||
return str(value)
|
||||
try:
|
||||
return value.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
return value.decode('mbcs' if os.name == 'nt' else 'utf-8', errors='replace')
|
||||
|
||||
|
||||
def _mark_interrupted(root, journal, reason):
|
||||
from .batch_resources import write_record, _valid_record
|
||||
from .stop_control import protect_interruption
|
||||
@@ -343,11 +352,13 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
||||
try:
|
||||
while line := process.stdout.readline(1024 * 1024):
|
||||
if isinstance(line, bytes):
|
||||
stdout_tail.extend(line.decode('utf-8', errors='replace'))
|
||||
decoded = _decode_process_output(line)
|
||||
stdout_tail.extend(decoded)
|
||||
else:
|
||||
stdout_tail.extend(str(line))
|
||||
decoded = str(line)
|
||||
stdout_tail.extend(decoded)
|
||||
try:
|
||||
messages.put(json.loads(line))
|
||||
messages.put(json.loads(decoded))
|
||||
except (ValueError, UnicodeError):
|
||||
messages.put({'type': 'invalid'})
|
||||
finally:
|
||||
@@ -360,7 +371,7 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
||||
if not line:
|
||||
return
|
||||
if isinstance(line, bytes):
|
||||
stderr_tail.extend(line.decode('utf-8', errors='replace'))
|
||||
stderr_tail.extend(_decode_process_output(line))
|
||||
else:
|
||||
stderr_tail.extend(str(line))
|
||||
try:
|
||||
|
||||
@@ -116,8 +116,17 @@ class ProjectSessionWorker:
|
||||
if interactive:
|
||||
# The monitor owns the safe/unsafe distinction. Do not
|
||||
# turn a GUI close or ordinary pause into a timed kill.
|
||||
force_event = getattr(getattr(self.runtime, 'stop_event', None), 'force_event', None)
|
||||
last_notice = time.monotonic()
|
||||
while not self._done.wait(.1):
|
||||
pass
|
||||
if force_event is not None and force_event.is_set():
|
||||
self._abort.set()
|
||||
break
|
||||
if time.monotonic() - last_notice >= 15:
|
||||
import logging
|
||||
logging.getLogger(__name__).warning(
|
||||
'project_session_awaiting_close token=%s', self.token)
|
||||
last_notice = time.monotonic()
|
||||
close_grace = 60 if self.private_desktop else min(30, max(10, self._timeout))
|
||||
if not self._done.wait(close_grace):
|
||||
self._abort.set()
|
||||
|
||||
Reference in new issue
Block a user