From 322685f5cf9b6192a2b1c32a20170a9b189fea0e Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Sat, 14 Nov 2026 10:41:20 +0000 Subject: [PATCH 1/2] batch: fix the M3.1 dry-run blockers (B1, F1-F4) and record the F5 close-out budget ruling (#632) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - B1: the one Mind writer never lets one bad op strand the rest. A re-apply of what main holds (a move already done, `## slug` sections active.md already has) is a skipped note; any other invalid or failing op is set aside in ledger/set_aside/ with its reason, named in the digest, and the remaining ops commit. A re-dispatched worker is told its claim may exist. - F1: close-outs are reaped in finish_shift and the late sweep (which now runs while one is out: merge counted, stage-2 row, late line, pilot amended); no close-out starts within 20 min of review-at. - F2: `.done` marks an issue `question: ` or `verdict: `; only a question (or a park) is an @mention. - F3: refusals are one entry per (task, reason class) with count and first/last time; token reasons keyed by class; max-workers in one line. - F4: the plan excludes drafts Mind origin/main no longer holds in draft/ or has claimed in active.md (read from the local origin/main ref the writer keeps current; no extra fetch, no pull), unless this shift picked them; fails closed if the ref is unreadable. - F5: close-outs may pass token-budget but count and show in the digest; none starts at 1.5x the budget. AUTONOMY.md "Close-out budget — 2026-11-14", the human's ruling. Co-Authored-By: Claude Opus 5.5 --- AUTONOMY.md | 5 + agents/conductors/batch/AGENTS.md | 34 +++- agents/conductors/batch/_digest.py | 145 +++++++++++-- agents/conductors/batch/_mind_writer.py | 104 ++++++++-- agents/conductors/batch/_orchestrator.py | 226 ++++++++++++++++++--- agents/conductors/batch/worker_template.md | 11 +- tests/test_digest_counters.py | 33 ++- tests/test_orchestrator_closeout.py | 70 +++++++ tests/test_orchestrator_digest.py | 9 +- tests/test_orchestrator_dispatch.py | 113 +++++++++++ tests/test_orchestrator_mentions.py | 22 +- tests/test_orchestrator_mind_writer.py | 45 +++- 12 files changed, 734 insertions(+), 83 deletions(-) diff --git a/AUTONOMY.md b/AUTONOMY.md index 7a5c0683..31dc4e6b 100644 --- a/AUTONOMY.md +++ b/AUTONOMY.md @@ -790,6 +790,11 @@ adversary amendment — 2026-11-04"). *Revert condition:* a `reverted` row demotes the tier exactly as the 2026-10-02 section says; one merge past a brief's cap retires this sub-rule. +**Close-out budget — 2026-11-14 (PyAutoBrain#632), the human's ruling.** A +close-out may take the shift past its `token-budget:`, but its tokens count +against that budget and the digest shows them, and no new close-out starts +once the shift's spend reaches 1.5× the budget. + ### One Mind writer per shift — 2026-11-03 During a shift, **only the orchestrator commits to PyAutoMind**, from its own diff --git a/agents/conductors/batch/AGENTS.md b/agents/conductors/batch/AGENTS.md index bf0ac2f5..fb61e345 100644 --- a/agents/conductors/batch/AGENTS.md +++ b/agents/conductors/batch/AGENTS.md @@ -263,7 +263,11 @@ pin that and record every process a full brief run starts. `bin/orchestrator_watch.py --brief --mind ` runs **one tick**: `STOP` first, then the open-brief gate, the tick lock, the lease reap, the plan inside the brief, the caps (`max-workers:`, default 2; -`max-sessions:`, default 6) and an exclusive-create lease per spawn. State lives +`max-sessions:`, default 6) and an exclusive-create lease per spawn. The plan +is checked against Mind `origin/main` (#632): a draft not under its `draft/` or +claimed in its `active.md` is excluded unless this shift picked it, read from the +local `origin/main` ref the one Mind writer keeps current (no extra fetch, no +pull). State lives under `$PYAUTO_ORCHESTRATOR_HOME` (default `.orchestrator` under the worktree root), one directory per brief: `STOP`, `leases/`, `counters.json`, `tick.log`. Until phase 3b it spawns only stub workers (`PYAUTO_ORCHESTRATOR_FAKE=1`); a real @@ -300,7 +304,9 @@ session is `unmeasured`: it stops blocking, its reservation counts as its usage, and the pilot row's `tokens` is `null` (`unmeasured` in `pilot.md`), never 0. Subagent transcripts (`/subagents/agent-*.jsonl`) are included and reported as `subagents`. The digest's `### Refusals` lists every spawn -refusal with its reason. A real worker holds a reservation from its spawn (default +refusal with its reason: `counters.json` keeps one entry per task and reason +class (a token reason without its running figure) with its count and first and +last time, and every `max-workers` refusal is one line (#632). A real worker holds a reservation from its spawn (default `token-budget / max-sessions`) until its usage passes it, so the budget binds on the first tick; `token-budget:` refuses a spawn once spent, or once committed usage plus a new reservation would pass it. Every worker has one exit record @@ -318,8 +324,12 @@ the reap, `_mind_writer.commit_ledger` applies all pending ops in a temporary detached worktree on `origin/main`, commits once and pushes; if `main` moved it replays the ops on the new `origin/main` (up to three tries). It never resets, never forces, and never touches the canonical checkout's working tree. -Committed op files move to `ledger/committed/`; an op that cannot apply stays -pending and the tick reports it. **Enforced, not asked:** a worker runs with +Committed op files move to `ledger/committed/`. One bad op never strands the +rest (#632): a re-apply of what main holds (a `move` already done, an `append` +of `## slug` sections `active.md` already has — a re-dispatched worker's claim) +is a skipped note, and any other op that is invalid or cannot apply is set aside +in `ledger/set_aside/` with its reason, named in the digest, while the rest +commit. A re-dispatched worker is told its claim may already exist. **Enforced, not asked:** a worker runs with `PYAUTO_SHIFT_WORKER=1`, `PYAUTO_SHIFT_LEDGER_DIR`, and `core.hooksPath` (via `GIT_CONFIG_*`) pointing at `bin/worker_git_hooks/`, whose `pre-commit` refuses any commit in a PyAutoMind repo — `prompt_sync_push`, `lifecycle close` @@ -399,8 +409,9 @@ running close-outs — `.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 — 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 +check, all green (pending waits a tick; red, none or unknown is refused), merges plus in-flight close-outs are under `merge-cap:`, the +shift is not shadow, `review-at:` is more than 20 minutes away, and spend is +under 1.5× `token-budget:` (#632; AUTONOMY.md "Close-out budget — 2026-11-14"). Then it starts **one** close-out session (`closeout_template.md`; `claude --bg --name shift-close: --model opus`). That session is the independent leg: it runs the `Witness:` itself, reviews the diff adversarially, checks the `decision-taken` label and Heart, and only then @@ -426,8 +437,10 @@ holding real worker leases, and `gh pr checks` for unmerged PRs, cached for the interval. **Late arrivals (PyAutoBrain#594).** A worker may finish after `review-at:`, -once the digest is posted. A closed shift with a lease still held or a ledger op -still queued runs `late_sweep` on each tick: it reaps as a live tick does, +once the digest is posted. A closed shift with a lease still held, a close-out +still running or a ledger op still queued runs `late_sweep` on each tick: it +reaps workers and close-outs as a live tick does (a late close-out merge is +counted, its stage-2 row written and named as a late line, #632), commits the queued ops through the one Mind writer, and appends one `- late: — (after review-at,