chore(release): prepare 0.4.1 (#6570)

Prepare version 0.4.1 and document the retained legacy upgrade path.

Avoid false busy update handoffs from disabled or not-yet-due idle scans. Keep real work, maintenance, lease and data-protection checks intact.

Retain safe package-failure diagnostics and cancellable test-controller progress checks. Reduce Windows installer startup contention without changing command deadlines or behavioral assertions.

Validated on the reviewed head with all required PR checks and the exact five-platform candidate. Historical package and recovery coverage remains as documented in the release acceptance record. Publication is separate; this merge does not create a tag, release, upload or feed change.
This commit is contained in:
Xubin Ren authored and GitHub committed 2026-11-06 20:48:57 +08:00
1 parent 1a89a25abd
commit cdaae66c89
15 files changed
+310 -37

No files matched your search

+91 -5
View File
@@ -27,7 +27,7 @@ import sqlite3
import subprocess
import sys
import time
from contextlib import ExitStack, closing, contextmanager
from contextlib import ExitStack, closing, contextmanager, suppress
from pathlib import Path
from typing import TYPE_CHECKING
from unittest.mock import patch
@@ -44,6 +44,11 @@ TWO_JOURNEY_SCENARIOS = {"upgrade-again", "import-failure", "restart-failure", "
# Each lane retains the existing per-command deadlines and cleanup. This outer
# bound also covers a stuck controller; it is not permission to leave it running.
LANE_TIMEOUT = 30 * 60
PREFLIGHT_MODULES = {"update_handoff.py", "update_worker.py", "update_plan.py", "update_stop.py",
"update_profiles.py", "release_feed.py", "installation_lock.py", "data_access.py"}
STOP_STATES = {"ready", "busy", "released", "stopping", "refused"}
BUSY_FLAGS = {"paused", "active", "inbound", "events", "pending_queues", "active_tasks",
"background_tasks", "deferred_automation_turns", "channel_delivery", "registered_work"}
def digest(path: Path) -> str:
@@ -59,6 +64,41 @@ def write(path: Path, value) -> None:
path.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
def phase_failure(root: Path, phase: str, error: Exception) -> None:
"""Export a failed probe location, not exception values or private journals."""
lines = []
traceback = error.__traceback__
while traceback is not None:
if traceback.tb_frame.f_code.co_filename == __file__:
lines.append(traceback.tb_lineno)
traceback = traceback.tb_next
record = {"phase": phase, "error_type": type(error).__name__, "probe_lines": lines}
# Read with stdlib only: the target package can be deliberately unimportable.
# Messages, commands, paths, identifiers and arbitrary phase values stay local.
with suppress(OSError, ValueError, KeyError, TypeError):
directory = Path(read(root / "launch.json")["directory"])
status = read(directory / "status.json")
record["update_phase"] = (status["phase"] if status["phase"] in {
"succeeded", "restored", "failed", "restart_failed", "handoff_failed",
} else "incomplete")
record["mutation_started"] = status["mutation_started"] is True
record["recovery_needs_attention"] = read(directory / "supervision.json").get("state") == "needs_attention"
preflight = read(directory / "acceptance-preflight.json")
record["preflight_error"] = (preflight["error_type"] if preflight["error_type"] in {
"ValueError", "OSError", "RuntimeError", "ReleaseFeedError", "InstallationBusyError",
"TimeoutError", "CalledProcessError", "FileNotFoundError", "PermissionError",
} else "OtherException")
record["preflight_frames"] = [[row[0], row[1]] for row in preflight["frames"]
if isinstance(row, list) and len(row) >= 2
and row[0] in PREFLIGHT_MODULES and type(row[1]) is int]
record["stop_states"] = sorted({value for value in preflight.get("stop_states", [])
if isinstance(value, str) and value in STOP_STATES})
busy = read(directory / "acceptance-busy.json")
record["busy_flags"] = {key: value for key, value in busy.items()
if key in BUSY_FLAGS and type(value) is bool}
write(root / "phase-failure.json", record)
class Timings:
"""Separate, incrementally persisted evidence; never include commands or logs."""
@@ -168,6 +208,48 @@ def transport():
raise OSError('Injected backup write failure')
'''.encode() + needle)
files["nanobot/update_worker.py"] = worker
# Observe an old-runtime preflight refusal without changing its decision,
# shutdown, worker or recovery semantics. Never export exception values.
handoff = files["nanobot/update_handoff.py"].replace(b"\r\n", b"\n")
files["nanobot/update_handoff.py"] = replace_once(handoff, b" except Exception:\n", f''' except Exception as acceptance_error:
from nanobot.update_worker import read_record, write_record
acceptance_trace = acceptance_error.__traceback__
acceptance_frames = []
while acceptance_trace is not None:
acceptance_name = Path(acceptance_trace.tb_frame.f_code.co_filename).name
if acceptance_name in {sorted(PREFLIGHT_MODULES)!r}:
acceptance_frames.append([acceptance_name, acceptance_trace.tb_lineno])
acceptance_trace = acceptance_trace.tb_next
write_record(directory / 'acceptance-preflight.json', {{
'error_type': type(acceptance_error).__name__, 'frames': acceptance_frames,
'stop_states': [value for path in (directory / 'stop-replies').glob('*.json')
if (value := read_record(path).get('state')) in {sorted(STOP_STATES)!r}],
}})
'''.encode())
# Diagnose a real idle-admission refusal in the disposable old gateway.
# Observe booleans only, after the original guard has already refused.
stop = files.get("nanobot/update_stop.py")
if stop is not None:
needle = b" except (RuntimeBusyError, RuntimeMaintenanceError):\n"
files["nanobot/update_stop.py"] = replace_once(stop.replace(b"\r\n", b"\n"), needle, needle + b''' try:
from nanobot.update_worker import write_record
acceptance_owner = maintenance.__self__
acceptance_bus = acceptance_owner.bus
acceptance_flags = {
'paused': acceptance_bus.admission.paused,
'active': bool(acceptance_bus.admission._active),
'inbound': bool(acceptance_bus.inbound_size),
'events': bool(acceptance_bus.has_pending_events),
**{name.removeprefix('_'): bool(getattr(acceptance_owner, name)) for name in (
'_pending_queues', '_active_tasks', '_background_tasks', '_deferred_automation_turns')},
'channel_delivery': any(check() for check in acceptance_bus.admission._pending_checks
if getattr(check, '__qualname__', '').startswith('ChannelManager.')),
'registered_work': any(check() for check in acceptance_bus.admission._pending_checks),
}
write_record(directory / 'acceptance-busy.json', acceptance_flags)
except Exception:
pass # Diagnostic failure must not alter the existing refusal.
''')
if scenario == "restore-interruption":
needle = b" os.rename(original, environment)\n"
files["nanobot/update_fallback.py"] = replace_once(files["nanobot/update_fallback.py"].replace(b"\r\n", b"\n"), needle, b''' if not (directory / 'restore-fault-fired').exists():
@@ -979,10 +1061,14 @@ def main() -> None:
if args.phase:
if sys.prefix == sys.base_prefix:
parser.error("Product phases must run in the disposable installation")
if args.phase == "prepare":
prepare(args.output)
else:
write(args.output / "result.json", verify(args.output))
try:
if args.phase == "prepare":
prepare(args.output)
else:
write(args.output / "result.json", verify(args.output))
except Exception as error:
phase_failure(args.output, args.phase, error)
raise
return
if not args.wheel or not args.commit:
parser.error("--wheel and --commit are required")