From 4954083f702de4c00d215ccf3b98a7386d04ba1c Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 1 Sep 2026 20:54:27 -0400 Subject: [PATCH] cortex conductor: collect reads the pull manifest's checkpoints table (PyAutoMind#382) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `collect`'s checkpoint leg had one lookup — `runs[]` — and one of the two science projects cannot fill it: its pull carries no job id at all. The manifest (PyAutoCortex decision 51) therefore always writes a `checkpoints` table keyed by the run directory relative to the pull root, which is the only name both sides can say, and `leg_checkpoint` gains that as its third lookup: `runs[ident]` → `runs[stem]` → `checkpoints[]`. A `bytes: 0` entry fails the leg, exactly like a zero `checkpoint_bytes`. A manifest with no `schema` key is read as the phase-2 shape, so nothing already written breaks. `agents/conductors/cortex/AGENTS.md` and `skills/cortex/cortex.md` describe the new shape. Three tests added; `pytest tests -q` 744 passed. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01SESCzU1FcwktEAdTZfmf3j --- agents/conductors/cortex/AGENTS.md | 2 +- agents/conductors/cortex/_cortex.py | 57 ++++++++++++++++++++++------- skills/cortex/cortex.md | 4 +- tests/test_cortex_conductor.py | 38 +++++++++++++++++++ 4 files changed, 86 insertions(+), 15 deletions(-) diff --git a/agents/conductors/cortex/AGENTS.md b/agents/conductors/cortex/AGENTS.md index 250abcb7..629c09c6 100644 --- a/agents/conductors/cortex/AGENTS.md +++ b/agents/conductors/cortex/AGENTS.md @@ -102,7 +102,7 @@ results in. `collect` scores every member whose phase is `submitted` or | `err` | every `error.*.err` under the roots. Benign = every non-blank line is a `*Warning*` line or its indented continuation — **not** size 0; `Traceback`/`Error`/`Killed`/`OOM` ⇒ FAIL | | `wall` | the `.out`'s first and last date stamps when it ends `Finished.`, else `Time To Run` in `search.summary` — **from the `.zip` when there is one**, because an extracted run dir can be a stale partial. Over `Budget:` ⇒ FAIL | | `version` | a top-level `version` key in a JSON matching the project's `witness_file` | -| `checkpoint` | `/.cortex/pull.json` only (`{"pulled_at": ISO, "runs": {"": {"checkpoint_bytes": N, "checkpoint_mtime": ISO}}}`) — `search_internal/checkpoint.hdf5` is never pulled, so without that manifest the leg is UNOBSERVABLE, tagged `RAL only` | +| `checkpoint` | `/.cortex/pull.json` only (`{"schema": 1, "pulled_at": ISO, "checkpoints": {"": {"bytes": N, "mtime": ISO}}, "runs": {"": {"checkpoint_bytes": N, "checkpoint_mtime": ISO}}}`; looked up `runs[]` → `runs[]` → `checkpoints[]`, and a manifest with no `schema` is the older `runs`-only shape) — `search_internal/checkpoint.hdf5` is never pulled, so without that manifest the leg is UNOBSERVABLE, tagged `RAL only` | | `resume` | `Fit Already Completed` / `Resuming … previous samples found` in the `.out` ⇒ FAIL: those are the previous fit's numbers | | `witness` | a file matching `witness_file` newer than the phase's first submission | diff --git a/agents/conductors/cortex/_cortex.py b/agents/conductors/cortex/_cortex.py index 2aadea6a..ee136e0e 100644 --- a/agents/conductors/cortex/_cortex.py +++ b/agents/conductors/cortex/_cortex.py @@ -1080,8 +1080,9 @@ def emit_census(c: dict) -> None: # one of the two project layouts writes no version stamp at all. A scorer that # called those legs PASS would be inventing evidence and a scorer that called # them FAIL would condemn every healthy run, so there is a third verdict: -# UNOBSERVABLE, which sends the member to the human as SUSPECT. Phase 3's sync -# work adds the pull manifest that makes the checkpoint leg observable. +# UNOBSERVABLE, which sends the member to the human as SUSPECT. The checkpoint +# leg becomes observable exactly when the project's own sync CLI writes the +# pull manifest (`.cortex/pull.json`), and not before. PASS, FAIL, UNOBSERVABLE = "PASS", "FAIL", "UNOBSERVABLE" #: the six legs, in packet order — the four `delivered:` legs of @@ -1096,9 +1097,15 @@ def emit_census(c: dict) -> None: "witness": "the witness landed", } -#: `/.cortex/pull.json`, written by the sync work of phase 3: -#: `{"pulled_at": ISO, "runs": {"": {"checkpoint_bytes": N, -#: "checkpoint_mtime": ISO}}}`. Absent until then — hence UNOBSERVABLE. +#: `/.cortex/pull.json`, written by each project's own +#: sync CLI (PyAutoCortex decision 51): +#: `{"schema": 1, "pulled_at": ISO, +#: "checkpoints": {"": {"bytes": N, "mtime": ISO}}, +#: "runs": {"": {"checkpoint_bytes": N, "checkpoint_mtime": ISO}}}`. +#: `checkpoints` is always filled — it is keyed by the only name both sides can +#: say — while `runs` is filled only where the CLI can link a job id to a run +#: directory. A manifest with no `schema` key is the phase-2 shape (`runs` +#: only) and still reads. Absent altogether — hence UNOBSERVABLE. PULL_MANIFEST = (".cortex", "pull.json") LOG_DEPTH = 4 # `**/output.*.out` — deep enough for both layouts @@ -1332,7 +1339,7 @@ def witness_matches(roots: list[Path], pattern: str, since: _dt.datetime, def pull_manifest(roots: list[Path]) -> dict: """`/.cortex/pull.json`, or `{}` — the only window onto RAL-only - artefacts, and it does not exist until phase 3 writes it.""" + artefacts, and it exists only where the project's sync CLI writes it.""" for root in roots: path = root.joinpath(*PULL_MANIFEST) if path.is_file(): @@ -1411,22 +1418,46 @@ def leg_version(hits: list[Path]) -> tuple: f"{len(jsons)} witness JSON(s), none with a top-level `version` key") -def leg_checkpoint(manifest: dict, ph) -> tuple: +def _manifest_run_dir_key(roots: list[Path], run_dir) -> str: + """The run directory as the puller named it: its path relative to the pull + root it sits under. The empty string when it sits under none of them.""" + if run_dir is None: + return "" + for root in roots: + if _under(run_dir, root): + try: + return run_dir.relative_to(root).as_posix() + except ValueError: + continue + return "" + + +def leg_checkpoint(manifest: dict, roots: list[Path], run_dir, ph) -> tuple: + """Three lookups, in order: the job id, its bare stem, then the run + directory. The third is the one the profiling project can answer — its + pull carries no job id at all, so `runs` is empty there and `checkpoints` + is keyed by the run directory instead.""" runs = manifest.get("runs") if isinstance(manifest.get("runs"), dict) else {} - rows = [] + ckpts = (manifest.get("checkpoints") + if isinstance(manifest.get("checkpoints"), dict) else {}) + rows: list[tuple] = [] for r in ph.runs: row = runs.get(r.ident) or runs.get(r.stem) if isinstance(row, dict): - rows.append((r.ident, row)) + rows.append((r.ident, int(row.get("checkpoint_bytes") or 0))) + if not rows: + key = _manifest_run_dir_key(roots, run_dir) + row = ckpts.get(key) if key else None + if isinstance(row, dict): + rows.append((key, int(row.get("bytes") or 0))) if not rows: return (UNOBSERVABLE, "RAL only — `search_internal/checkpoint.hdf5` is not pulled " "and no `.cortex/pull.json` records it") - empty = [ident for ident, row in rows - if not int(row.get("checkpoint_bytes") or 0)] + empty = [label for label, size in rows if not size] if empty: return FAIL, f"empty checkpoint for {', '.join(empty)} — not delivered" - total = sum(int(row.get("checkpoint_bytes") or 0) for _i, row in rows) + total = sum(size for _label, size in rows) return PASS, f"{len(rows)} checkpoint(s), {total} bytes (pull manifest)" @@ -1495,7 +1526,7 @@ def score_phase(mod, ph, projects: dict) -> dict: "err": leg_err(logs["err"]), "wall": leg_wall(logs["out"], run_dir, zip_path, _mins(budget), budget), "version": leg_version(hits), - "checkpoint": leg_checkpoint(pull_manifest(roots), ph), + "checkpoint": leg_checkpoint(pull_manifest(roots), roots, run_dir, ph), "resume": leg_resume(logs["out"]), "witness": leg_witness(hits, roots, pattern), } diff --git a/skills/cortex/cortex.md b/skills/cortex/cortex.md index 6fb36db5..f6e1bd66 100644 --- a/skills/cortex/cortex.md +++ b/skills/cortex/cortex.md @@ -51,6 +51,8 @@ Shared routing context: `PyAutoBrain/skills/COMMANDS.md`. - **UNOBSERVABLE is not FAIL.** Two of the four `delivered:` legs are not visible on the laptop (the checkpoint is never pulled; one project writes no version stamp), so those members come back **SUSPECT** — read them, do not - treat them as broken runs. + treat them as broken runs. The checkpoint leg becomes scorable only where + the project's sync CLI writes `.cortex/pull.json` — its `checkpoints` table + is keyed by the run directory, its `runs` table by job id. - **A cloud session plans nothing** — every Cortex phase is `local-dev`, so a session with no `gh` reports the ready count and stops. diff --git a/tests/test_cortex_conductor.py b/tests/test_cortex_conductor.py index 8a89f42e..482ee4f9 100644 --- a/tests/test_cortex_conductor.py +++ b/tests/test_cortex_conductor.py @@ -537,6 +537,44 @@ def test_the_two_legs_the_laptop_cannot_see_are_unobservable_not_failed(board): assert s["health"] == "SUSPECT" +def test_the_manifests_checkpoints_table_is_keyed_by_the_run_directory(board): + """The third lookup (PyAutoCortex decision 51). The subhalo-style member's + pull carries no job id, so `runs` is empty and the only name both sides can + say is the run directory, relative to the pull root.""" + _write(board["sub"] / ".cortex/pull.json", json.dumps( + {"schema": 1, "pulled_at": "2026-08-31T10:00Z", + "checkpoints": {"output/lens_a/cccc3333": { + "bytes": 81920, "mtime": "2026-08-30T09:51Z"}}, + "runs": {}})) + s = _score(board)["01_partial"] + assert s["legs"]["checkpoint"][0] == _cortex.PASS, s["legs"]["checkpoint"] + assert "81920 bytes" in s["legs"]["checkpoint"][1] + + +def test_a_zero_byte_checkpoint_in_the_manifest_fails_the_leg(board): + """A checkpoint the puller found and measured at zero bytes is not an + unobservable leg — it is a run that delivered nothing.""" + _write(board["sub"] / ".cortex/pull.json", json.dumps( + {"schema": 1, "pulled_at": "2026-08-31T10:00Z", + "checkpoints": {"output/lens_a/cccc3333": { + "bytes": 0, "mtime": "2026-08-30T09:51Z"}}})) + s = _score(board)["01_partial"] + assert s["legs"]["checkpoint"][0] == _cortex.FAIL + assert "empty checkpoint" in s["legs"]["checkpoint"][1] + assert s["health"] == "FAILED" + + +def test_a_manifest_without_a_schema_key_still_reads_as_the_runs_only_shape(board): + """The phase-2 manifest (`pulled_at` + `runs`, no `schema`) is what the + healthy member carries — it must keep scoring PASS unchanged.""" + manifest = json.loads( + (board["mirror"] / ".cortex/pull.json").read_text(encoding="utf-8")) + assert "schema" not in manifest and "checkpoints" not in manifest + s = _score(board)["11_healthy"] + assert s["legs"]["checkpoint"][0] == _cortex.PASS + assert "40960 bytes" in s["legs"]["checkpoint"][1] + + def test_a_benign_err_is_warnings_not_an_empty_file(board): """`.err` "clean" is not size 0: the baseline both projects produce is a warning line plus its indented source line."""