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
6 changes: 5 additions & 1 deletion AUTONOMY.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ never an assumption:
(`consult_vitals_verdict --repos "$(active_task_repos <task>)"`). Only CI
on `main` of the touched repos and their dependants blocks; every other
reason comes back in `shown_reasons` and is listed in the PR body without
blocking. Only **GREEN** passes. **STALE** — in-scope evidence missing,
blocking. A touched repo on Heart's `not_heart_gated:` list (profiling,
inference, assistants, visualization, Scientist, Broca, Cortex; ruling
2026-11-13, PyAutoHeart#343) is *gate-deferred*: shown, never STALE, and
its PR checks decide at merge — at least one completed check, all green,
or the merge is the human's. Only **GREEN** passes. **STALE** — in-scope evidence missing,
unfinished, or older than 6 h — **never passes**: re-check, or park. With
**no Heart CLI** (a web session) the one fallback is the *published*
organism-wide feed: GREEN and under 6 h old passes, because it is at least
Expand Down
10 changes: 6 additions & 4 deletions agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ counts the PRs GitHub shows merged by `review-at:`, whoever merged them, and
`workers-crashed` counts exit records, not a tally. A `### Workers` section
prints one line per worker (`<label> (<id>): spawned/crashed`). An issue URL in
a `.done` is kept in `issues`, never `prs`. Health per PR is one
read-only `gh pr checks` (exit 0 → HEALTHY, 8 → RUNNING, else FAILED or
NO-CHECKS). `glance-auto-merges`, `reverts`, `pushes`, `drafts-filed` and
read-only `gh pr checks --json`, judged per check (PyAutoHeart#343): any
failed or cancelled → FAILED, any pending → RUNNING, no completed check at all
(no CI, or only skipped) → NO-CHECKS, else HEALTHY — at least one completed
check, all green; unreadable → UNKNOWN. `glance-auto-merges`, `reverts`, `pushes`, `drafts-filed` and
`packets-sent` read `counters.json` and stay 0 until phases 4–5 move them
(human, 2026-11-04). `batch digest --record <file>` prints the digest and
writes nothing; `batch brief --check` refuses a digest missing a section, a
Expand Down Expand Up @@ -333,8 +335,8 @@ ends at PR-open (`worker_template.md`). Each tick, `_closeouts` first reaps
running close-outs — `<task>.closeout` (`merged` | `refused`, `why`, `gate`,
`model`), or a session gone without one, which is recorded refused — then, for
each PR a worker named, judges the guards it can see with its own reads: the
recorded tier is `glance`, `gh pr checks` is green (pending waits a tick, red is
refused), merges plus in-flight close-outs are under `merge-cap:`, and the
recorded tier is `glance`, `gh pr checks` is green — at least one completed
check, all green (pending waits a tick; red, none or unknown is refused), merges plus in-flight close-outs are under `merge-cap:`, and the
shift is not shadow. Then it starts **one** close-out session
(`closeout_template.md`; `claude --bg --name shift-close:<task> --model opus`).
That session is the independent leg: it runs the `Witness:` itself, reviews the
Expand Down
40 changes: 32 additions & 8 deletions agents/conductors/batch/_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import annotations

import json
import re
import subprocess
from pathlib import Path
Expand Down Expand Up @@ -96,23 +97,46 @@ def urls_of(outcome: dict | None) -> list[str]:
return list(outcome.get("prs") or []) + list(outcome.get("issues") or [])


#: `gh pr checks --json` buckets that are a COMPLETED verdict. `skipping`
#: (path-filtered or `if:`-skipped) never ran, so it is not evidence either way.
_DONE_BUCKETS = frozenset({"pass", "fail", "cancel"})


def pr_health(url: str, run=None) -> str:
"""One read-only `gh pr checks`. Its exit code is the verdict: 0 passed,
8 pending; anything else failed — or names why it could not say."""
"""One read-only `gh pr checks --json`, judged explicitly (PyAutoHeart#343).

HEALTHY needs at least one completed check on the PR head and every
completed check green: a PR with no checks at all (a repo with no CI) or
only skipped ones is NO-CHECKS, which the close-out refuses — that PR is
the human's merge. Any pending check is RUNNING; any failed or cancelled
one is FAILED (`gh pr checks`' exit code counts a cancelled check as
skipped, so the exit code alone is not the verdict)."""
if "/pull/" not in url:
return "PARKED-ON-ISSUE"
run = run or subprocess.run
try:
res = run(["gh", "pr", "checks", url], capture_output=True, text=True, timeout=60)
res = run(["gh", "pr", "checks", url, "--json", "name,bucket,state"],
capture_output=True, text=True, timeout=60)
except (OSError, subprocess.TimeoutExpired):
return "UNKNOWN"
if res.returncode == 0:
return "HEALTHY"
if res.returncode == 8:
if "no checks" in ((res.stderr or "") + (res.stdout or "")).lower():
return "NO-CHECKS"
try:
checks = json.loads(res.stdout or "")
except ValueError:
checks = None
if not isinstance(checks, list):
return "UNKNOWN" # gh could not say (auth, network): never a pass
buckets = [str(c.get("bucket") or "").lower() for c in checks if isinstance(c, dict)]
if any(b in ("fail", "cancel") for b in buckets):
return "FAILED"
if any(b not in _DONE_BUCKETS | {"skipping", "pending"} for b in buckets):
return "UNKNOWN" # a bucket this reader does not know: fail closed
if "pending" in buckets:
return "RUNNING"
if "no checks" in (res.stderr or res.stdout or "").lower():
if "pass" not in buckets:
return "NO-CHECKS"
return "FAILED"
return "HEALTHY"


# --- build ---------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions agents/conductors/batch/_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,8 +1454,9 @@ def _closeouts(slot: Path, brief: dict, counters: dict, spawner, now: _dt.dateti
"""Reap finished close-out sessions, then start one per newly green PR.

The watcher's guards are the ones it can judge from its own reads (AUTONOMY
"Unattended `glance` merges"): the recorded tier, green CI by `gh pr checks`,
the brief's `merge-cap:`, and never in a shadow shift. The label, Heart and
"Unattended `glance` merges"): the recorded tier, green CI by `gh pr checks`
(at least one completed check, all green — a PR with none is refused,
PyAutoHeart#343), the brief's `merge-cap:`, and never in a shadow shift. The label, Heart and
the witness are the close-out session's to check — it is the independent
session, and it refuses rather than merges when one fails.

Expand Down
6 changes: 5 additions & 1 deletion agents/conductors/batch/closeout_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ outcome — the human merges by `/prm` at check-in.

It prints `green`, `red`, `stale` or `unknown`. Only `green` passes: `stale`
never does, and `unknown` (a reply that is not Heart's dev-ship gate, or no
Heart here) parks — refuse with the word it printed.
Heart here) parks — refuse with the word it printed. A repo Heart does not
gate reads `green` with a "gate-deferred" note: its PR checks decide, so
refuse unless the head has **at least one completed check and every check
green** (`gh pr checks {pr_url} --json name,bucket`: none, or only
`skipping`, refuses — PyAutoHeart#343).
4. If everything passed, use the prm skill on {pr_url}: the full close-out,
judged exactly as a human-typed `/prm`. Never commit to PyAutoMind yourself
— a hook refuses it; queue each Mind change with
Expand Down
4 changes: 3 additions & 1 deletion skills/prm/prm.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ test leg `skipped` is **not green** — name it; a tiered merge stops on it.
- **Red** — **fetch the failing job's log immediately** (GitHub purges it),
quote the failing step, and stop: no merge, no re-run, no waiting for the
flake. Offer `/bug`, or a named re-run if the user judges it a flake.
- **No checks configured** — say so explicitly and ask before merging.
- **No completed check on the head** (no CI, or every check skipped) — say
so; a human-typed `/prm` asks before merging, a tiered or unattended merge
refuses: at least one completed check, all green (PyAutoHeart#343).

## 4. Merge

Expand Down
8 changes: 6 additions & 2 deletions skills/prm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ differences:
else report and end; the human runs `/prm`.
- **Extra refusals (step 4).** Never merge a `decision-taken` PR, a Heart
RED-override or corrective-PR-exception ship, red / pending / conflicting
CI, or a SKIPPED test leg — report and stop; the human runs `/prm`. The
library-first, sibling-branch and data-worktree guards apply verbatim.
CI, a SKIPPED test leg, or a head with **no completed check** — at least one
completed check, all green, is required (PyAutoHeart#343: for a repo Heart
does not gate, the PR's checks are the only CI evidence, so a repo with no
CI, such as the website, stays a human merge) — report and stop; the human
runs `/prm`. The library-first, sibling-branch and data-worktree guards
apply verbatim.
- **The merge call.** `gh pr merge <n> --merge` as a **bare, unchained** Bash
call (no `&&`, `;` or pipe); if the permission layer denies it, stop and
report — never retry it another way. For `glance`, the close-out appends the
Expand Down
21 changes: 21 additions & 0 deletions tests/test_orchestrator_closeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime as _dt
import json
import shutil
import subprocess
import sys
from pathlib import Path

Expand Down Expand Up @@ -126,6 +127,26 @@ def test_a_non_glance_task_is_never_closed_out(tmp_path):
assert co["state"] == "refused" and "only glance merges unattended" in co["why"]


def test_witness_343_a_pr_with_zero_completed_checks_is_refused_at_merge(tmp_path):
"""PyAutoHeart#343 Witness: a PR whose head has no completed check (a repo
with no CI, such as the website, or only skipped checks) is refused at the
watcher's merge guard and left to the human — through the real
`gh pr checks --json` reader, not a stubbed verdict."""
def gh(out, err="", rc=0):
return lambda argv, **kw: subprocess.CompletedProcess(argv, rc, out, err)
no_ci = gh("", "no checks reported on the 'feature/x' branch", rc=1)
skipped_only = gh(json.dumps([{"name": "smoke", "bucket": "skipping", "state": "SKIPPED"}]))
health = {PR1: lambda u: _digest.pr_health(u, run=no_ci),
PR2: lambda u: _digest.pr_health(u, run=skipped_only)}
mind, brief, home, sp = _shift(tmp_path, cap=2)
_tick(brief, mind, home, sp, 1, health=lambda u: health[u](u))
assert sp.closeouts == []
c = orch.read_counters(orch.slot_dir(brief, home))
assert c["closeouts"][PR1]["state"] == "refused"
assert c["closeouts"][PR1]["why"] == "CI NO-CHECKS — never merged unattended"
assert c["closeouts"][PR2]["why"] == "CI NO-CHECKS — never merged unattended"


def test_red_ci_is_refused_and_pending_ci_waits(tmp_path):
mind, brief, home, sp = _shift(tmp_path, cap=2)
h = _health({PR1: "FAILED", PR2: "RUNNING"})
Expand Down
28 changes: 22 additions & 6 deletions tests/test_orchestrator_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,29 @@ def test_parse_done_keeps_issue_urls_out_of_prs():
assert state == "https://github.com/o/r/issues/7 — PARKED-ON-ISSUE"


@pytest.mark.parametrize("rc,err,want", [(0, "", "HEALTHY"), (8, "", "RUNNING"),
(1, "", "FAILED"),
(1, "no checks reported", "NO-CHECKS")])
def test_pr_health_reads_the_gh_exit_code(rc, err, want):
def _checks(*buckets):
return json.dumps([{"name": f"c{i}", "bucket": b, "state": b.upper()}
for i, b in enumerate(buckets)])


@pytest.mark.parametrize("rc,out,err,want", [
(0, _checks("pass", "pass"), "", "HEALTHY"),
(0, _checks("pass", "skipping"), "", "HEALTHY"),
(8, _checks("pass", "pending"), "", "RUNNING"),
(1, _checks("pass", "fail"), "", "FAILED"),
# gh's exit code counts a cancelled check as skipped: judged per check.
(0, _checks("pass", "cancel"), "", "FAILED"),
(1, "", "no checks reported on the 'x' branch", "NO-CHECKS"),
# Only skipped checks: nothing completed, so nothing to call green.
(0, _checks("skipping"), "", "NO-CHECKS"),
(0, "[]", "", "NO-CHECKS"),
(1, "", "HTTP 401: Bad credentials", "UNKNOWN"),
(0, _checks("pass", "mystery"), "", "UNKNOWN"),
])
def test_pr_health_judges_every_check(rc, out, err, want):
def run(argv, **kw):
assert argv[:3] == ["gh", "pr", "checks"]
return subprocess.CompletedProcess(argv, rc, "", err)
assert argv[:3] == ["gh", "pr", "checks"] and "--json" in argv
return subprocess.CompletedProcess(argv, rc, out, err)
assert _digest.pr_health("https://github.com/o/r/pull/1", run=run) == want
assert _digest.pr_health("https://github.com/o/r/issues/3", run=run) == "PARKED-ON-ISSUE"

Expand Down
Loading