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
4 changes: 3 additions & 1 deletion AUTONOMY.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,9 @@ not open.

**Human ruling 2026-11-16 (backlog reach, PyAutoBrain#637):** a `backlog:
scoped` dip takes `queue.md` first, then only `Difficulty: small` single-repo
backlog tasks; anything bigger must be queued by the human.
backlog tasks; anything bigger must be queued by the human. Narrowed
2026-11-19 (human, PyAutoBrain#696): queuing an epic ledger queues its
members, at the ledger's rank; phase order and every other gate still apply.

**Human rulings R5 and R2 — 2026-11-17 (M3.6b, PyAutoBrain#667).** R5
(option a): the one-slice-per-epic limit and phase order bind only tasks with
Expand Down
20 changes: 17 additions & 3 deletions agents/conductors/batch/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ priority. `retired`, `epic-slice` and `theme-sweep` entries are skipped rather
than resolved: resolving one is a decision (which phase? which chip?), and the
reader does not decide.

**A queued epic ledger queues its members** (PyAutoBrain#696). A `kind:
prompt` entry whose prompt is an epic ledger (`Epic:`, no `Phase:`, `Status:
campaign map`), or which `epics.md` lists as an epic's `- ledger:`, makes every
member of that epic count as queued at the ledger's rank (`queue_standing`, the
one test of "is this queued?"). So the backlog-reach ruling no longer keeps a
medium or multi-repo phase out. Every other gate still applies: phase order,
`human-required`, `Unattended:`, `Blocked-by:`, Witness, lane, repo holds and
budget. A queued phase or side task queues only itself. `batch plan` (text and
`--json` `queued_epics`), `brief --check` and the digest give one line per
queued epic: what it takes, or why nothing (its next phase and each member's
gate, or "no draft prompt" — file it from the epic's Continue prompt in an
attended chat).

`plan` also reports what the **previous slot carried**: the members its
`outcomes:` block marks `carried` are read first, because they are already
costing the human review-minutes in the slot being planned and a batch composed
Expand Down Expand Up @@ -199,8 +212,9 @@ whole grant (`AUTONOMY.md`, "Shift briefs and unattended `glance`").
`batch brief --new <YYYY-MM-DD-am|pm> --review-at <ISO>` composes that writing:
a skeleton brief whose `goals:` are `PyAutoMind/goals.md`'s, in order, with
`backlog: scoped` to their `epics:`/`tags:` (else `scoped` by `tiers: notify,
glance`, M3.6b) and
`merge-cap: 0`. It prints to stdout (`--out FILE` writes it) and never writes a
glance`, M3.6b), plus the epics of `queue.md`'s queued ledgers, `merge-cap: 0`,
and `lanes: any local-dev ral` with a `ral-allowance:` of 2 packets, partition
`ral`, 64 cpu-hours (PyAutoBrain#696; edit either per shift). It prints to stdout (`--out FILE` writes it) and never writes a
record into `batches/` — saving it there is the human's dispatch.
`goals.md` is written by the human alone (by hand or in chat), so every goal
is copied as their word; `--new` also prints on stderr how the goals changed
Expand Down Expand Up @@ -297,7 +311,7 @@ organ rule to it); a task an earlier shift in the same
home left parked on a question is not startable until a later shift finishes
it or a brief names it again; a dip never takes a Brain, Mind or Hands target;
a `backlog: scoped` dip beyond `queue.md` takes only small single-repo tasks
(ruling 2026-11-16); a re-dispatch goes first and may pass `max-sessions:` by
(ruling 2026-11-16; a queued epic ledger queues its members, #696); a re-dispatch goes first and may pass `max-sessions:` by
one; and a worker's token reservation is the larger of the even share and the
mean spend of finished workers in this and the last three shifts. State lives
under `$PYAUTO_ORCHESTRATOR_HOME` (default `.orchestrator` under the worktree
Expand Down
256 changes: 233 additions & 23 deletions agents/conductors/batch/_batch.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion agents/conductors/batch/_brief.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ def rank_note(record: dict) -> str:
(M2.3, 2026-11-12), then the path — so a tie is alphabetical, and says so."""
parts = []
if record.get("queued"):
parts.append(f"queue.md #{record['queue_rank'] + 1}")
parts.append(f"queue.md #{record['queue_rank'] + 1}"
+ (f" via epic {record['queued_via']}" if record.get("queued_via") else ""))
elif "queue_rank" in record:
parts.append("not in queue.md")
parts.append(f"priority {record.get('priority') or 'normal'}")
Expand Down
7 changes: 7 additions & 0 deletions agents/conductors/batch/_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,13 @@ def names(paths):
if reach:
out.append(f"Backlog reach (ruling 2026-11-16): {len(reach)} unqueued draft(s) not "
"dipped — beyond queue.md only small single-repo tasks: " + names(reach))
# One line per queued epic ledger (#696): what it gave the shift, or why
# nothing. `· ` rather than an indent: an indented line would read as the
# continuation of the pick above it.
epics = gates.get("queued_epics") or []
if epics:
out.append("Queued epics:")
out += [f"· {line}" for line in epics]
absent = gates.get("lane_absent") or []
if absent:
out.append(f"Lane absent: {len(absent)} draft(s) excluded — no valid `Lane:`, "
Expand Down
15 changes: 13 additions & 2 deletions agents/conductors/batch/_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,7 @@ def plan() -> dict:
recs = recs + [a["record"] for a in (counters.get("added") or {}).values()
if isinstance(a.get("record"), dict)
and a["record"].get("path") not in have]
surveyed = list(recs)
# Parked on a question by an earlier shift (#637, item 3): not
# startable until answered. A brief that names it again is the
# human's word that it is; a task this shift picked stays. Read
Expand Down Expand Up @@ -2220,8 +2221,16 @@ def plan() -> dict:
# Unattended by construction: an absent Lane is excluded and an
# empty queue.md stops the backlog dip (M2.3, AUTONOMY.md "M2
# rulings — 2026-11-12"). Recorded each tick so the digest can say so.
# Kept out above, with why: read only by the queued-epic lines (#696).
kept = {r["path"] for r in recs}
why_out = {**planned["parked"], **(claimed or {})}
withheld = [(r, why_out.get(r["path"], "kept out before planning "
"(carried or resumed elsewhere)"))
for r in surveyed if r["path"] not in kept]
planned["d"] = _batch.plan(recs, session_lane="local-dev", brief=brief,
queue=_batch.read_queue(mind), released=freed)
queue=_batch.read_queue(mind), released=freed,
epic_ledgers=_batch.read_epic_ledgers(mind),
withheld=withheld)
return planned["d"]

def known(task: str) -> bool:
Expand Down Expand Up @@ -2291,7 +2300,9 @@ def known(task: str) -> bool:
# digest's "Not started" reason), and the backlog
# drafts kept out for want of a `Witness:`.
"named": _named_reasons(brief, d, planned),
"witness_absent": sorted(d.get("witness_absent") or [])}
"witness_absent": sorted(d.get("witness_absent") or []),
# #696: one line per queued epic ledger.
"queued_epics": _batch.queued_epic_lines(d)}
paused = bool(counters.get("paused"))
if _brief.is_shadow(brief):
proposed = [] if paused else _propose(
Expand Down
6 changes: 3 additions & 3 deletions agents/conductors/batch/_ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def epic_members(mind: Path, epic: str) -> list[dict]:
def is_ledger(text: str) -> bool:
"""An epic ledger: `Status: campaign map` with `Epic:` and no `Phase:`
(as intake's `_shipped` reads a map). A side task of an epic (`Epic:`, no
`Phase:`, any other status) is an ordinary prompt."""
return bool(_batch._epic_of(text)) and not _batch._phase_declared(text) \
and _batch._header_of(text, "status").lower().startswith("campaign map")
`Phase:`, any other status) is an ordinary prompt. The planner's own
test (`_batch.is_ledger_text`), so both read a ledger alike."""
return _batch.is_ledger_text(text)


def origin_epic_members(mind: Path, epic: str, ref: str = "origin/main") -> list[dict] | None:
Expand Down
2 changes: 1 addition & 1 deletion skills/batch/batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Resolve it to prompt paths; plan exactly that set as a brief's named tasks, or
its named tasks go first, then the backlog dip its policy allows (`none` |
`fill-idle` | `scoped:` plus `exclude:`). Backlog the brief does not cover is
never dipped, and every dipped pick carries a one-line reason in the digest.
`brief --check` says why any named task will not start (AUTONOMY.md, R5 and R2).
`brief --check` says why any named task will not start (AUTONOMY.md, R5 and R2); a queued epic ledger queues its members (#696), and plan, check and digest say per epic why it is idle.
Report, per task they named:

- **taken** — with its tier and review-minutes;
Expand Down
4 changes: 4 additions & 0 deletions skills/queue/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ in one line and ask for the path. Never work around it by editing the file.
`remove` moves the entry to `## Retired` with `shelved-as:` and keeps its
note. The prompt itself stays in `draft/`.

Adding an epic's ledger queues the whole epic (PyAutoBrain#696): a shift then
takes its next phase at the ledger's rank, under every other gate. Adding one
phase prompt queues only that phase.

`show` writes nothing: run it in a fresh worktree (steps 1, 2 and 5 below)
and skip the commit, so it reads `origin/main`, not a stale checkout.

Expand Down
60 changes: 60 additions & 0 deletions tests/test_batch_brief_goals.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,63 @@ def test_goals_are_copied_as_written_with_or_without_git(tmp_path):
assert [c["text"] for c in _brief.parse(text)["brief"]["goals"]["children"]] == [
"1. Land the flywheel rework", "2. Clear review-ready PRs"]
assert "# - " not in text


# --- RAL by default, and queued epics in scope (PyAutoBrain#696) ------------

LEDGER_TEXT = """# Widgets epic

Type: feature
Target: widgets
Difficulty: too-large
Autonomy: human-required
Status: campaign map — phases route one at a time
Epic: widgets
Lane: local-dev
"""
QUEUE_TEXT = """# Queue

## 1. Widgets epic
- kind: prompt
- ref: draft/feature/x/widgets_epic.md
"""


def test_an_unedited_new_brief_allows_ral_and_passes_check(tmp_path, capsys):
"""The Witness, part (a): `brief --new` writes `ral` into `lanes:` with a
`ral-allowance:` block, and `brief --check` passes it as written."""
mind = _mind(tmp_path, "# Goals\n\n## 1. Ship it\n")
out = tmp_path / "brief.md"
assert _batch.main(["brief", "--new", "2026-11-14-am", "--review-at",
"2099-01-01T12:00Z", "--mind", str(mind), "--out", str(out),
"--issue", "https://github.com/example-org/PyAutoMind/issues/1"]) == 0
text = out.read_text()
brief = _brief.parse(text)["brief"]
assert "ral" in _brief.lanes_of(brief)
allow = _brief._keyed(brief["ral-allowance"]["children"])
assert {k: v["value"] for k, v in allow.items()} == {
"packets": "2", "partition": "ral", "cpu-hours": "64"}
assert _brief.check(out, mind)["ok"]
capsys.readouterr()
assert _batch.main(["brief", "--check", str(out), "--mind", str(mind),
"--no-premise"]) == 0


def test_new_puts_queued_epics_in_scope_and_check_says_why_one_is_idle(tmp_path, capsys):
"""A queued epic ledger queues its phases, so `brief --new` scopes the
brief to its epic beside the default tiers, and `brief --check` warns,
one line per queued epic, why nothing of it starts."""
mind = _mind(tmp_path, "# Goals\n\n## 1. Ship it\n")
(mind / "draft" / "feature" / "x" / "widgets_epic.md").write_text(LEDGER_TEXT)
(mind / "queue.md").write_text(QUEUE_TEXT)
text = _batch.new_brief(mind, "2026-11-14-am", "2099-01-01T12:00Z",
issue="https://github.com/example-org/PyAutoMind/issues/1")
scoped = _brief.scoped_of(_brief.parse(text)["brief"])
assert scoped == {"tiers": ["notify", "glance"], "epics": ["widgets"]}
out = tmp_path / "brief.md"
out.write_text(text)
assert _batch.main(["brief", "--check", str(out), "--mind", str(mind),
"--no-premise"]) == 0
printed = capsys.readouterr().out
assert ("! queued epic widgets (q1): nothing — no draft prompt for its next "
"phase") in printed
128 changes: 128 additions & 0 deletions tests/test_batch_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,131 @@ def test_carried_members_are_reported_to_the_next_plan():
carried_from="2026-09-03-pm")
assert d["carried"] == ["subhalo-wave"]
assert d["carried_from"] == "2026-09-03-pm"


# ------------------------------------- a queued epic queues its phases (#696) --
EPIC_BRIEF = """# Batch 2026-11-20 am
- dispatched: 2026-11-20T08:00Z
- review-at: 2026-11-20T12:00Z
- brief:
- goals:
- 1. drive the queued epics
- backlog: scoped
- scoped:
- epics: lib
- tiers: notify, glance
- review-minutes: 200
- lanes: any local-dev ral
- merge-cap: 0
- token-budget: 5000000
"""
LEDGER = "draft/feature/lib/lib_epic.md"


def _brief_of(text=EPIC_BRIEF):
return _batch._brief.parse(text)["brief"]


def ledger(path=LEDGER, epic="lib"):
r = rec(path, epic=epic, autonomy="human-required")
r.update(ledger=bool(epic), phase_declared=False, witness="the map")
return r


def member(path, phase, *, epic="lib", repos=("autofit", "autolens"), **kw):
r = rec(path, epic=epic, phase=phase, repos=repos, **kw)
r.update(phase_declared=True, witness="a fixture passes")
return r


def test_a_queued_epic_ledger_queues_its_medium_multi_repo_phase():
"""Ruling 2026-11-16 narrowed (#696): the human queuing an epic ledger is
the human queuing its phases. The medium 2-repo next phase is taken at the
ledger's rank, with no scoped-reach rejection."""
other = rec("draft/x/queued_first.md", repos=["autoarray"])
other["witness"] = "w"
d = _batch.plan([ledger(), member("draft/feature/lib/p5c.md", 5), other],
budget=200, session_lane="local-dev", brief=_brief_of(),
queue=["draft/x/queued_first.md", LEDGER])
assert "draft/feature/lib/p5c.md" in paths(d)
m = next(m for m in d["members"] if m["path"] == "draft/feature/lib/p5c.md")
assert m["queue_rank"] == 1 and m["queued"] and m["queued_via"] == "lib"
assert d["scoped_reach"] == []
assert "via epic lib" in _batch._brief.rank_note(m)
assert [e["line"] for e in d["queued_epics"]] == ["lib (q2): takes p5c"]


def test_an_unqueued_epic_member_is_still_held_to_the_reach_ruling():
d = _batch.plan([ledger(), member("draft/feature/lib/p5c.md", 5)],
budget=200, session_lane="local-dev", brief=_brief_of(), queue=["x.md"])
assert "ruling 2026-11-16" in why(d, "draft/feature/lib/p5c.md")


def test_a_queued_epic_still_offers_only_its_next_phase():
d = _batch.plan([ledger(), member("draft/feature/lib/p5.md", 5),
member("draft/feature/lib/p6.md", 6)],
budget=200, session_lane="local-dev", brief=_brief_of(), queue=[LEDGER])
assert paths(d) == ["draft/feature/lib/p5.md"]
assert why(d, "draft/feature/lib/p6.md") == "epic lib phase 6 is not next"
# The ledger itself is never a member: it is human-required.
assert "human-required" in why(d, LEDGER)


def test_epics_md_maps_a_ledger_whose_epic_header_was_not_read(tmp_path):
(tmp_path / "epics.md").write_text(
"# Epics\n\n## lib\n- title: L\n- ledger: draft/feature/lib/lib_epic.md\n"
"## web\n- ledger: https://example.invalid/x.md\n", encoding="utf-8")
ledgers = _batch.read_epic_ledgers(tmp_path)
assert ledgers == {LEDGER: "lib"}
plain = ledger(epic="")
assert _batch.queued_epics([LEDGER], [plain], ledgers) == {"lib": 0}
assert _batch.queued_epics([LEDGER], [plain]) == {}
# A queued phase prompt queues only itself, not its epic.
assert _batch.queued_epics(["draft/feature/lib/p5.md"],
[member("draft/feature/lib/p5.md", 5)]) == {}


def test_a_queued_epic_with_no_draft_phase_says_to_file_one():
d = _batch.plan([ledger()], budget=200, session_lane="local-dev",
brief=_brief_of(), queue=[LEDGER])
(line,) = _batch.queued_epic_lines(d)
assert line.startswith("lib (q1): nothing — no draft prompt for its next phase")
assert "Continue prompt in an attended chat" in line


def test_a_queued_epic_whose_next_phase_is_human_required_names_the_gate():
d = _batch.plan([ledger(),
member("draft/feature/lib/p2a.md", 2, autonomy="human-required"),
member("draft/feature/lib/p2b.md", 2, autonomy="human-required"),
member("draft/feature/lib/p3.md", 3)],
budget=200, session_lane="local-dev", brief=_brief_of(), queue=[LEDGER])
assert paths(d) == []
(e,) = d["queued_epics"]
assert e["next_phase"] == "2" and not e["taken"]
assert e["line"] == ("lib (q1): nothing — next phase 2: "
"p2a (autonomy human-required); p2b (autonomy human-required)")
assert e["members"][0]["why"] == "autonomy human-required — would park at ship"


def test_a_held_lower_phase_still_blocks_the_next_one():
"""A phase the caller kept out before planning (claimed on Mind
origin/main, parked) is still open: the phase after it is not next."""
p4 = member("draft/feature/lib/p4.md", 4)
d = _batch.plan([ledger(), member("draft/feature/lib/p5.md", 5)], budget=200,
session_lane="local-dev", brief=_brief_of(), queue=[LEDGER],
withheld=[(p4, "repo autofit claimed by `x` in active.md")])
assert paths(d) == []
assert why(d, "draft/feature/lib/p5.md") == "epic lib phase 5 is not next"
(line,) = _batch.queued_epic_lines(d)
assert line == "lib (q1): nothing — next phase 4: p4 (repo autofit claimed by `x` in active.md)"


def test_the_plan_text_and_json_carry_the_queued_epics(capsys):
d = _batch.plan([ledger()], budget=200, session_lane="local-dev",
brief=_brief_of(), queue=[LEDGER])
_batch.emit(d)
out = capsys.readouterr().out
assert "Queued epics:\n lib (q1): nothing" in out
assert out.index("Queued epics:") < out.index("Not selected:")
import json
assert json.loads(json.dumps(d))["queued_epics"][0]["epic"] == "lib"
14 changes: 14 additions & 0 deletions tests/test_digest_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,17 @@ def test_refusals_are_one_entry_per_task_and_reason_class(tmp_path):
_digest.note_refusals(old, [{"task": "a", "why": "token-budget 400000 spent (3)"}],
"2026-11-16T13:05:00Z")
assert len(old["refusals"]) == 2 and "3× from" in _digest.refusal_lines(old)[0]


def test_the_digest_says_per_queued_epic_what_it_gave_or_why_not():
"""PyAutoBrain#696: one line per queued epic ledger under the backlog
picks, never read as the continuation of the pick above it."""
lines = _digest.backlog_gate_lines({"backlog_gates": {"queued_epics": [
"lib (q1): takes p5c",
"cti (q2): nothing — next phase 2: p2a (autonomy human-required — would park at ship)"]}})
assert lines[1:] == ["Queued epics:", "· lib (q1): takes p5c",
"· cti (q2): nothing — next phase 2: p2a (autonomy "
"human-required — would park at ship)"]
section = ["- `a-pick` — why: scoped epic lib · queue.md #1 via epic lib"] + lines
(item,) = _digest._items(section)
assert "Queued epics" not in item
Loading