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
54 changes: 54 additions & 0 deletions AUTONOMY.md
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,60 @@ went out on an acked YELLOW. That is ack-fatigue risk, addressed by making
Heart's verdict distinguish stale evidence from bad evidence (the freshness
tier), never by weakening leg 4.

## Scheduler actions — 2026-10-31

A cluster queue is shared, and one CPU array on the wrong partition has idled
all eight RAL A100s (2026-09-30). So the queue changes in one place, the
project's own `hpc/sync`, and every change leaves a record (hpc-campaign phase
5, ruling F12). **`hpc/sync act` is the only way a campaign's jobs start or
change.**

| Verb | Effect | Who may run it |
|------|--------|----------------|
| `hpc/sync act submit <campaign.yaml> [--stage S] [--indices SPEC] [--dry-run]` | starts a campaign's jobs — a pilot is `--indices` with the pilot's slice — logged | an agent, only when the human asked for that run (a pilot, then the full campaign, each on its own go) |
| `hpc/sync act <resubmit \| hold \| release \| throttle \| update-pending \| cancel> <campaign> <arg …>` | changes a campaign's queued or running jobs, logged | an agent, only on the human's ask; never another campaign's jobs without their OK |
| `hpc/sync cancel <job>` | the older spelling of `act cancel`, logged the same way | as `act` |
| `hpc/sync submit \| push-submit [gpu\|cpu] <script> [sbatch arg …]` | sbatches one hand-written script, outside any campaign | an agent, only when the human asked for that run in the session |
| `hpc/sync status \| plan \| pilot \| resubmit \| report <campaign.yaml>`, `jobs`, `sacct`, `pull`; `squeue`, `sacct`, `sinfo`, `scontrol show` | read, or write a proposal that submits nothing | anyone, any time |

`act resubmit` takes a proposal file the human has approved; `hpc/sync
resubmit` only writes the proposal, and `hpc/sync pilot` only chooses a slice.
`update-pending` changes only the fields the template allows (never a
partition).

**The audit log.** Every `act` first checks that
`<project_root>/campaign/<name>/actions.log` on the cluster can be written, and
stops without acting if it cannot; then it acts, appends one JSON line, and
prints it:

```json
{"utc": "2026-10-31T09:00:00Z", "user": "<cluster user>", "campaign": "<name>", "action": "hold", "args": ["413011"], "exit": 0}
```

`exit` is the action's own exit code, so a refused action is recorded too.
`hpc/sync status <campaign.yaml>` pulls the log back with the digest, into
`hpc/campaign/<name>/`. It is append-only: nothing rewrites or trims it.

**What enforces it.** A raw `sbatch`, `scancel`, `srun`, `salloc`, mutating `scontrol` (any
subcommand but `show`, `ping`, `version`, `help`) or `python -m
autofit.campaign submit` (but `--dry-run`) is refused by
`bin/scheduler_action_guard.py`, a PreToolUse(Bash) hook for Claude and Codex —
typed directly, over `ssh`, in `bash -c`/`eval`, behind env assignments or
wrappers (`xargs`, `parallel`, `find -exec` …), chained, substituted, or in a
heredoc fed to a shell. Help, usage, version and `sbatch --test-only` only read
and are allowed, as is `scontrol show`,
which stays allowed because recording a run as GPU needs `gres/gpu` from
`scontrol show job`. `srun`/`salloc` are refused too (human ruling 2026-10-31):
they start work outside any log; only the command an agent types is judged, so
`srun` inside a batch script is untouched. A mention (a commit message, `grep sbatch`) is not a call. The hook
is textual: a scheduler call inside a script or a Python `subprocess` is not
seen, and this table is what governs it. Human-directed exception (kept by human ruling 2026-10-31):
`PYAUTO_SKIP_SCHEDULER_GUARD=1` in the environment or as the leading assignment
of the command it excuses — a mention elsewhere excuses nothing. Registration
(human-approved 2026-10-31) follows this source's merge: the workspace-root
`.claude/settings.json` Bash hooks and `PyAutoMind/scripts/repos_sync.py`'s
Codex hook list.

