The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: the crash-cell oracle judges the marker with update_lock itself
Teknium50bff6b15121
diff --git a/tests/ci/test_windows_update_crash_oracles.py b/tests/ci/test_windows_update_crash_oracles.pyindex 9d7134367de..27dd90ee641 100644--- a/tests/ci/test_windows_update_crash_oracles.py+++ b/tests/ci/test_windows_update_crash_oracles.py@@ -7,6 +7,7 @@ import inspectimport osimport shleximport subprocess+import sysimport timefrom pathlib import Pathfrom types import SimpleNamespace@@ -16,6 +17,7 @@ import pytestfrom _pytest.mark.expression import Expressionimport tests.e2e.core.windows_update.test_crash_cells as crash+from hermes_cli import update_lock_REPO = Path(__file__).resolve().parents[2]_SUITE = "tests/e2e/core/windows_update"@@ -105,16 +107,39 @@ def test_kill_point_counts_only_an_update_killed_while_running(crash._kill_when(_Machine(tmp_path), proc, "cell", point, "t")[email protected]("age,with_ct,live", [- (60, False, True), # v1 marker inside update_lock's 20-minute ceiling- (1260, False, False), # v1 past the ceiling: the product reads it DEAD (the pid may be reused)- (1260, True, True), # a matching creation time is live at any age-])-def test_marker_oracle_reads_a_marker_live_exactly_when_update_lock_does(age, with_ct, live):- pid = os.getpid()- ct = f"ct:{psutil.Process(pid).create_time():.3f}\n" if with_ct else ""- text = f"{pid}\n{time.time() - age}\n{ct}"- assert crash._marker_live(text) == (f"owner {pid}" if live else None)[email protected](scope="module")+def other_process():+ """A live process that is not this one: the judge reads its own pid by exact incarnation."""+ proc = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(600)"])+ try:+ yield proc.pid, update_lock.process_create_time(proc.pid)+ finally:+ proc.kill()+ proc.wait(timeout=60)+++# (lines after "<pid>\n<started_at>\n" given (pid, ct, now), the oracle's expected reading)+_MARKERS = {+ "v1-inside-ceiling": (lambda p, ct, now: f"{now - 60}\n", "owner"),+ "v1-past-ceiling": (lambda p, ct, now: f"{now - 1260}\n", None), # the pid may be reused+ "ct-match-any-age": (lambda p, ct, now: f"{now - 1260}\nct:{ct:.3f}\n", "owner"),+ # Review K132346-oracle-judge: the three rows a hand copy of the judge got wrong.+ "float-started-at": (lambda p, ct, now: f"{now - 60}.5\nct:{ct:.3f}\n", None), # malformed+ "ct-off-by-1.5s": (lambda p, ct, now: f"{now - 60}\nct:{ct + 1.5:.3f}\n", "owner"),+ "run-before-delegate": (lambda p, ct, now: f"{now - 60}\nct:{ct - 100:.3f}\nrun:abc\n"+ f"delegate:{p} ct:{ct:.3f}\n", "delegate"),+}++[email protected]("case", list(_MARKERS))+def test_marker_oracle_reads_a_marker_live_exactly_when_update_lock_does(other_process, case):+ pid, ct = other_process+ assert ct is not None, "the product cannot read a creation time on this host"+ tail, expected = _MARKERS[case]+ text = f"{pid}\n" + tail(pid, ct, int(time.time()))+ verdict, owner, _ = update_lock.judge_marker(text.encode("utf-8"))+ assert crash._marker_live(text) == (f"{expected} {pid}" if expected else None)+ assert (verdict == "live", owner) == ((True, pid) if expected else (False, None)), verdictclass _Journey:diff --git a/tests/e2e/core/windows_update/test_crash_cells.py b/tests/e2e/core/windows_update/test_crash_cells.pyindex 61c0c0d3be4..3445e4a5d2a 100644--- a/tests/e2e/core/windows_update/test_crash_cells.py+++ b/tests/e2e/core/windows_update/test_crash_cells.py@@ -72,7 +72,7 @@ from pathlib import Pathimport psutilimport pytest-from hermes_cli.update_lock import UPDATE_MARKER_MAX_AGE_SECONDS+from hermes_cli import update_lockfrom tests.e2e.core._pending_fixes import known_failurefrom tests.e2e.core.windows._helpers import _decode@@ -409,58 +409,19 @@ def _tree_moved(proc, machine, target) -> str | None:# -- marker (contract C1, line format) ------------------------------------------------CT_TOLERANCE = 1.0 # seconds; writers round ct to 3 decimals---def _parse_marker(text: str) -> dict:- """``<pid>\\n<started_at>\\n[ct:<ct>\\n][delegate:<pid> ct:<ct>\\n]`` (positional)."""- lines = text.lstrip("\ufeff").splitlines()-- def num(index: int, cast):- try:- return cast(lines[index].strip())- except (IndexError, ValueError):- return None-- def ct(field: str):- field = field.strip()- try:- return float(field[3:]) if field.startswith("ct:") else None- except ValueError:- return None-- delegate = delegate_ct = None- if len(lines) > 3 and lines[3].startswith("delegate:"):- head, _, tail = lines[3][len("delegate:"):].partition(" ")- delegate, delegate_ct = (int(head) if head.strip().isdigit() else None), ct(tail)- return {"pid": num(0, int), "started_at": num(1, float),- "ct": ct(lines[2]) if len(lines) > 2 else None,- "delegate": delegate, "delegate_ct": delegate_ct}---def _identity_live(pid: int | None, ct: float | None, age: float) -> bool:- """update_lock's C1 verdict for one identity of a marker ``age`` seconds old."""- if not pid or pid <= 0:- return False- try:- proc = psutil.Process(pid)- if not proc.is_running():- return False- if ct is None: # v1 / no creation time: the pid may be reused, so only the age ceiling bounds it- return age <= UPDATE_MARKER_MAX_AGE_SECONDS- return abs(proc.create_time() - ct) <= CT_TOLERANCE- except psutil.Error:- return False--def _marker_live(text: str) -> str | None:- """Who keeps the marker LIVE (``"owner <pid>"`` / ``"delegate <pid>"``), or None."""- m = _parse_marker(text)- age = time.time() - (m["started_at"] or 0.0)- if _identity_live(m["pid"], m["ct"], age):- return f"owner {m['pid']}"- if _identity_live(m["delegate"], m["delegate_ct"], age):- return f"delegate {m['delegate']}"+ """Who keeps the marker LIVE (``"owner <pid>"`` / ``"delegate <pid>"``), or None.++ The updater's own judge (``update_lock``), not a copy: a second parser drifted from it+ (float started_at, create-time tolerance, a ``run:`` line before ``delegate:``) and graded+ the orphaned update against rules the product does not follow. This process runs on the+ host the marker's pids live on, so the product's process table reads them as the updater does.+ """+ marker = update_lock._parse_marker(text.encode("utf-8"))+ if marker.owner_live():+ return f"owner {marker.pid}"+ if marker.delegate_live():+ return f"delegate {marker.delegate_pid}"return None@@ -477,7 +438,7 @@ def _marker_text(machine) -> str:text = _read_marker(machine)if text is None:return "<absent>"- return f"{text!r} parsed={_parse_marker(text)} live={_marker_live(text)}"+ return f"{text!r} judge={update_lock.judge_marker(text.encode('utf-8'))} live={_marker_live(text)}"# -- orphaned update: only the hand-off script dies --------------------------------