Skip to content

feat: batch collect --integration — one merged worktree root per review slot - #338

Merged
Jammy2211 merged 6 commits into
mainfrom
feature/batch-review-integration
Sep 2, 2026
Merged

Jammy2211 merged 6 commits into
mainfrom
feature/batch-review-integration

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Summary

Closes #337. The batch review packet lets the human rule on each member but not run the batch together. This adds an opt-in, laptop-only batch collect --integration leg: one throwaway worktree root per slot (~/Code/PyAutoLabs-wt/integration-<slot>/, built by the existing worktree_create, so activate.sh + PYTHONPATH + cache dirs come for free), with integration/<slot> per affected repo cut from origin/main and every member's PR head merged in dispatch order. A member whose merge conflicts is left out and named with the conflicting paths — that report is the answer to "how would this resolve at the end", not a failure (exit code unchanged). Nothing is pushed, no PR is opened, no remote ref is touched; pushing (--push, sweep expiry) is a deferred phase 3.

Phase 1 first makes the member → (repo, branch) map reliable: the batch record stores no branch per member and active.md's repos: field has four dialects, so the evidence JSON now records each PR's head_ref / head_sha / head_repo from gh.

Also fixes a pre-existing break found by the end-to-end smoke: GH_FIELDS asked gh pr view --json for merged, which is not a field — gh fails the whole request, so every --fetch scored UNOBSERVABLE. Now mergedAt, with merged derived.

API Changes

  • pyauto-brain batch collect --integration (new flag, collect-only; also triggered by a - integration: yes line in the batch record at dispatch). Refuses non-local-dev lanes with a pointer, like --fetch.
  • Evidence JSON PR rows gain head_ref, head_sha, head_repo; --json output and a pasted evidence doc gain a top-level integration block; collect never rewrites the --evidence file.
  • Packet: a sentinel-bounded integration region (sentinels always emitted; body only when a block exists, so refreshes never blank it). Report: ## Integration branches with the source <root>/activate.sh line first. Record: - integration-root: stamp (the human's - integration: yes survives).
  • bin/worktree.sh: PYAUTO_WT_BRANCH overrides the per-task branch name (default unchanged: feature/<task>).
  • New network leg in the Brain: git fetch origin (read-only), opt-in, documented in the batch AGENTS.md beside --fetch.
    See full details below.