## Hard invariants (every level, no exceptions)

- **Merge and issue-close are human acts, except as "Merge authority follows
Expand Down
4 changes: 4 additions & 0 deletions agents/conductors/clone/_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
"skills/al_*.md", # every al_* skill body
".claude/skills/al_*.md", # ... and their harness mirrors
"skills/init-slam.md", ".claude/skills/init-slam.md", # SLAM = lensing
# Running a lens sample through SLaM stages on a cluster: the
# stages, Pulse keys and resources are lensing (like `hpc/*`).
"skills/hpc_campaign.md", ".claude/skills/hpc_campaign.md",
".claude/commands/hpc_campaign.md",
# The euclid mode: a survey-specific pipeline register (its skills
# + its own sub-wiki). Lensing science throughout — a newborn grows
# whatever survey modes its own domain has, if any.
Expand Down
22 changes: 20 additions & 2 deletions agents/conductors/cortex/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ note`).

| Verb | Question | Emits |
|------|----------|-------|
| `pull [--project KEY] [--dry-run]` | **What does the cluster say?** | the laptop leg: each project's own `<sync_cli> pull`, streamed, then its `jobs` output verbatim, then one line per project (and the roots that are not on this machine, as skipped). Writes nothing. Exit **1** a pull failed · **2** no project's `local_path` is here |
| `pull [--project KEY] [--dry-run]` | **What does the cluster say?** | the laptop leg: each project's own `<sync_cli> pull`, streamed, then its `jobs` output verbatim — or, for a campaign project, its `status <campaign_file>` output and a `sync-runs --dry-run` read of the pulled digest — then one line per project (and the roots that are not on this machine, as skipped). Writes nothing. Exit **1** a pull failed · **2** no project's `local_path` is here |
| `checkin [--dry-run \| --apply] [--push \| --no-push] [--project KEY]` | **Where is my science?** | the door — the sequence below, ending in a summary keyed by project; reaches no cluster; exit **1** when the tree does not check |
| `census [--json]` | What is the Cortex holding? | per project: status, summary, runs by state, log length, last update; totals (active projects, runs open, runs running); the check-in stamp; the problems `cortex.py check` would report |
| `drift [--science-root PATH] [--json]` | **Does the register match the Science tree?** | the laptop Science tree (`<root>/<category>/<project>`, root derived from the rows' `local_path`s) against `projects.yaml`: errors — a folder in `active/` or `development/` with no row, a non-retired row whose folder is gone, a folder whose category disagrees with its status, a derived root that does not exist while other rows' folders do (the tree moved); warnings — an unregistered folder in `complete/` or `archive/`, a `ral_root` in a different category. Writes nothing. Exit **1** on an error · 0 otherwise, including off the laptop (a one-line skip). `census` and `checkin` print its one-line summary; `census()` itself stays drift-free so the CI board is machine-independent |
Expand Down Expand Up @@ -133,9 +133,27 @@ everywhere but one machine.
project's own `<sync_cli> jobs` is run and its output printed **verbatim**
— no parsing, no state flip. The human, or the agent in the session,
records what it says with `cortex.py running | done`.
4. **Campaigns read the digest, not squeue.** A row with `campaign_file:` (and
`status` among its `sync_verbs`) runs `<sync_cli> status <campaign_file>`
instead of `jobs` — it collects the campaign on the cluster and pulls its
`digest.json` — printed verbatim. A row with `digest:` then has the Cortex's
own `sync-runs <key> --dry-run` read that digest, and what it *would*
change is printed (`sync-runs: <key>: <n> changed (dry run)`); a malformed
digest is said and the sweep goes on. Recording it is
`cortex.py sync-runs <key>` in the Cortex checkout (schema decision 64:
run status is a cluster fact; `result`, `lesson` and `## Now` stay the
human's).

It writes nothing: no stamp, no pages, no ledger. `--dry-run` prints the exact
`cd <local_path> && <sync_cli> pull` per project and reaches nothing at all.
`cd <local_path> && <sync_cli> pull` per project (and the `status` call and
digest a campaign project would read) and reaches nothing at all.

### Scheduler actions

`pull` and `checkin` change nothing on a cluster. When the human asks for a
queue change, it goes through the project's own CLI and nothing else — the
allowlist and the `actions.log` contract are in `AUTONOMY.md` ("Scheduler
actions"), enforced by `bin/scheduler_action_guard.py`.

### `checkin` — the door

Expand Down
118 changes: 106 additions & 12 deletions agents/conductors/cortex/_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,21 +1457,78 @@ def cmd_birth(root: Path, mod, a) -> int:
return rc


def run_jobs(row: dict) -> str | None:
"""The project's own `<sync_cli> jobs`, verbatim — stdout and stderr as
they came, no parsing. None when the row has no `jobs` verb."""
cmd = _cli(row, "jobs")
def _run_verbatim(cmd: tuple | None, verb: str) -> str | None:
"""A project CLI call's stdout and stderr as they came, no parsing. None
when there is no such call."""
if cmd is None:
return None
argv, cwd = cmd
try:
r = subprocess.run(argv, cwd=cwd, capture_output=True, text=True)
except (OSError, subprocess.SubprocessError) as e:
return f"(jobs could not run: {e})"
return f"({verb} could not run: {e})"
out = r.stdout + (r.stderr if r.stderr else "")
if r.returncode != 0:
out += f"\n(jobs exited {r.returncode})"
return out.rstrip("\n") or "(jobs printed nothing)"
out += f"\n({verb} exited {r.returncode})"
return out.rstrip("\n") or f"({verb} printed nothing)"


def run_jobs(row: dict) -> str | None:
"""The project's own `<sync_cli> jobs`, verbatim — stdout and stderr as
they came, no parsing. None when the row has no `jobs` verb."""
return _run_verbatim(_cli(row, "jobs"), "jobs")


# A project whose runs are campaigns (`campaign_file:` in its row)
# is read through the campaign digest, not raw squeue: `<sync_cli> status
# <campaign.yaml>` collects the campaign on the cluster and pulls its
# `digest.json`, and the Cortex's own `sync-runs` reads that digest (schema
# decision 64). `pull` runs `sync-runs` as a dry run only — what the digest
# would change is printed, and recording it stays the Cortex script's verb.
def campaign_status_cmd(row: dict) -> tuple | None:
"""`(argv, cwd)` for `<sync_cli> status <campaign_file>`, or None when the
row names no campaign or its CLI has no `status` verb."""
campaign = (row.get("campaign_file") or "").strip()
cmd = _cli(row, "status")
if not campaign or cmd is None:
return None
argv, cwd = cmd
return argv + [campaign], cwd


def campaign_status_shell(row: dict) -> str:
return (f"cd {row.get('local_path')} && {row.get('sync_cli')} status "
f"{row.get('campaign_file')}")


def run_campaign_status(row: dict) -> str | None:
"""The project's own `<sync_cli> status <campaign_file>`, verbatim."""
return _run_verbatim(campaign_status_cmd(row), "status")


def digest_path(row: dict) -> Path | None:
"""The row's `digest:` resolved against its `local_path`, as the Cortex's
`sync-runs` resolves it; None when the row names no digest."""
given = (row.get("digest") or "").strip()
if not given:
return None
p = Path(given)
return p if p.is_absolute() else Path(local_root(row)) / p


def read_digest_dry(mod, root: Path, key: str, row: dict) -> list[str] | None:
"""What `sync-runs <key>` would change, from the pulled digest — a dry run,
so nothing is written. None when the row names no digest."""
path = digest_path(row)
if path is None:
return None
sync = getattr(mod, "sync_runs", None)
if sync is None:
return ["(this Cortex checkout has no `sync-runs` — update PyAutoCortex)"]
try:
return sync(root, key, path, _dt.date.today(), dry_run=True)
except mod.CortexError as e:
return [f"(the digest could not be read: {e})"]


# ------------------------------------------------------------- the push ---
Expand Down Expand Up @@ -1656,7 +1713,9 @@ def project_digest(key: str, c: dict) -> list[str]:
# -------------------------------------------------------------- the pull ---
def cmd_pull(root: Path, mod, a) -> int:
"""The laptop leg: each project's own `<sync_cli> pull`, then its `jobs`
output verbatim. Nothing else — no stamp, no render, no push.
output verbatim — or, for a campaign project, its `status <campaign_file>`
output and what `sync-runs` would change from the pulled digest. Nothing
else — no stamp, no render, no push, no ledger write.

It is a separate verb because it has a separate precondition: every path
it runs under is a `local_path` out of `projects.yaml`, which exists on
Expand All @@ -1673,8 +1732,15 @@ def jobs_line(key: str) -> str:
row = projects[key]
return f"cd {row.get('local_path')} && {row.get('sync_cli')} jobs"

def asks_campaign(key: str) -> bool:
return campaign_status_cmd(projects[key]) is not None

def reads_digest(key: str) -> bool:
return asks_campaign(key) or digest_path(projects[key]) is not None

def asks_jobs(key: str) -> bool:
return bool(runs_by_key.get(key)) and \
# A campaign project is read through its digest; squeue is not asked.
return bool(runs_by_key.get(key)) and not reads_digest(key) and \
"jobs" in (projects[key].get("sync_verbs") or [])

if a.dry_run:
Expand All @@ -1684,8 +1750,13 @@ def asks_jobs(key: str) -> bool:
here = "" if key in present else " (not on this machine)"
print(f"\n{key} — {row.get('status')}{here}")
print(f" $ {pull_shell(row)}")
if asks_jobs(key):
if asks_campaign(key):
print(f" $ {campaign_status_shell(row)}")
elif asks_jobs(key):
print(f" $ {jobs_line(key)}")
if digest_path(row) is not None:
print(f" then sync-runs {key} --dry-run, reading "
f"{digest_path(row)}")
for n in notes:
print(f"\nnote: {n}")
print(f"\n{len(present)} of {len(keys)} project(s) would be pulled. "
Expand All @@ -1708,9 +1779,22 @@ def asks_jobs(key: str) -> bool:
return RC_USAGE

pulls = run_pull_streamed(projects, present)
status_out: dict[str, str] = {}
digest_out: dict[str, list] = {}
for key in present:
if not asks_campaign(key):
continue
out = run_campaign_status(projects[key])
status_out[key] = out
print(f"\n$ {campaign_status_shell(projects[key])}", flush=True)
print(out, flush=True)
for key in present:
lines = read_digest_dry(mod, root, key, projects[key])
if lines is not None:
digest_out[key] = lines
jobs_out: dict[str, str] = {}
for key in present:
if not runs_by_key.get(key):
if not asks_jobs(key):
continue
out = run_jobs(projects[key])
if out is None:
Expand All @@ -1725,6 +1809,14 @@ def asks_jobs(key: str) -> bool:
rc, note = pulls.get(key, (None, "not run"))
print(f"{key}: " + ("pull ok" if rc == 0 else
(note or f"pull exited {rc}")))
if key in status_out:
print(status_out[key])
if key in digest_out:
print("\n".join(digest_out[key]))
elif asks_campaign(key):
print(" sync-runs: no `digest:` in projects.yaml — not read")
if reads_digest(key):
continue
if key in jobs_out:
print(jobs_out[key])
elif asks_jobs(key):
Expand All @@ -1739,7 +1831,9 @@ def asks_jobs(key: str) -> bool:
if missing:
print(f" {NOT_THE_LAPTOP}")
print("\nRecord what the jobs output says with `python3 scripts/cortex.py "
"running|done <key> <jobid>` in the Cortex checkout; a result or a "
"running|done <key> <jobid>` in the Cortex checkout — or, for a "
"campaign project, `python3 scripts/cortex.py sync-runs <key>`, "
"which records what its digest says; a result or a "
"lesson is written only in the human's words. Then "
"`pyauto-brain cortex checkin --apply` stamps and re-renders the "
"board.")
Expand Down
Loading
Loading