Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agents/conductors/cortex/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ results in. `collect` scores every member whose phase is `submitted` or
| `err` | every `error.<jobid>*.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 `<hash>.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` | `<root>/.cortex/pull.json` only (`{"pulled_at": ISO, "runs": {"<jobid>": {"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` | `<root>/.cortex/pull.json` only (`{"schema": 1, "pulled_at": ISO, "checkpoints": {"<run dir rel to the pull root>": {"bytes": N, "mtime": ISO}}, "runs": {"<jobid>": {"checkpoint_bytes": N, "checkpoint_mtime": ISO}}}`; looked up `runs[<jobid>]` → `runs[<stem>]` → `checkpoints[<run dir rel>]`, 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 |

Expand Down
57 changes: 44 additions & 13 deletions agents/conductors/cortex/_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1096,9 +1097,15 @@ def emit_census(c: dict) -> None:
"witness": "the witness landed",
}

#: `<mirror>/.cortex/pull.json`, written by the sync work of phase 3:
#: `{"pulled_at": ISO, "runs": {"<jobid>": {"checkpoint_bytes": N,
#: "checkpoint_mtime": ISO}}}`. Absent until then — hence UNOBSERVABLE.
#: `<mirror or local_path>/.cortex/pull.json`, written by each project's own
#: sync CLI (PyAutoCortex decision 51):
#: `{"schema": 1, "pulled_at": ISO,
#: "checkpoints": {"<run dir rel to the pull root>": {"bytes": N, "mtime": ISO}},
#: "runs": {"<jobid|jobid_task>": {"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.<jobid>*.out` — deep enough for both layouts
Expand Down Expand Up @@ -1332,7 +1339,7 @@ def witness_matches(roots: list[Path], pattern: str, since: _dt.datetime,

def pull_manifest(roots: list[Path]) -> dict:
"""`<root>/.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():
Expand Down Expand Up @@ -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)"


Expand Down Expand Up @@ -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),
}
Expand Down
4 changes: 3 additions & 1 deletion skills/cortex/cortex.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
38 changes: 38 additions & 0 deletions tests/test_cortex_conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading