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
52 changes: 51 additions & 1 deletion AUTONOMY.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,54 @@ writes use a separate bot or machine account's token, set by the human as
is set they post as the human's account and the digest warns that the
mention will not notify.

**Amendment — 2026-11-13 (PyAutoBrain#622), authorized by the human.** The
human approved the live shift view as drafted on 2026-11-13: a running shift
they can watch and steer from its digest issue. The watcher's network surface
gains, and only:

- **one status comment per shift** on the brief's `issue:`, created once and
from then on only **edited** in place: at most one edit a tick, when the
shift's state changes or every 10 minutes, and one last edit at
`review-at:` marking it closed. It shows the picks and workers with their
state, tokens against the budget, blocks and parks, refusals, time to
`review-at:` and every command with its acknowledgement. It never
@-mentions anyone, so an edit notifies nobody. Its marker is claimed
exclusively before the create, as above. A create `gh` said failed is made
again next tick. A create that timed out, or a claim whose tick died, is
never made again: the comments read adopts it by its hidden tag if it
landed, and only one written by the posting identity (`gh api user`, once
per shift) — that read runs for adoption even when no login is set. A
failed edit is retried next tick, and the tick carries on;
- **one read a tick of that issue's comments** (`gh api
repos/<owner>/<repo>/issues/<n>/comments`, one page, under the posting
token), for the steering commands;
- **the command set**, enacted from that read: `/pause` (spawns,
re-dispatches and new close-outs are held until `/resume`; reaps and
mentions continue), `/resume`, `/drop <task>` (a task of this shift only,
else "no such task in this shift"; a pick not yet spawned is never picked;
a running worker is not killed by the watcher: it is shown "dropped, still
running", never re-dispatched and its PR never merged unattended, and
stopping it stays the human's act, by hand; a close-out already running is
told to refuse by a `<task>.dropped` marker it checks just before merging,
and a merge that lands anyway is recorded as merged outside the close-out,
never counted and with no stage-2 row) and `/stop` (writes the `STOP`
kill-switch file, with exactly its effect: that tick commits nothing to
Mind, and its one status edit is the acknowledgement). A command
counts only when it is the first line of a comment by the login in
`PYAUTO_SHIFT_MENTION` or `config/policy.yaml` `shift_watcher:
mention_login:`, made after the brief's `dispatched:`. The status comment
is skipped by its tag and its id, so the watcher never reads its own text
as a command. Each comment is enacted once, by id, and acknowledged once, as
a line of the status comment, with no extra comment or reaction.

The dashboard shows the same status as a `- live:` line in the brief record,
written through the one Mind writer when the shift's state changes. That adds
no network act beyond the Mind push the writer already makes. The revert
condition now also covers a second status comment in one shift, more than
one comments read or one status write in a tick, and a command enacted from
any other login or enacted twice: any of these 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
Expand Down Expand Up @@ -1181,6 +1229,8 @@ Codex hook list.
- `batch` (the close-out session) — "Stage-2 adversary amendment" (2026-11-04):
the independent close-out session is the adversary leg, same model allowed.
- `batch` (the watcher) — "The watcher's network surface" (2026-11-03): what
the watcher may reach, and that it is opt-in, laptop-only and never writes.
the watcher may reach, and that it is opt-in, laptop-only and never writes;
amended 2026-11-12 (mentions, #611) and 2026-11-13 (the live status comment
and the steering commands, #622).

Skills must link here rather than copying the tables.
27 changes: 26 additions & 1 deletion agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,30 @@ trigger is durable state (a parked task or an issue-only `.done` with no
marker yet), so a tick that dies between parking and posting mentions on the
next; a failed mention is also retried by the late sweep.

**Watching and steering a shift from its issue (PyAutoBrain#622).** Each open
tick ends with the shift's **status comment** on the brief's `issue:`: the
`batch watch` snapshot as Markdown (`_watch.render_status`, no tick log),
created once (`<slot>/status.json` claimed before the create) and then only
edited, at most once a tick, when the state changes or every 10 minutes
(`STATUS_REFRESH_S`). A create that may have landed is never made again; the
comments read adopts it by its hidden tag. A failed edit is retried next tick.
After the reap, one `gh api …/comments` read takes the human's commands, each
the first line of a comment by `mention_login`, made after `dispatched:`:
`/pause` (spawns, re-dispatches, shadow proposals and new close-outs are held
until `/resume`; reaps and mentions continue), `/resume`, `/drop <task>` (a
task of this shift only, else "no such task in this shift"; `counters.json`
`dropped` plus a `leases/<task>.dropped` marker; never picked, never
re-dispatched, its PR refused for close-out; a close-out already running checks
the marker just before merging and refuses, and a merge that lands anyway is
recorded as merged outside the close-out, with no stage-2 row; a live worker is
shown `dropped, still running` and stopping it is the human's, `claude stop
<id>`) and `/stop` (writes `STOP`; that tick commits nothing to Mind). 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
the batch box. Doctrine: AUTONOMY.md watcher network surface, amendment
2026-11-13.

**The watcher's GitHub identity (human ruling 2026-11-12, #611).**
`PYAUTO_SHIFT_GH_TOKEN` holds a separate bot or machine account's token,
**fine-grained, PyAutoMind issues:write only**, set by the human in the
Expand Down Expand Up @@ -418,7 +442,8 @@ live shift 1 (2026-11-06) lost all three workers about 30 seconds after spawn
(`daemon-reload`). Separately, a worker or close-out whose `claude agents`
state is in `_digest.ENDED_STATES` (`failed`, `killed`, `error`, …) is reaped
at once, as a crash (worker, re-dispatched once) or a refusal (close-out),
never read as alive. To stop a shift, `touch <slot>/STOP`; to remove the
never read as alive. To stop a shift, `touch <slot>/STOP` (or comment `/stop` on
its issue); to remove the
watcher, `systemctl --user disable --now pyauto-orchestrator.timer`.

## Running
Expand Down
16 changes: 15 additions & 1 deletion agents/conductors/batch/_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,21 @@ def task_state(task: str, counters: dict, health, *, live: bool = False,
digest and `batch watch` share, so the live view and the digest never
disagree. Only the live view passes `live=True` (with the task's `lease`
and the `agents` view): at `review-at:` the watcher has already reaped
every lease, and the digest's wording stays exactly as it was."""
every lease, and the digest's wording stays exactly as it was. A task the
human dropped by `/drop` (PyAutoBrain#622) says so first."""
state, tiered = _task_state(task, counters, health, live=live, lease=lease,
agents=agents)
if task not in (counters.get("dropped") or {}):
return state, tiered
if live and lease is not None:
return f"dropped, still running — {state}", tiered
if state == "not started":
return "dropped by /drop — not started", False
return f"dropped by /drop — {state}", tiered


def _task_state(task: str, counters: dict, health, *, live: bool = False,
lease: dict | None = None, agents=None) -> tuple[str, bool]:
out = counters.get("outcomes", {}).get(task)
if counters.get("picks", {}).get(task, {}).get("proposed"):
return PROPOSED, True
Expand Down
43 changes: 42 additions & 1 deletion agents/conductors/batch/_mind_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{"op": "set-header", "path": "draft/a/b/x.md", "key": "Verified", "value": "2026-11-12 abc123 (Repo)"}
{"op": "jsonl-upsert", "path": "batches/pilot/pilot.jsonl", "key": "slot", "row": {...}}
{"op": "table-upsert", "path": "batches/pilot/pilot.md", "key": "<slot>", "row": "| … |", "header": "…"}
{"op": "record-key", "path": "batches/<slot>.md", "key": "live", "value": "…"}

`jsonl-upsert` keeps one JSON line per `row[key]`: the line with that key is
replaced (its other fields kept), else the row is appended. `table-upsert`
Expand All @@ -28,6 +29,11 @@
first into a missing file. Both are how the shift watcher writes its one pilot
row per shift and amends it on a late arrival (PyAutoBrain#610).

`record-key` sets one top-level `- key: value` line of a batch record — the
key's own line replaced, else inserted after `- issue:` (else `- review-at:`).
The watcher writes the dashboard's `- live:` status line this way
(PyAutoBrain#622); a record no longer on main is skipped, like `set-header`.

`set-header` sets one `Key: value` line in a prompt's header block (replacing
the key's line if present) — how a shift worker records the premise check's
`Verified:` stamp (`batch premise --record`) without touching the file itself.
Expand All @@ -48,7 +54,7 @@
from pathlib import Path

OPS = ("append", "write", "move", "remove", "drop-section", "table-append",
"set-header", "jsonl-upsert", "table-upsert")
"set-header", "jsonl-upsert", "table-upsert", "record-key")
PUSH_TRIES = 3
LEDGER_DIR = "ledger"
COMMITTED_DIR = "committed"
Expand Down Expand Up @@ -118,6 +124,14 @@ def validate_op(op: dict, lm) -> list[str]:
errs.append("table-upsert: row must be one `| … |` line")
elif _cells(row)[0] != op.get("key"):
errs.append("table-upsert: the row's first cell must be its key")
if kind == "record-key":
key, value, path = op.get("key"), op.get("value"), str(op.get("path", ""))
if not isinstance(key, str) or not re.fullmatch(r"[a-z][a-z0-9-]*", key):
errs.append("record-key: key must be one lower-case record key")
if not isinstance(value, str) or not value.strip() or "\n" in value:
errs.append("record-key: value must be one non-empty line")
if not (path.startswith("batches/") and path.endswith(".md")):
errs.append("record-key: path must be a batch record (batches/*.md)")
if kind == "set-header":
key, value = op.get("key"), op.get("value")
if not isinstance(key, str) or not re.fullmatch(r"[A-Z][A-Za-z-]*", key):
Expand Down Expand Up @@ -171,6 +185,11 @@ def apply_op(tree: Path, op: dict, lm) -> str | None:
f"since the check) — {op['key']}: skipped")
target.write_text(set_header(target.read_text(encoding="utf-8"),
op["key"], op["value"]), encoding="utf-8")
elif kind == "record-key":
if not target.exists():
return f"record-key: {op['path']} is not on main — {op['key']}: skipped"
target.write_text(record_key(target.read_text(encoding="utf-8"),
op["key"], op["value"]), encoding="utf-8")
elif kind == "table-append":
target.write_text(table_append(target.read_text(encoding="utf-8")
if target.exists() else "",
Expand All @@ -188,6 +207,28 @@ def apply_op(tree: Path, op: dict, lm) -> str | None:
encoding="utf-8")


def record_key(text: str, key: str, value: str,
after: tuple[str, ...] = ("issue", "review-at")) -> str:
"""`text` with one top-level `- key: value` line above the first `## `
heading: the key's line replaced if present, else inserted after the
first of `after` present, else after the title. Every other line is kept."""
lines = text.split("\n")
end = next((i for i, ln in enumerate(lines) if ln.startswith("## ")), len(lines))
new = f"- {key}: {value}"
for i in range(end):
if lines[i].startswith(f"- {key}:"):
lines[i] = new
return "\n".join(lines)
at = next((i + 1 for i, ln in enumerate(lines) if ln.startswith("# ")), 0)
for anchor in after:
hit = next((i for i in range(end) if lines[i].startswith(f"- {anchor}:")), None)
if hit is not None:
at = hit + 1
break
lines.insert(at, new)
return "\n".join(lines)


def table_append(text: str, heading: str, row: str) -> str:
"""`row` inserted after the last table line under the `## ` heading that
starts with `heading` — whatever follows that section stays where it is."""
Expand Down
Loading
Loading