From c491beb5df8144806f184e12cbedc37ff2138cda Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 12 Nov 2026 20:14:50 +0000 Subject: [PATCH 1/3] fix: shift numbers right and kept; a blocked worker @mentions the human (M1.5 #610, M1.6 #611) M1.5 (#610): - tokens: every live, parked and close-out session's usage is read each tick and stored per session (replaced, never added); transcript_usage dedupes by message id, reports cache-read apart and returns None when unavailable, which refuses the next spawn ("token usage unavailable"); - a per-worker reservation (default token-budget / max-sessions) makes the budget bind on the first tick; - digest counters from per-worker exit records (spawned/finished/crashed/ parked/late, one launch-failed record per task) and from GitHub's merged state read once at review-at; a ### Workers section, one line per worker; - finish_shift reaps first; issue URLs kept out of `prs`; - one batches/pilot/pilot.jsonl line per shift, pilot.md its render, both upserted by slot through the one Mind writer (new jsonl-upsert and table-upsert ops); the late sweep amends the line and posts one correction comment; a post gh said failed is retried (3 tries, never after a timeout). M1.6 (#611): - a worker parked (blocked past the grace) or parked on its issue posts one comment on the shift's digest issue @-mentioning the login from PYAUTO_SHIFT_MENTION or config/policy.yaml shift_watcher.mention_login; one per worker per state, marker before post, retried on failure; counted in `pushes`. AUTONOMY.md network surface amended (2026-11-12 ruling). Tests run offline: conftest stubs the watcher's GitHub seams unless a test passes its own run=. Co-Authored-By: Claude Opus 5.5 --- AUTONOMY.md | 26 + agents/conductors/batch/AGENTS.md | 51 +- agents/conductors/batch/_digest.py | 166 ++++++- agents/conductors/batch/_mind_writer.py | 76 ++- agents/conductors/batch/_orchestrator.py | 581 ++++++++++++++++++++--- agents/conductors/batch/_watch.py | 2 +- config/policy.yaml | 8 + skills/batch/batch.md | 4 +- tests/conftest.py | 23 + tests/test_digest_counters.py | 204 ++++++++ tests/test_orchestrator_digest.py | 51 +- tests/test_orchestrator_mentions.py | 144 ++++++ tests/test_orchestrator_tokens.py | 146 ++++++ tests/test_premise_check.py | 2 +- 14 files changed, 1383 insertions(+), 101 deletions(-) create mode 100644 tests/test_digest_counters.py create mode 100644 tests/test_orchestrator_mentions.py create mode 100644 tests/test_orchestrator_tokens.py diff --git a/AUTONOMY.md b/AUTONOMY.md index 80f94b12..5d08debc 100644 --- a/AUTONOMY.md +++ b/AUTONOMY.md @@ -771,6 +771,32 @@ the exemption it runs under is `PyAutoMind/policy/shift_watcher.md`). second issue comment in one shift — retires the watcher to fake mode until the cause is found and this section is re-approved. +**Amendment — 2026-11-12 (PyAutoBrain#610, #611).** The human ruled the +channel for a blocked worker on 2026-11-12: a GitHub @mention in a comment on +the shift's digest issue (GitHub mobile pushes it; no new credentials). The +watcher's comments on the brief's `issue:` are now, and only: + +- **the digest**, once per shift; +- **one mention per worker per state that needs the human** — a worker + `blocked` on a person past the stall grace (parked), or one that parked on + its issue with a question — @-mentioning the login set by + `PYAUTO_SHIFT_MENTION` or `config/policy.yaml` `shift_watcher: + mention_login:` (never written in code). Each counts as a push under "The + push-notification test" and in the digest's `pushes` counter; a crash, a + refusal, an obsolete premise or a finished worker waits for the digest; +- **one correction comment per shift**, when a worker arrives after + `review-at:` and the record and pilot row are amended. + +Each comment's marker is created exclusively **before** its post, so a crash +leaves no comment rather than two. A post `gh` says failed is retried on a +later tick, at most three tries in all; one that timed out may have landed and +is never retried. The watcher also reads `gh pr view --json +state,mergedAt,mergedBy` for the PRs its own workers named — the close-out's +merge truth (#603) and, once at `review-at:`, the digest's `merges` (#610). +The revert condition now reads: one network call outside these, or a comment +beyond these (a second digest, a second mention for the same worker and +state, a second correction), retires the watcher to fake mode. + ## Human override for Heart RED (development only) Heart RED still parks every autonomous run and blocks every release. After the diff --git a/agents/conductors/batch/AGENTS.md b/agents/conductors/batch/AGENTS.md index 36624b11..72b2c667 100644 --- a/agents/conductors/batch/AGENTS.md +++ b/agents/conductors/batch/AGENTS.md @@ -217,9 +217,18 @@ honoured by `--bg`). Each tick reads `claude agents --json --all` once: `working` → heartbeat; `blocked` (waiting on a person) → `stalled_since`, and after `STALL_GRACE_S` (15 min) the task is **parked** — never killed, never re-dispatched, named in the digest; `done` with the marker → released, without -it → crashed (re-dispatched once). A finished worker's tokens (input + output + -cache creation) are summed from its local transcript, named by the full -`sessionId`, and the brief's `token-budget:` refuses the next spawn once spent. +it → crashed (re-dispatched once). **Tokens (PyAutoBrain#610)** are read every +tick for every live, parked and close-out session from its local transcript +(named by the full `sessionId`): input, output and cache creation, once per +message id, with cache reads reported apart; each read **replaces** that +session's entry in `counters.json` `usage`, never adds. No transcript is +`None`, never 0: it keeps the last read and refuses the next spawn (`token usage +unavailable`). 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 +(`workers`: `spawned/finished`, `spawned/crashed`, `spawned/parked/late/finished`; +a failed launch is one `launch-failed` record per task) with its blocked minutes. `worker-mode:` defaults to `auto` (human, 2026-11-03); `dontAsk` and `acceptEdits` are allowed, `bypassPermissions` never. @@ -254,8 +263,14 @@ its `why:`, one proof packet per started task or a stub that says none was written, every counter) to `/digest.md`, appends it to the record through the one Mind writer, writes `digest.html` only under `packet: yes`, then **exclusive-creates `digest.posted` before** the one `gh issue comment` on the -brief's `issue:`. A crash between the two leaves no comment, never two; a failed -post is not retried; nothing is read back from GitHub. Health per PR is one +brief's `issue:`. A crash between the two leaves no comment, never two; a post +`gh` said failed is retried by a later tick, three tries in all (#610), and a +timed-out one never. It reaps first, so a `.done` written after the last live +tick is in the digest, and reads each worker PR's `gh pr view` once: `merges` +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 (`