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
70 changes: 68 additions & 2 deletions AUTONOMY.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ never an assumption:
speed — 2026-11-19" below; M3.7b, PyAutoBrain#688). The pre-merge smoke
is the worker's targeted smoke, and PR CI must be green. The full sweep
runs in the cloud after the merge: the Workspace Smoke workflow, nightly
(M3.7d) and at shift end (M3.7e). Until S2 the close-out ran
(M3.7d), and at the close of every shift that merged a library or
workspace PR (M3.7e, live; S4 below). Until S2 the close-out ran
`pyauto-heart smoke --affected-by <the PR's repo> --jobs 3` on the PR
head; S2's revert condition brings that back.
- *PRs bound for the human's `/prm`* (`decision-taken`, `judge`, a
Expand Down Expand Up @@ -569,7 +570,43 @@ Watcher latency (M3.7c, the human's plan decisions of 2026-11-19):
close resumes it in a later shift. A shift that never started anything,
or a shadow shift, stays open to `review-at:`.

A later ruling from the same review (S4) is added to this section.
- **S4, the shift-end sweep** (M3.7e, PyAutoBrain#692). A shift that
merged at least one library or workspace PR dispatches the Workspace
Smoke workflow once at its close: after the last merge, before the digest.
The dispatch has no inputs, so the workflow's own SHA gate decides whether
to sweep; it is never forced. A shift with no such merge, or a shadow
shift, dispatches nothing. A close-out that merges after the close, in
the late window, makes the shift's one dispatch if none was made. A
failed dispatch is not retried: the digest says "sweep not dispatched",
and the human runs it from chat. The sweep
takes about 30 minutes. The digest is not held for it: it says "sweep
running" or "not yet listed", and the next shift's ticks read the result.
Each tick of a shift reads the workflow's latest runs on `main`. The
digest names, per library, the SHA the latest green sweep verified.
- **Red handling** (M3.7e). When the latest completed sweep on `main` is red
(failure or timed out), no unattended close-out starts on a
repo in a failing workspace's install chain (Heart `config/repos.yaml`
`smoke:`) or on that workspace's own repo. The PR is refused for `/prm`
as `workspace sweep red: <run url>`. PRs on other repos still close out.
A cancelled run is no verdict: the run before it on `main` counts. A
failing workspace the watcher cannot map, or a report it cannot read,
blocks every library, chain and workspace repo. A run list that has
failed on every read for 30 minutes (from the first failure; any good
read resets it) holds those repos' PRs instead: a wait, not a refusal,
as `workspace sweep unknown: run list unreadable since <time>`. No
session starts and no slot is taken; the next good read releases them,
and the shift does not close early meanwhile. A close-out already
running on a blocked repo finds a `.sweep-red` marker (red or unknown)
and refuses with its line before it merges. The red block holds in this
shift and the next, until a later sweep on `main` is green or the
human posts `/clear-sweep` on the shift issue. `/clear-sweep` clears the
latest red run only; a newer red run blocks again. The red run files one
bug draft through the one Mind writer, naming the failing scripts, the
blocked repos and the suspect PRs (merged between the last green sweep's
SHAs and the red one's). Reverts are draft PRs opened for the human;
nothing is reverted unattended. Bisection is dispatched from a chat
session (`workspace-smoke-pinned.yml` with `commit_shas`), never by the
watcher.

## Merge authority follows Consequence — 2026-10-02

Expand Down Expand Up @@ -1280,6 +1317,35 @@ per shift. When GitHub cannot say it reads again, at most once a tick; after
3 misses over 15 minutes from first seeing the PR, the PR goes to `/prm`. The
kick file that starts a tick early is local and adds no network act.

**Amendment — 2026-11-19 (M3.7e, PyAutoBrain#692), approved by the human
(ruling S4; decision b).** For the shift-end sweep ("Shift speed —
2026-11-19", S4 and red handling) the watcher's surface gains:

- **one `gh workflow run`** of the Workspace Smoke workflow per shift, at
its close (or in the late window, when a close-out merged after the close
and none was made), with no inputs. Its marker is claimed exclusively before the
call, and a failed dispatch is never retried. This is the one watcher
write not made under the App token: it runs under the human's own `gh`
login (decision b);
- **one `gh run list`** of that workflow's runs on `main` a tick, while a
shift's tick runs;
- **`gh run download`** of a run's two artifacts (`workspace-smoke-shas`,
and `workspace-validation-report` for a run that did not succeed), once
per run id, at most 3 tries ever, cached in the watcher's home;
- **one `compare` read** (`gh api repos/<owner>/<repo>/compare/…`) per
affected repo per red run, cached, for the suspect PRs;
- **the bug draft** for a red run, one per run id, through the one Mind
writer (no new network act);
- **`/clear-sweep`** joins the command set, under the same rules as the
others (the configured login, the first line, after `dispatched:`, once by
id). It clears the block for the latest red run only and is acknowledged
in the status comment.

These reads use the human's `gh` login too. The run list, downloads and
compares make no writes. *Revert condition:* a second dispatch in one
shift, more than one run list a tick, or a download or compare for the same
run id beyond its tries retires the watcher to fake mode.

**Login probe — 2026-11-17.** The watcher runs `claude auth status --json` (local, no model call) on a shift's first tick and when a worker shows as blocked. `loggedIn: false`, or a `loginExpiresAt` already passed, is a `login-expired` event, never "blocked on a person", and no worker starts until it passes.

## Human override for Heart RED (development only)
Expand Down
33 changes: 32 additions & 1 deletion agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,35 @@ close-out, no merge slot and no CI read. It stays an earlier PR in the merge
order, so later PRs on its library wait until GitHub says MERGED or CLOSED.
The digest's `### Waited behind your /prm` names them, one line per library.

**S4: the shift-end sweep and the red block (M3.7e, PyAutoBrain#692).**
`_sweep.py` holds the mechanics; `config/policy.yaml` `shift_watcher:`
names the workflow (`sweep_repo`, `sweep_workflow`, `sweep_siblings`). At
close, `finish_shift` dispatches the Workspace Smoke workflow once
(`gh workflow run`, no inputs, marker `sweep.dispatched`) when GitHub
confirmed a merge this shift on a library, workspace or Heart chain repo.
`late_sweep` makes it instead when a close-out merged after the close. A
shadow shift never dispatches, and a failed dispatch is not retried. Each shift tick makes one
`gh run list` of the workflow on `main`, before steering. Each run's
artifacts are downloaded once per run id, at most 3 tries, into
`<home>/sweep/`, which every shift shares. When the latest completed run (a
cancelled one is skipped) is red and not cleared, `_start_closeouts` refuses a PR on a failing
workspace's chain (Heart `config/repos.yaml` `smoke:`, read locally, plus
the workspace repo from Heart's validation workflow) as `workspace sweep
red: <url>`, right after the S7 check. An unmapped workspace or an
unreadable report blocks every library, chain and workspace repo. A run
list failing for 30 minutes from the streak's first failure holds those
PRs in `counters["sweep_waits"]` instead (a wait, re-judged each tick, no
refusal), and `early_close_ready` keeps the shift open. A running close-out on a
blocked repo gets `leases/<task>.sweep-red` and refuses before it merges;
a marker the current block does not cover is removed.
A later green run clears the block, as does `/clear-sweep`. The latest
red run, cleared or not, files one bug draft (`draft/bug/<most upstream suspect library>/
workspace_sweep_red_<id>.md`, marker `sweep/drafted/<id>`) through the one
Mind writer, with suspect PRs from one compare read per affected repo. All
these calls use the human's own `gh` login (decision b). The digest's
`### Workspace sweep` names the dispatch, the verified SHA per library and
any red block. Nothing in the watcher reverts or bisects.

**Deploy.** Installing the units is the human's step, when no shift is live:

cp bin/systemd/pyauto-orchestrator.{service,timer,path} ~/.config/systemd/user/
Expand Down Expand Up @@ -760,7 +789,9 @@ per command; the draft on origin/main becomes a named task, refused within 30
min of `review-at:`; it overrides `exclude:` and an earlier shift's parked hold,
never the organ rule) and `/kill <task>` (the watcher runs a local `claude stop`
on that task's running worker; the reap marks the exit `killed`, not crashed,
and it is re-dispatched once unless dropped first). Each comment acts once, by id, and is acknowledged
and it is re-dispatched once unless dropped first). M3.7e adds `/clear-sweep`, making
eight: it clears the red sweep block for the latest red run id only
(`<home>/sweep/cleared.json`, kept for later shifts). Each comment acts once, by id, and is acknowledged
once in the status comment's `Commands` list. Without a login, nothing is read
and the comment says steering is off. The dashboard's copy is the record's `-
live:` line (`record-key` op, one Mind writer, on a change of state), shown in
Expand Down
68 changes: 68 additions & 0 deletions agents/conductors/batch/_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ def build(brief: dict, slot: Path, counters: dict, *, tiers: dict | None = None,
lines += cap_lines(counters)
lines += ["", WORKERS_HEADING] + (worker_lines(counters, links) or [NO_PICKS])
lines += ["", REFUSALS_HEADING] + (refusal_lines(counters) or [NO_PICKS])
lines += sweep_lines(counters)
lines += report_lines(slot)
lines += identity_lines(counters)
# The readiness pass's count is the digest's last line (M3.3, #671).
Expand All @@ -776,6 +777,73 @@ def build(brief: dict, slot: Path, counters: dict, *, tiers: dict | None = None,
return "\n".join(lines) + "\n"


SWEEP_HEADING = "### Workspace sweep"
#: The prefix of the close-out refusal a sweep block gives (M3.7e): red, or unknown.
SWEEP_RED_WHY = "workspace sweep "


def _sweep_own(sweep: dict, at: str) -> dict | None:
"""The run the shift's own dispatch started (`_sweep.own_run`)."""
import _sweep # noqa: E402 — deferred: the digest builds without it
return _sweep.own_run({"runs": sweep.get("runs") or []}, at)


def sweep_lines(counters: dict) -> list[str]:
"""The shift-end cloud sweep (M3.7e, PyAutoBrain#692): the shift's own
dispatch and its run, what the latest green sweep verified per library,
and a red sweep's block, refusals and bug draft. The digest is never held
for the sweep. Nothing when the sweep is off."""
sweep, disp = counters.get("sweep") or {}, counters.get("sweep_dispatch") or {}
if not sweep and not disp:
return []
out = []
if disp:
if not disp.get("ok"):
out.append(f"- sweep not dispatched ({disp.get('error') or '?'}) — run it from chat")
else:
own = _sweep_own(sweep, disp.get("at", ""))
if own is None:
out.append(f"- sweep dispatched at {disp.get('at', '?')}, not yet listed")
elif own.get("status") != "completed":
out.append(f"- sweep running: {own.get('url')}")
else:
out.append(f"- this shift's sweep finished: {own.get('conclusion') or '?'} — "
f"{own.get('url')}")
read = sweep.get("read") or {}
if read.get("at") and not read.get("ok"):
out.append(f"- sweep runs unreadable at {read['at']} ({read.get('error') or '?'}); "
"the last known state is below")
if sweep.get("error"):
out.append(f"- sweep state could not be worked out: {sweep['error']}")
green = sweep.get("green") or {}
run = green.get("full_sweep_run_id") or green.get("id") or "?"
for lib, sha in (green.get("verified") or {}).items():
out.append(f"- {lib}: workspaces verified through `{sha}` (run {run})")
blk = sweep.get("block")
if blk:
repos = ", ".join((["every library, chain and workspace repo"]
if blk.get("everything") else [])
+ list(blk.get("repos") or [])) or "?"
refused = [pr_ref(pr) for pr, co in (counters.get("closeouts") or {}).items()
if str(co.get("why") or "").startswith(SWEEP_RED_WHY)]
draft = f"`{blk['draft']}`" if blk.get("draft") else "not filed yet"
if blk.get("kind") == "unknown":
held = [pr_ref(pr) for pr in sorted(counters.get("sweep_waits") or {})]
out.append(f"- {blk.get('why')} — blocked: {repos}; PRs waiting: "
f"{', '.join(held) or 'none'}; PRs refused: "
f"{', '.join(refused) or 'none'}")
else:
out.append(f"- {blk.get('why')} — blocked: {repos}; PRs refused: "
f"{', '.join(refused) or 'none'}; bug draft: {draft}")
cleared = sweep.get("cleared")
if cleared:
out.append(f"- red sweep {cleared.get('url')} cleared by /clear-sweep "
f"({cleared.get('by', '?')}, {cleared.get('at', '?')})")
if not out:
out.append("- no sweep run known yet")
return ["", SWEEP_HEADING] + out


_REPORT_WORDS = {
"skipped": "note: Mind ledger op skipped",
"set-aside": "warning: Mind ledger op set aside, not committed",
Expand Down
Loading
Loading