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
71 changes: 56 additions & 15 deletions AUTONOMY.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,13 @@ never an assumption:
import path, or a public name the diff touches); none match → the
cheapest script of the changed repo's own workspace, as an import check.
The PR body says which smoke ran.
- *Before any unattended merge* — the **full affected** smoke on the PR
head: `pyauto-heart smoke --affected-by <the PR's repo> --jobs 3` (every
workspace whose install chain has the repo, three at a time,
thread-capped). The close-out runs it for a `glance` PR or a `notify` PR
(every `notify` PR in a shift, since its worker now ends at PR-open —
"Shift `notify` workers end at PR-open — 2026-11-19" below;
`agents/conductors/batch/closeout_template.md`). Any failure refuses the
merge → `/prm`.
- *Before any unattended merge* — no full smoke since ruling S2 ("Shift
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
`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
public-name hit, a refusal) — no automatic full sweep: the worker's
targeted smoke plus PR CI; the human runs `/smoke_test` if they want it.
Expand Down Expand Up @@ -504,13 +503,43 @@ human (`/prm`) already reads the PR a second time.
unattended merge ("Stage-2 adversary amendment — 2026-11-04") and the
human at `/prm` for everything else.

- **S2, leg 2 before an unattended merge** (M3.7b, PyAutoBrain#688). The
pre-merge smoke is the worker's targeted smoke. The close-out runs no full
affected smoke. The full sweep runs in the cloud after the merge (nightly,
M3.7d; at shift end, M3.7e). *Revert condition:* one red sweep traced to
an unattended merge restores the close-out's full affected smoke.
- **S5, close-out timing** (M3.7b). A close-out may start at PR-open, while
CI still runs. It runs the `Witness:`, reads the diff adversarially and
checks the label, public names and Heart first. Then it waits in-turn for
CI and merges only on a green `ci-verdict`. The wait has a limit: 30
minutes from the start, and never later than 5 minutes before
`review-at:` (`CLOSEOUT_MERGE_MARGIN_S`, room for the `/prm` run after
green, so no close-out merges after `review-at:`). The merge is pinned to
the witnessed head (`gh pr merge --match-head-commit`). A CI that has not
finished by then refuses to `/prm`. Every other guard of "Unattended
`glance` merges — 2026-11-03" applies unchanged. The merge slot is taken
immediately before the merge, by the close-out session itself
(`pyauto-brain merge-slot take`, the human's decision A). The watcher only
checks that one is free before it starts the session. A close-out that
sees red CI after it started has spent its tokens; the digest counts them
as before.
- **S6, M3.6j ruling (a) amended** (M3.7b). The branch update and the CI
rerun on the new head are needed only when the PR's changed files overlap
those of a PR of this shift merged ahead of it on that library, or when
GitHub reports the branch as conflicting. A file list that cannot be read
counts as an overlap. Otherwise the PR merges on its own green CI. Merge
order (rulings b, c, f) is unchanged. Two disjoint PRs that are each green
can still break `main` together; `main` CI and the shift-end sweep find
that after the merge. *Revert condition:* one red `main` CI traced to two
disjoint shift PRs merged this way restores the unconditional update.

A worker caps any pytest it runs at `-n 4`. It starts the review beside the
tests and the targeted smoke (leg 2), and opens the PR as soon as they pass
(`agents/conductors/batch/worker_template.md`).

Outside a shift (an `--auto` chat) nothing changes.

Later rulings from the same review (S2, S4 to S7) are added to this section.
Later rulings from the same review (S4, S7) are added to this section.

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

Expand Down Expand Up @@ -615,8 +644,8 @@ and the close-out merges after the affected smoke.** This replaces R3's
in-turn path inside a shift (its first two bullets): a shift worker never runs
`merge-slot take` or `gh pr merge`, whatever its tier. The watcher closes out
a green `notify` PR exactly as a `glance` one (R3's third bullet, unchanged),
and that close-out runs the witness and the full affected smoke
(`pyauto-heart smoke --affected-by <repo> --jobs 3`) before it merges. R3's
and that close-out runs the witness before it merges (it ran the full
affected smoke too, until ruling S2 of "Shift speed — 2026-11-19"). R3's
fourth bullet stands: these are `notify` merges, not stage-2 rows. Outside a
shift (an `--auto` chat, no close-out), R3's in-turn merge is unchanged.
`merge-slot take` keeps refusing an out-of-order in-turn merge as a backstop,
Expand Down Expand Up @@ -706,7 +735,7 @@ section is that dated doctrine edit.
the author** — Opus 5.5 for both, on cost: the alternatives were a more
expensive model (Fable) or a weaker one (Sonnet). What makes it the leg is
**independence, not the model**: a **fresh close-out session** the watcher
starts after CI lands, which did not write the PR, shares none of the worker's
starts after CI lands (at PR-open since ruling S5, 2026-11-19), which did not write the PR, shares none of the worker's
context, **runs the `Witness:` itself** and reviews the diff adversarially
before it merges or refuses (`agents/conductors/batch/closeout_template.md`).
It applies to the first 10 rows of the stage-2 sub-window exactly as the ruling
Expand Down Expand Up @@ -920,8 +949,9 @@ to per-task `--auto` until the cause is found.
### Unattended `glance` merges — 2026-11-03

This extends the 2026-10-02 table. For a declared `glance` task under an open
brief, **the in-turn wait may be replaced by a watcher-started close-out after
CI lands**, only when every one of these holds:
brief, **the in-turn wait may be replaced by a watcher-started close-out**,
only when every one of these holds. Since ruling S5 ("Shift speed —
2026-11-19") the close-out starts at PR-open and merges only on green CI:

1. an **independent session** ran the `Witness:` — not the author; a different
model where one is available, as leg 5 already requires of the adversary;
Expand Down Expand Up @@ -955,7 +985,9 @@ while an earlier PR of the shift on it is open. Six rulings:
- **(a)** an unattended branch-update session may push a merge from `main` to a
shift PR's branch (`gh pr update-branch`, never a rebase or force-push), then
must end; a later close-out merges only on CI green at the new head. The
watcher itself still pushes nothing;
watcher itself still pushes nothing. Since ruling S6 (2026-11-19, M3.7b)
this applies only when the PR's changed files overlap a PR merged ahead of
it, or GitHub reports a conflict;
- **(b)** the watcher may `gh pr view` the PRs a waiting PR waits behind every
tick, carried ones included;
- **(c)** an earlier PR blocks until GitHub says MERGED or CLOSED, whatever its
Expand Down Expand Up @@ -1199,6 +1231,15 @@ The revert condition also covers these: an @mention for a parked question,
or any read of `questions.md` other than that local one, retires the watcher
to fake mode.

**Amendment — 2026-11-19 (M3.7b, PyAutoBrain#688), approved by the human
(decision B).** For ruling S6 ("Shift speed — 2026-11-19") the watcher may
read, read-only, the changed-file list (`gh pr view --json files`) of a
waiting library PR and of the earlier PRs of the shift merged ahead of it on
that library. It reads each PR's list at most once per shift and keeps it.
`mergeable` is a field of the `gh pr view` it already makes, not a new call.
A repeat read for the same PR in one shift falls under the existing revert
condition.

**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
56 changes: 38 additions & 18 deletions agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,28 @@ running close-outs — `<task>.closeout` (`merged` | `refused`, `why`, `gate`,
each PR a worker named, judges the guards it can see with its own reads: the
recorded tier is `glance` or `notify` (ruling R3, 2026-11-17; since 2026-11-19
every `notify` PR comes here, its worker having ended at PR-open — ruling "ii",
PyAutoHeart#352), `gh pr checks` is green — at least one completed
check, all green (pending waits a tick; red, none or unknown is refused), the
shift is not shadow, `review-at:` is more than 20 minutes away, spend is
under 1.5× `token-budget:` (#632; AUTONOMY.md "Close-out budget — 2026-11-14"),
and — last — a merge slot is free under `merge-cap:` (`_merge_slots.py`; a
worker's in-turn merge takes from the same count). Then it starts **one** close-out session
(`closeout_template.md`; `claude --bg --name shift-close:<task> --model opus --effort medium`).
That session is the independent leg: it runs the `Witness:` itself, reviews the
diff adversarially, checks the `decision-taken` label and Heart, runs the full
affected smoke on the PR head (`pyauto-heart smoke --affected-by <repo> --jobs 3`,
PyAutoHeart#352), and only then runs the `/prm` close-out — or refuses. A merge marks the PR merged; a `glance` one also bumps `glance_auto_merges`
PyAutoHeart#352), `gh pr checks` is running or green (ruling S5, M3.7b:
the close-out starts at PR-open; red or unknown is refused; none at all waits
`UPDATE_CHECKS_GRACE_S`, 600 s, from when the watcher first saw the PR in
`counters["pr_seen"]`, then is refused), the shift is not shadow,
`review-at:` is more than 20 minutes away, spend is under 1.5×
`token-budget:` (#632; AUTONOMY.md "Close-out budget — 2026-11-14"), and —
last — a merge slot is free under `merge-cap:` (`_merge_slots.room`, counting
the merge close-outs already running without one). The watcher takes no slot
for a merge close-out (decision A): the session takes it itself with
`pyauto-brain merge-slot take` immediately before the merge, and the reaper
frees it when the close-out refuses, whoever holds it for that task. Then the
watcher starts **one** close-out session
(`closeout_template.md`; `claude --bg --name shift-close:<task> --model opus --effort medium`),
with a CI deadline: `CLOSEOUT_CI_WAIT_S` (30 minutes) from now, never later
than `review-at:` minus `CLOSEOUT_MERGE_MARGIN_S` (5 minutes). That session is the independent leg: it runs the `Witness:`
itself on the PR head and records that head, reviews the diff adversarially,
checks the `decision-taken` label and Heart, then waits in-turn for CI
(`pyauto-brain ci-verdict <pr> --until <deadline>`, repeated while PENDING),
checks the head did not move, takes its slot (its output must say `taken: `)
and runs the `/prm` close-out, its merge pinned with `--match-head-commit` —
or refuses. It runs no full affected smoke (ruling S2); the cloud sweep runs
after the merge. A merge marks the PR merged; a `glance` one also bumps `glance_auto_merges`
and queues a `table-append` op that lands one row in
`autonomy_log.md` "Unattended `glance` sub-window (stage 2)" through the one Mind
writer. Every refusal is final for the shift and named in the digest
Expand All @@ -555,17 +566,26 @@ tick, one `gh pr view` per blocking PR per tick, ruling b) and a `waiting`
event when what it waits behind changes. A workspace PR waits while its own
task's library PR waits or is being closed out. Once nothing is ahead, a PR
whose branch was cut before an earlier PR merged (merged after its task's first
worker started; for a carried PR, any merged earlier PR) takes its merge slot
and gets one **branch-update session** (`closeout_update_template.md`, `claude
worker started; for a carried PR, any merged earlier PR) gets a branch update
only when the two PRs' changed files overlap, a file list cannot be read, or
GitHub reports this PR `CONFLICTING` (ruling S6, M3.7b). The watcher reads
each PR's files once a shift (`gh pr view --json files`, kept in
`counters["pr_files"]`; an unreadable list is kept as unreadable, counts as
an overlap and is not read again) and `mergeable` from its usual `gh pr view`. A
disjoint earlier PR is not updated for: the close-out's step 4b names it
`merged ahead, disjoint files, not updated (S6)` and does not compare it. A
PR that needs the update has the watcher take its merge slot and gets one
**branch-update session** (`closeout_update_template.md`, `claude
--bg --name shift-update:<task>`), after the public-name gate: it runs `gh pr
update-branch` (a merge commit from `main`; never a rebase or force-push,
ruling a), writes `updated` (new head), `current` or `refused` (`conflicts with
main after <A> merged → your /prm`) and ends. An `updated` or `current` PR
keeps its slot and is looked at again each tick: CI running, or NO-CHECKS
within `UPDATE_CHECKS_GRACE_S` (600 s), waits; red refuses (`CI <verdict> on
the updated head → your /prm`) and frees the slot; green starts the merge
close-out, whose step 4b checks every earlier PR is no longer OPEN and each
merged one is in the branch. A PR needing a third update refuses (`main kept
keeps its slot and is looked at again each tick: NO-CHECKS within
`UPDATE_CHECKS_GRACE_S` (600 s) waits; red refuses (`CI <verdict> on the
updated head → your /prm`) and frees the slot; running or green on the head
the update made starts the merge close-out (S5), which waits in-turn for CI
and whose step 4b checks every earlier PR is no longer OPEN and each merged
one it was updated for is in the branch. A PR needing a third update refuses (`main kept
moving`, `UPDATE_LIMIT` 2). A waiting or updated PR at `review-at:` is not
refused; the next shift carries it with what it waited behind. The digest says
`waits behind <A> (<A's state>) — merge <A> first` and lists a per-library
Expand Down
64 changes: 47 additions & 17 deletions agents/conductors/batch/_merge_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
in-turn `notify` merge and the watcher's close-outs alike. Shift 2026-11-16-pm
read "2 merged of merge-cap 1" because the workers never asked. A worker runs
`pyauto-brain merge-slot take <pr>` (`bin/merge_slot.py`) as its own bare call
before its bare `gh pr merge`; the watcher takes a slot just before it spawns a
close-out. Both write the same file.
before its bare `gh pr merge`; so does a merge close-out session, immediately
before its merge (M3.7b, PyAutoBrain#688, decision A). The watcher takes a slot
only before it spawns a branch-update session; before a merge close-out it only
reads whether one is free (`room`). All write the same file.

The file is `merge_slots.json` in the shift's slot directory, read and written
under an exclusive `fcntl.flock` on `merge_slots.lock` beside it, and written
Expand Down Expand Up @@ -36,6 +38,9 @@
LOCK_FILE = "merge_slots.lock"
#: Who the watcher is, as a slot holder.
WATCHER = "watcher"
#: Who every worker and close-out session is, as a slot holder (one class:
#: `bin/merge_slot.py` takes as this).
SESSION = "worker"


#: A GitHub PR URL, with anything after the number (`/files`, `/`, `#…`, `?…`).
Expand Down Expand Up @@ -120,34 +125,59 @@ def publish(slot: Path, cap: int, paused: bool) -> None:
data["published"] = _now()


def _judge(data: dict, key: str, task: str, pending: int = 0) -> tuple[bool | None, str]:
"""(True, why) when `key` already holds a slot for `task`; (None, "") when
a slot is free for it; (False, why) when it is refused. `pending` counts
slots promised but not yet taken (`room`)."""
held = data["slots"].get(key)
cap, used = data.get("cap"), len(data["slots"])
if held and task and held.get("task") == task:
return True, (f"{key} already holds a merge slot for task {task} "
f"(taken by {held.get('by', '?')})")
if held:
return False, (f"{key} holds a merge slot for task {held.get('task') or '?'}, "
f"not {task or '(no task)'} — left for your /prm")
if cap is None:
return False, "no merge-cap published by the watcher — left for your /prm"
if data.get("paused"):
return False, "the shift is paused — left for your /prm"
if used + pending >= int(cap):
return False, f"merge-cap {cap} reached this shift — left for your /prm"
return None, ""


def take(slot: Path, pr: str, by: str, task: str = "") -> tuple[bool, str]:
"""(taken, why). Idempotent per PR and task; every refusal is recorded."""
key = pr_key(pr)
if key is None:
return False, (f"{pr!r} is not a https://github.com/<owner>/<repo>/pull/<n> URL "
"— left for your /prm")
with _locked(slot) as data:
held = data["slots"].get(key)
cap, used = data.get("cap"), len(data["slots"])
if held and task and held.get("task") == task:
return True, (f"{key} already holds a merge slot for task {task} "
f"(taken by {held.get('by', '?')})")
if held:
why = (f"{key} holds a merge slot for task {held.get('task') or '?'}, "
f"not {task or '(no task)'} — left for your /prm")
elif cap is None:
why = "no merge-cap published by the watcher — left for your /prm"
elif data.get("paused"):
why = "the shift is paused — left for your /prm"
elif used >= int(cap):
why = f"merge-cap {cap} reached this shift — left for your /prm"
else:
ok, why = _judge(data, key, task)
if ok:
return True, why
if ok is None:
used, cap = len(data["slots"]), data.get("cap")
data["slots"][key] = {"by": by, "task": task, "at": _now()}
return True, f"merge slot {used + 1} of merge-cap {cap} taken for {key}"
data["refusals"].append({"pr": key, "by": by, "task": task, "why": why, "at": _now()})
return False, why


def room(slot: Path, pr: str, task: str, pending: int = 0) -> tuple[bool, str]:
"""(free, why) — whether `take(pr, task)` would succeed now, read only:
nothing is taken and no refusal recorded (M3.7b, decision A: the watcher
reads this before a merge close-out; the session takes its slot itself,
immediately before the merge). `pending` is the slots already promised to
close-outs still running without one, so the cap is never oversold."""
key = pr_key(pr)
if key is None:
return False, (f"{pr!r} is not a https://github.com/<owner>/<repo>/pull/<n> URL "
"— left for your /prm")
ok, why = _judge(state(slot), key, task, pending)
return ok is not False, why


def release(slot: Path, pr: str, by: str, why: str = "", *, task: str | None = None) -> bool:
"""Free `pr`'s slot, only when `by` took it — and, when `task` is given
(every worker or close-out session holds as one class), only for that
Expand Down
Loading
Loading