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
3 changes: 2 additions & 1 deletion agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ 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 --json`, judged per check (PyAutoHeart#343): any
read-only `gh pr checks --json`, judged per check by `bin/ci_verdict.py`'s
`judge` (PyAutoBrain#628; 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
Expand Down
54 changes: 33 additions & 21 deletions agents/conductors/batch/_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
import json
import re
import subprocess
import sys
from pathlib import Path

import _brief # noqa: E402

# The one CI judgement (PyAutoBrain#628) lives in bin/, beside its CLI.
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "bin"))
import ci_verdict # noqa: E402

DIGEST_HEADING = "## Digest"
SECTIONS = ("### Brief work", "### Backlog picks", "### Proof packets", "### Counters")
#: Every counter, always printed — a zero is a fact, an absent line is a finding.
Expand Down Expand Up @@ -97,20 +102,21 @@ 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 --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)."""
"""One read-only `gh pr checks --json`, judged by `bin/ci_verdict.py`
(PyAutoBrain#628) — the one CI judgement `/prm` and the close-out run too.

The watcher's network surface is `gh pr checks` only (AUTONOMY.md "The
watcher's network surface"), so this keeps that read and hands its rows to
`ci_verdict.judge` with mergeability not read; the close-out session runs
the full `pyauto-brain ci-verdict`, which reads it. The words map from the
verdict: GREEN is HEALTHY (at least one completed check, every completed
check green — PyAutoHeart#343); a failed, cancelled or timed-out check is
FAILED (`gh pr checks`' exit code counts a cancelled check as skipped, so
the exit code alone is not the verdict); a bucket the judge does not know
is UNKNOWN (fail closed); a pending check is RUNNING; no checks, or only
skipped ones, is NO-CHECKS, which the close-out refuses — that PR is the
human's merge."""
if "/pull/" not in url:
return "PARKED-ON-ISSUE"
run = run or subprocess.run
Expand All @@ -120,23 +126,29 @@ def pr_health(url: str, run=None) -> str:
except (OSError, subprocess.TimeoutExpired):
return "UNKNOWN"
if "no checks" in ((res.stderr or "") + (res.stdout or "")).lower():
return "NO-CHECKS"
return health_word(ci_verdict.judge([], read_mergeable=False))
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 health_word(ci_verdict.judge(ci_verdict.from_pr_checks(checks),
read_mergeable=False))


def health_word(verdict: dict) -> str:
"""A `ci_verdict.judge` result in the watcher's words."""
codes = {r["code"] for r in verdict["reasons"]}
if codes & {"check-failed", "check-cancelled", "check-timed-out"}:
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:
if "check-unrecognised" in codes:
return "UNKNOWN"
if verdict["verdict"] == ci_verdict.PENDING:
return "RUNNING"
if "pass" not in buckets:
if codes & {"no-checks", "skipped-only"}:
return "NO-CHECKS"
return "HEALTHY"
return "HEALTHY" if verdict["verdict"] == ci_verdict.GREEN else "UNKNOWN"


# --- build ---------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions agents/conductors/batch/_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,18 @@ def closeout_prompt(task: str, pr_url: str, prompt_path: str, brief_path: Path,
lease_dir: Path) -> str:
"""The close-out session template filled in for one PR (phase 4b). Its
Heart check is the scoped development-ship gate for the PR's repo (leg 4,
PyAutoHeart#340): only `green` merges."""
PyAutoHeart#340): only `green` merges. Its CI check is `pyauto-brain
ci-verdict` on the PR (PyAutoBrain#628): only `GREEN` merges."""
repos = pr_repos(pr_url)
heart_cmd = (f"bash -c 'source \"{COMMON_SH}\"; consult_vitals_verdict --repos {repos}'"
if repos else "")
return CLOSEOUT_TEMPLATE.read_text(encoding="utf-8").format(
task=task, pr_url=pr_url, task_path=prompt_path, brief_path=brief_path,
lease_dir=lease_dir, ledger_dir=Path(lease_dir).parent / _mind_writer.LEDGER_DIR,
shift_ledger=SHIFT_LEDGER, pr_repos=repos or "(none — not a GitHub PR URL)",
heart_cmd=heart_cmd or "(cannot be scoped — refuse)")
heart_cmd=heart_cmd or "(cannot be scoped — refuse)",
ci_verdict_cmd=f"{BRAIN_CLI} ci-verdict {pr_url}" if repos
else "(not a GitHub PR URL — refuse)")


def closeout_command(task: str, pr_url: str, prompt_path: str, brief_path: Path,
Expand Down
23 changes: 16 additions & 7 deletions agents/conductors/batch/closeout_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,30 @@ 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. 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. Immediately before you merge — after every check above, and again right
gate reads `green` with a "gate-deferred" note: its PR checks (step 4)
decide (PyAutoHeart#343).
4. Judge the PR's CI with the one CI-verdict script (PyAutoBrain#628), for
every repo — never by reading `gh pr checks` yourself:

{ci_verdict_cmd}

It reads every check-run, workflow run and job on the REST head sha, and
mergeability, and prints `GREEN`, `PENDING` or `RED` with reasons (exit 0,
2, 1). Only `GREEN` passes. `PENDING` or `RED` refuses with its first
reason line (`CI PENDING: …` / `CI RED: …`): no waiting, no re-run. A
`GREEN` that names a skipped **test** leg refuses too (a tiered merge
stops on a skipped test leg, `skills/prm/reference.md` "Tiered merge").
5. Immediately before you merge — after every check above, and again right
before the merge command itself — look for {lease_dir}/{task}.dropped. If
it exists, the human dropped this task with `/drop` mid-shift: do not merge;
refuse with why `dropped by /drop`.
5. If everything passed, use the prm skill on {pr_url}: the full close-out,
6. 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
`{shift_ledger} append|write|move|remove|drop-section ...` (ops land in
{ledger_dir}/) and the orchestrator commits them. Do **not** append the
Shadow-window row: the watcher writes the stage-2 row from your verdict.
6. End at your deliverable. Never arm anything that outlives your turn.
7. End at your deliverable. Never arm anything that outlives your turn.

Last, write {lease_dir}/{task}.closeout as one JSON object:

Expand Down
6 changes: 6 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Executable tooling for the PyAuto organism.
than 6 h is never GREEN (STALE, `pass: false`); `--repos A,B` asks the local
Heart's scoped dev-ship gate (PyAutoHeart#340). Run first by `start_dev`
step 0a and `route`.
- **`ci_verdict.py`** — `pyauto-brain ci-verdict <owner/repo>#<n> [--json]`:
the one CI judgement for a PR (PyAutoBrain#628). REST head sha (empty is
refused), every check-run, commit status, workflow run and job, and
mergeability → GREEN / PENDING / RED with reasons; exit 0 · 2 · 1. `/prm`
step 2 and the shift close-out run it; the watcher's `pr_health` feeds its
`gh pr checks` rows to the same `judge`.
- **`lane_backfill.py`** — proposes a `Lane:` for every lane-less draft in
the planner pool, from intake's own lane signals, as a table for a human to
skim; `--apply [--from <table>]` writes the headers (commits nothing).
Expand Down
Loading
Loading