fix: tests rerun what autorun retries

run_tests reran a module only when a signal killed it: a SystemError or an unknown opcode from this host's CPU failed the run, where an autorun step failing the same way ran again. host_misread moves to core.hostguard and both runners read it, a signal kill of any kind now counting for autorun too.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 23:07:45 +01:00
1 parent f379df5e1e
commit e62332b4c6
7 files changed
+59 -19

No files matched your search

+13 -1
View File
@@ -1,4 +1,4 @@
"""Host-wide guards every heavy job shares: the automation lock and free disk space."""
"""Host-wide guards every heavy job shares: the automation lock, free disk space and the misread rule."""
from __future__ import annotations
@@ -12,6 +12,9 @@ from pathlib import Path
DEFAULT_LOCK = Path.home() / ".local" / "state" / "retrobios" / "auto.lock"
LOCK_ENV = "RETROBIOS_AUTO_LOCK"
LOCK_HELD_ENV = "RETROBIOS_AUTO_LOCK_HELD"
# A segfault as a shell reports it. Python reports the signal as -11.
SHELL_SEGFAULT = 139
HOST_MISREAD_MARKERS = ("SystemError", "unknown opcode")
class LockBusy(RuntimeError):
@@ -49,3 +52,12 @@ def lock_busy(path: Path) -> bool:
def free_gb(path: Path) -> float:
return shutil.disk_usage(path).free / 1024 ** 3
def host_misread(returncode: int, text: str) -> bool:
"""A failure this host's CPU produces under load, worth one retry: a signal
kill, a segfault a shell reported, or an error sound hardware never raises.
"""
if returncode < 0 or returncode == SHELL_SEGFAULT:
return True
return returncode != 0 and any(marker in text for marker in HOST_MISREAD_MARKERS)
+9 -3
View File
@@ -13,6 +13,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import dataclass
from pathlib import Path
from core.hostguard import host_misread
from core.paths import REPO_ROOT as ROOT
TESTS = ROOT / "tests"
@@ -116,9 +117,9 @@ def run_all(order: Iterable[str], jobs: int, env: dict[str, str], logs: Path,
def rerun_crashed(results: Iterable[Result], env: dict[str, str], logs: Path,
say: Callable[[str], None]) -> None:
"""A module a signal killed is the host's doing until it fails alone."""
"""A module the host misread is the host's doing until it fails alone."""
for result in results:
if result.code < 0:
if result.code != 0 and host_misread(result.code, _log_text(result)):
say(f" again, alone: {result.module}")
again = run_module(result.module, env, logs)
result.crashed_then = again.code
@@ -126,9 +127,14 @@ def rerun_crashed(results: Iterable[Result], env: dict[str, str], logs: Path,
again.tests, again.failures, again.errors, again.skipped)
def _log_text(result: Result) -> str:
return result.log.read_text(encoding="utf-8", errors="replace") if result.log else ""
def save_durations(durations: dict[str, float], results: Iterable[Result]) -> None:
"""The timings of this run over the previous ones, a crashed run left out."""
timed = {**durations, **{r.module: round(r.seconds, 1) for r in results if r.code >= 0}}
timed = {**durations, **{r.module: round(r.seconds, 1) for r in results
if r.crashed_then is None}}
DURATIONS.write_text(json.dumps(timed, indent=1, sort_keys=True), encoding="utf-8")
+6 -3
View File
@@ -15,8 +15,9 @@ tmp/test-durations.json, from the previous run, and a module never timed is
weighed by its size.
The host computes wrong and Python segfaults under load: a module killed by
a signal is run again alone at the end, and reported as passing only if that
run passes. Every module's output is kept in its own log, and the summary
a signal, or failing with an error sound hardware never raises (SystemError,
unknown opcode), is run again alone at the end, and reported as passing only
if that run passes. Every module's output is kept in its own log, and the summary
counts the tests, the failures and the skips, a skip being no proof.
"""
@@ -73,7 +74,9 @@ def main() -> int:
f"{time.monotonic() - started:.0f} s, {skipped} skipped")
for result in crashed:
outcome = "passed" if result.crashed_then == 0 else "failed"
print(f" {result.module}: killed by signal {-result.code}, then {outcome} alone")
why = (f"killed by signal {-result.code}" if result.code < 0
else f"exit {result.code} on a host misread")
print(f" {result.module}: {why}, then {outcome} alone")
for result in failed:
print(f"FAILED {result.module}: {result.failures} failures, {result.errors} errors "
f"(code {result.code if result.crashed_then is None else result.crashed_then}), "
+1 -10
View File
@@ -18,7 +18,7 @@ from dataclasses import dataclass, field
from pathlib import Path
from core.artifacts import TIMESTAMP_KEYS
from core.hostguard import LockBusy, free_gb, global_lock, lock_busy
from core.hostguard import LockBusy, free_gb, global_lock, host_misread, lock_busy
from core.paths import AUTORUN_DIR, AUTORUN_WORKTREE
from core.statefile import now_iso, save_state
from unattended.breaker import may_push, refresh_breaker
@@ -37,8 +37,6 @@ from unattended.worktree import (
ALERT_FREE_GB = 100
LOG_DAYS = 30
SEGFAULT_CODES = (139, -11)
HOST_MISREAD_MARKERS = ("SystemError", "unknown opcode")
@dataclass
@@ -101,13 +99,6 @@ def wait_for_load(host: Host, max_wait: float) -> bool:
host.sleep(min(host.poll, left))
def host_misread(returncode: int, text: str) -> bool:
"""A failure this host's CPU produces under load, worth one idle retry."""
if returncode in SEGFAULT_CODES:
return True
return returncode != 0 and any(marker in text for marker in HOST_MISREAD_MARKERS)
# Running commands