Test Plan

  • tests/test_batch_integration.py (19 tests) — temp bare origin + clone, two members on the same file: alpha merged, beta left out with paths == ["a.py"], canonical checkout untouched (the prompt's Witness); clean multi-member; idempotent re-run (same tree); dirty worktree skipped; fork / merged / missing-head reported not merged; root has activate.sh + symlinks; branch override; packet region sentinelled + escaped; refresh preserves region; cloud lane pointer; record integration: yes triggers; apply stamps integration-root; plan --integration → rc 2.
  • tests/test_batch_collect.py — head fields in the --json argv and the row; null owner → ""; mergedAt → merged.
  • Full Brain suite: 815 passed; 1 pre-existing failure (test_cortex_conductor.py::test_a_fixture_tree_finds_the_schema_its_checkout_ships) that only fails inside a task worktree where PyAutoCortex is a symlink — passes on the canonical checkout, untouched here.
  • Laptop smoke on real repos: collect --slot 2026-08-31-pm --fetch --integration (all PRs merged → nothing to integrate, no root built); with an evidence file naming four unmerged branches → PyAutoFit clean, PyAutoArray one merged + two conflicted with paths listed; second run reproduced identical trees; root and integration/* branches removed afterwards, canonical repos on main and clean.
Full API Changes (for automation & release notes)

Added

  • agents/conductors/batch/_integration.py — stdlib-only, loaded lazily by _batch.load_integration(): plan_jobs(members, order, notes), ensure_root(slot, repo_dirs, notes), integrate_repo(job, wt, slot, notes), run(members, order, slot, *, lane).
  • _batch.py: _head_of(data, repo), _yes(values), load_evidence_doc(path), _integration_panel(d), _integration_report(d); collect() returns dispatch_order and integration_requested; --integration in COLLECT_ONLY + argparse; record_update writes integration-root.
  • GH_FIELDS += headRefName,headRefOid,headRepository,headRepositoryOwner; merged → mergedAt.
  • packet.css: ul.integ rules. No packet.js change.
  • bin/worktree.sh: PYAUTO_WT_BRANCH.
  • Docs: batch AGENTS.md (Running, constraints row, "Integration branches (--integration)", evidence keys, network sentence), batch.sh usage, skills/batch/batch.md ("I want to run the whole batch").

Removed

  • none

Migration

  • none; every flag and key is opt-in and additive. Companion doc PR in PyAutoMind adds the - integration: yes / - integration-root: record keys to batches/AGENTS.md.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP

Jammy2211 and others added 6 commits September 2, 2026 12:59
A batch record names members, never branches, and `active.md`'s PR field has
four spellings — so a PR's own head is the only reliable member -> (repo,
branch) map. `gh pr view` is now asked for `headRefName`/`headRefOid`/
`headRepository`/`headRepositoryOwner`, and `_head_of` splices `head_ref`,
`head_sha` and `head_repo` onto every PR row. A fork or a deleted head repo
reports an empty `head_repo` rather than being guessed as `origin`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP
`_worktree_add_one` hardcoded `feature/$task`, so every root worktree.sh builds
claims to be feature work. The batch conductor's forthcoming
`collect --integration` needs a throwaway review root named
`integration/<slot>` instead — the one thing the helper could not say. The
override is additive: unset, nothing changes, which the second test pins.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP
…ree (#337)

One throwaway worktree root per slot: every member's head branch merged into
`integration/<slot>`, per repo, off `origin/main`, so the human can RUN the
whole batch before ruling on any of it — and so "how would these resolve at the
end?" is answered by a merge rather than by reading diffs.

Three properties, deliberately. It writes no remote: `git fetch origin` and
local merges, no push and no PR. It resolves nothing: a member whose merge
conflicts is left OUT and named with the conflicting paths, and that report is
the product. And it is stdlib-only, importing nothing from `_batch`, so the
conductor can load it lazily and this suite can drive it against throwaway
repos with no Mind, no record and no packet in sight.

The seam with `bin/worktree.sh` is that worktree.sh knows LAYOUT and this
module knows MERGES. The root is built by shelling to `worktree_create` with
`PYAUTO_WT_BRANCH=integration/<slot>`, because the value of that function is
activate.sh's PYTHONPATH, the per-task caches and the symlink of every other
top-level entry — re-deriving it here would fork the definition of "a PyAuto
worktree root" into two places that would drift. The merges are plain git,
because a shell helper would bury the exit code and the unmerged-path list the
report needs.

The branch is re-cut from `origin/main` every run: the merge result is a
function of the current base and the current heads, so a second run that
stacked onto the first would preview a base that no longer exists. That is only
safe because a dirty integration worktree is refused outright — that refusal,
not the branch policy, is the safety property, and it is what the re-run and
dirty-worktree tests pin.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP
…amp (#337)

`collect --integration` (or `- integration: yes` written into the record at
dispatch) runs the merge leg and reports it in the three places collect already
owns: the terminal report, the packet page, and the record's stamps.

`collect()` now exposes `dispatch_order` — `d["members"]` is sorted by HEALTH,
so it cannot drive a merge order, and the order the human listed the members in
is the order the preview must merge them in. It also exposes
`integration_requested`, read through a `_yes` helper from the record key.

`load_evidence_doc` returns the whole evidence document alongside
`load_evidence`'s members, because `integration` is slot-level rather than per
member — a laptop's block pasted into a cloud session is how a non-laptop
surface renders one at all. Collect deliberately does NOT rewrite the human's
`--evidence` file: that file is an input, `--apply` writes exactly the packet
and the record, and persisting the block is `--json > ev.json`'s job.

The report puts the `source <root>/activate.sh` line at the TOP, right after
the NOT-DELIVERED lede: the whole point of the leg is that the human can run
the batch, and a source line five screens down is a line nobody sources. The
packet's `pyauto:integration` sentinels ship even when the body is empty, so a
later `--integration` refresh has somewhere to splice into, while the region is
only re-rendered when this collect HAS a block — a plain refresh must not blank
a preview that is still true. The panel carries no `data-*` hook and no second
`<script>`: there is nothing to rule about a merge preview.

`- integration-root:` is a separate key from the dispatch-time
`- integration: yes`. That line is the human's request; overwriting it with a
path would erase what they asked for and leave only what happened.

Conflicts move no exit code and no member's health word. A member's health is
about its own delivery; a merge collision is a property of the slot, and mixing
them would make a green member read as SUSPECT because a sibling touched the
same file.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP
The conductor's AGENTS.md gains a constraints row, a `## Running` line and an
"Integration branches (`--integration`)" subsection: the block's JSON shape,
the four skip reasons (merged, closed, fork, no `head_ref`), the dirty-worktree
refusal, the re-cut policy and why the refusal rather than the policy is the
safety property, and that conflicts change no exit code and no member's health
word.

The network line is said out loud, because `AUTONOMY.md`'s "the Brain reads no
network except one opt-in flag" predates this one: `--integration` fetches and
reads; it never pushes, opens a PR, or touches a remote ref. Like `--fetch` it
is opt-in, non-default and laptop-only, and pushing `integration/<slot>` is a
separate, later decision.

Also documented so the next session does not "fix" it: **collect does not
rewrite your `--evidence` file.** That file is an input; persisting the block is
`--json > ev.json`'s job, and a block pasted back into an evidence file is how a
cloud session renders one at all.

The skill says where a member has to be RUN — a library change is live anywhere
once `activate.sh` is sourced, a workspace member's script must be run from
inside `<root>/<workspace>` — and adds the dispatch-time line: if the human says
they will want to run the batch, write `- integration: yes` into the record.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP
`gh pr view --json merged` does not drop an unknown name, it rejects the WHOLE
request: "Unknown JSON field: merged" (gh 2.98). So one wrong word in
`GH_FIELDS` made every PR of every `--fetch` exit 1 and be scored
UNOBSERVABLE — and the report blamed the PRs, not the field list. Found driving
the `--integration` smoke, which cannot run without a working `--fetch`.

`mergedAt` is the same fact and is a real field; the evidence row's `merged`
stays a bool, derived from it, so nothing downstream changes shape.

Pinned by a test that asserts both halves — that `mergedAt` is asked for and
that no bare `merged,` remains in the field list — because the failure mode is
silent at the call site and only visible as a note about a PR.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: batch collect --integration — one merged worktree root per review slot

1 participant