Skip to content

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

Closed

Description

@Jammy2211

Overview

The batch review packet lets a human rule on each member, but it gives them no way to run the batch — checking out "everything in the review" today means hand-checking-out several PR branches across several repos. This adds an opt-in batch collect --integration leg that builds one throwaway worktree root per review slot, with integration/<slot> cut fresh from origin/main per repo and every member's head branch merged in dispatch order, reporting clean/conflicted (with the colliding paths and member) per repo in the packet, the report and the record. Phase 1 first records each PR's head branch in the evidence JSON, which is the authoritative member → (repo, branch) map; phase 3 (--push, integration/* sweep expiry) is deferred to a later prompt — nothing here pushes, names a remote branch, or resolves a conflict.

Plan

  • Phase 1 — evidence carries the head branch. Widen GH_FIELDS with headRefName,headRefOid,headRepository,headRepositoryOwner, add a _head_of helper, and splice head_ref/head_sha/head_repo into every PR row in fetch_evidence. Unknown heads are reported empty, never guessed as origin.
  • One override in bin/worktree.sh (PYAUTO_WT_BRANCH, default feature/$task) so the batch root reuses worktree_create — and with it the root layout (activate.sh PYTHONPATH, per-task NUMBA_CACHE_DIR/MPLCONFIGDIR, symlinks) — under branch integration/<slot> instead of forking the definition of "a PyAuto worktree root".
  • New stdlib-only _integration.py, loaded lazily like load_cortex_conductor, owning the merges: plan jobs by repo in dispatch order (skipping merged / closed / fork / no-head members with a note), ensure the root idempotently, then per repo cut integration/<slot> from origin/main and merge --no-ff each member's head.
  • A conflicting member is left out and named, never resolved by the agent: capture diff --name-only --diff-filter=U before merge --abort, then continue with the next member. Conflicts are the product — they do not change the exit code and do not touch any member's health word.
  • Opt-in, laptop-only, local. --integration on collect, or - integration: yes in the batch record at dispatch; non-local-dev lanes get a pointer, exactly like the existing --fetch leg. The only new network is git fetch origin; nothing is pushed.
  • Safety property is the dirty-worktree refusal, not branch policy: the local branch is re-cut with checkout -B every run (the preview is a function of current main + heads), but a worktree with uncommitted changes is skipped and said so in the packet.
  • Artifacts: a sentinel-bounded integration packet region (always emitted, only re-rendered when a block exists, so a plain refresh cannot blank it), an "Integration branches" report section leading with the copy-paste source <root>/activate.sh line, and an - integration-root: record stamp that leaves the human's - integration: yes request line intact.
  • Docs + 13 tests, including the prompt's Witness (two members, one conflicting, in a temp bare-origin workspace).
Detailed implementation plan

Affected Repositories

  • PyAutoBrain (primary)
  • PyAutoMind (batches/AGENTS.md record schema)

Branch Survey

Repository Current Branch Dirty?
./PyAutoBrain main clean
./PyAutoMind main epics.md (concurrent session)

Suggested branch: feature/batch-review-integration
Worktree: ~/Code/PyAutoLabs-wt/batch-review-integration/
Claim note: PyAutoBrain also claimed by organ-board-github-link (PR #326, board/Pages files only) — disjoint files, parallel worktree approved.

Implementation Steps

Phase 1 — record member → (repo, branch) in the evidence

1.1 _batch.py GH_FIELDS (:619): add headRefName,headRefOid,headRepository,headRepositoryOwner, with a comment that these four are the authoritative member → (repo, branch) map phase 2 drives from, and that the head repo is recorded because a fork's head is not on origin.
1.2 New _head_of(data, repo) -> dict beside _checks_from_rollup (
:636): returns {"head_ref", "head_sha", "head_repo"}, tolerating None/non-dict headRepository/headRepositoryOwner; head_repo falls back to "" (never to repo) so a caller can tell "same repo" from "unknown".
1.3 fetch_evidence (:706-716): add **_head_of(data, repo) to the appended PR row. No other change; still writes nothing.
1.4 Doc agents/conductors/batch/AGENTS.md "The evidence JSON" (
:290): extend the jsonc PR object with the three keys plus one sentence on why (active.md's repos: field has four dialects; the PR's own head is the only reliable source; a head_repo != repo is a fork).
1.5 Test in tests/test_batch_collect.py: fake gh, assert the --json argv names headRefName and the row carries head_ref/head_sha/head_repo; null owner → "". Extend the shared pr() fixture with the three head keys.

Phase 2 — batch collect --integration

2.1 bin/worktree.sh _worktree_add_one (:84): local branch="${PYAUTO_WT_BRANCH:-feature/$task}", used in the worktree_add_repo echo too; documented in the header block. Backwards-compatible — unset, nothing changes.
2.2 New agents/conductors/batch/_integration.py (stdlib only, no _batch import, loaded lazily): workspace_root / task_name / branch_name / root_for, _git (GIT_TERMINAL_PROMPT=0, never raises), plan_jobs, ensure_root, integrate_repo, run. plan_jobs groups member PRs by repo in dispatch order and notes-and-skips merged / closed / fork-head / missing-head_ref / no-local-checkout. integrate_repo: merge --abort (stale run) → refuse dirty worktree → fetch origin → checkout -B integration/<slot> origin/main → per member merge --no-ff --no-edit origin/<head>; on conflict capture unmerged paths then merge --abort and continue. run(members, order, slot, *, lane) refuses non-local-dev lanes with a pointer and returns the block + notes.
2.3 load_evidence_doc(path) beside load_evidence — the whole evidence document, because integration is slot-level, not per member (and a laptop 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 is --json > ev.json's job, documented so nobody "fixes" it.
2.4 collect() (
:1079-1158): return dispatch_order (record order, not the health-sorted members) and integration_requested (via a small _yes() helper near _dash).
2.5 CLI: add "integration" to COLLECT_ONLY (so plan --integration is the usage error it should be) and an --integration store_true beside --fetch; _main_collect runs the leg when flagged or record-requested, else renders a pasted block from the evidence wrapper. --lane honoured. Exit codes unchanged.
2.6 collect_report: new _integration_report(d) inserted right after the NOT-DELIVERED lede so the source <root>/activate.sh line is at the top of a terminal run, then one line per repo (clean / conflicted with the colliding member and paths).
2.7 Packet: new _integration_panel(d) beside _rulings, every value through _e, no <script>; _fresh_packet always emits the pyauto:integration:begin/end sentinels (even empty) and packet_html appends the region only when a block exists, so a plain refresh cannot blank it.
2.8 record_update: after the packet line, stamp - integration-root: <root> — <branch>; N clean, M conflicted as a separate key — the dispatch-time - integration: yes is the human's request and must survive verbatim.
2.9 packet.css: three ul.integ rules mirroring ol.rulings; reuse .panel / .chip-healthy / .chip-failed. No packet.js change (the panel holds no review control).
2.10 Docs: batch AGENTS.md (Running line, constraints row, new "Integration branches" subsection, the git fetch/never-push sentence, the idempotence rationale), batch.sh usage, skills/batch/batch.md (dispatch line + "I want to run the whole batch" bullet), and PyAutoMind batches/AGENTS.md (- integration: yes / - integration-root: schema + the "easy to get wrong" paragraph).
2.11 Tests tests/test_batch_integration.py (13, on a temp bare-origin workspace with feature/alpha, conflicting feature/beta, clean feature/gamma): the Witness (alpha merged, beta left out with paths == ["a.py"], canonical checkout untouched), clean multi-member, re-run idempotent, dirty worktree skipped, fork/merged/missing-head reported, root carries activate.sh + symlinks, branch override honoured (and no regression without it), packet region sentinelled + escaped, refresh preserves the region, cloud lane pointer, record integration: yes triggers, apply stamps integration-root, plan --integration → rc 2.
2.12 Verify: python3 -m pytest -q -n auto PyAutoBrain/tests, then a manual laptop smoke pyauto-brain batch collect --slot <slot> --fetch --integration (no --apply, no remote writes) and inspect the root's git log.

Commit sequencing: (1) phase 1 + its test; (2) worktree.sh override + its test; (3) _integration.py + unit tests; (4) _batch.py wiring + packet.css; (5) docs (PyAutoMind batches/AGENTS.md rides its own PR, being the second repo on the prompt's Repos:).

Key Files

  • agents/conductors/batch/_batch.py — GH_FIELDS, _head_of, collect(), CLI, report, packet region, record stamp
  • agents/conductors/batch/_integration.py — NEW: plan_jobs / ensure_root / integrate_repo / run
  • bin/worktree.sh — PYAUTO_WT_BRANCH override
  • agents/conductors/batch/packet.css — ul.integ
  • agents/conductors/batch/AGENTS.md, batch.sh, skills/batch/batch.md — docs
  • tests/test_batch_integration.py — NEW; tests/test_batch_collect.py — head-field test
  • PyAutoMind batches/AGENTS.md — integration: / integration-root: schema

Original Prompt

Click to expand starting prompt

Batch review: opt-in integration branches so a reviewer can run the whole batch together

Type: feature
Target: PyAutoBrain
Repos:

  • PyAutoBrain
  • PyAutoMind
    Difficulty: large
    Autonomy: supervised
    Priority: medium
    Status: formalised
    Consequence: notify
    Witness: a batch-conductor test builds a temp repo with two member branches, runs collect --integration, and asserts integration/<slot> tree == merge of both heads plus a packet line clean / conflicted: <path> per repo; evidence JSON carries headRefName for every member PR
    Review-minutes: 0
    Unattended: ready

Original request (verbatim, 2026-09-02)

For the PyAutoMind runs, I would like to be able to run the code representative of everythign in the review. This
is often require as I need to check if the outputs of a run are as expected and the like. Would it be possible
to make it so when the review is made, a single set of branches I can checkout locally and then created and
temporarily put on GitHub, which puts all changes together? I guess this could be problematic if PRs and changes
conflict, so I am happy to be told this cannot be done safely, but I guess it would also give me a sense of how
work would be resolved at the end. I dont necessarily always need this so it could also be something I can request
at the top of a review via a button, thus saving tokens when sensible.

Agreed design (assessment 2026-09-02, user: "yep sounds good")

Cheapest safe version is entirely local and needs no new credentials or doctrine change. Libraries are
imported via hardcoded PYTHONPATH (no editable installs), so checking out a merged branch per repo inside a
dedicated worktree root is enough to run everything. Never do this in the canonical checkouts: they feed
every other shell/agent and bin/morning.sh -> pull_all_main.sh flips them back to main.

Phase 1 — record member -> (repo, branch) reliably

  • The batch record (PyAutoMind/batches/<slot>.md) stores no repo/branch/PR per member; read_active /
    active_for in PyAutoBrain/agents/conductors/batch/_batch.py recover PR URLs by regex over
    active.md, whose repos: field has four dialects. Do not parse those.
  • Add headRefName (and headRepository/repo name) to GH_FIELDS (_batch.py ~632) and to the evidence
    JSON schema in agents/conductors/batch/AGENTS.md ("The evidence JSON"). This is the authoritative
    member -> (repo, branch) map the later phases drive from.

Phase 2 — batch collect --integration (laptop lane, opt-in)

  • New flag on bin/pyauto-brain batch collect, off by default, laptop lane only (same precedent as the
    opt-in --fetch leg that shells to gh). Also honour an integration: yes line in the batch record at
    dispatch so the human can request it up front.
  • Creates one integration worktree root for the slot via the existing helper
    (PyAutoBrain/bin/worktree.sh worktree_create integration-<slot> <repos...>), which writes
    activate.sh with its own PYTHONPATH and per-task NUMBA_CACHE_DIR / MPLCONFIGDIR.
  • Per affected repo: cut integration/<slot> from origin/main, then real git merge of each member's
    head branch in dispatch order (git 2.34.1 on this box has no merge-tree --write-tree, so no dry-run
    preview; the throwaway worktree is the preview). A conflicting member is left OUT of that repo's branch
    (merge aborted), never resolved by the agent.
  • Packet reports per repo: clean / conflicted with the conflicting paths and which member collided. This
    is the "how would this resolve at the end" signal the organism has never had; conflicts are the honest
    output, not a blocker. Print one copy-paste source <root>/activate.sh line.
  • The packet page cannot be the button: it is static and credential-free (Submit is a link to GitHub's
    new-file form). Opt-in lives in the record / the collect flag, not the page. Cost is git time, not model
    tokens, so default-off is about clutter.
  • Regenerable packet region (sentinel-bounded, like tiles / rulings) so refresh splices it.

Phase 3 (later, separate) — --push and expiry

  • --integration --push pushes integration/<slot> per repo from the laptop's own git auth. New network
    leg in the Brain (stdlib-only/offline invariant, AUTONOMY.md ~552-560): explicit, opt-in, laptop only.
  • Real branches only (GitHub accepts refs/heads/* and refs/tags/*). Refresh = new commit or -2 suffix,
    never force-push (never rewrite pushed history). Never a PR, never a base for anything.
  • PyAutoBrain/bin/branch_sweep.sh would classify integration/* as unmerged -> kept forever: ship an
    expiry rule (record the branch names + a sweep-after date in the batch record, which lives in a
    LEDGER_DIRS auto-merging dir) so the sweep can void them after the review closes.

Constraints

  • Batch planner already limits each shift to one member per library repo (members collide at merge), so
    within-repo conflicts should be rare; cross-repo single-member cases (one member, five organ PRs) are the
    common case.
  • Not the Gut organ: an integration ref is live work being previewed, not condemned material, and a Gut ref in
    the Gut repo cannot be checked out as a library repo. Reuse only the pattern (prefix + manifest line + sweep-after).

Activity

  1. Jammy2211 commented on Sep 2, 2026

    @Jammy2211
    ContributorAuthor

    PRs Created (Brain library + Mind companion doc — no workspace leg)

    Both PRs are open and labelled pending-release, awaiting human merge in
    library-first order (Brain before Mind).

    Commits

    PyAutoBrain (feature/batch-review-integration, head bf3e57b):

    sha subject
    dcd33e2 batch: record each PR's head branch in the evidence JSON
    99e98c9 worktree: PYAUTO_WT_BRANCH override for non-feature roots
    f39230f batch: _integration — merge every member's head into one review worktree
    68054fa batch: collect --integration wiring, report, packet region, record stamp
    7cdf59c docs: batch --integration in AGENTS.md, batch.sh, skills/batch
    bf3e57b batch: --fetch asks gh for mergedAt — there is no merged field

    PyAutoMind (feature/batch-review-integration, head 3715b97a):

    sha subject
    3715b97a batches: integration: / integration-root: record keys

    API changes

    • pyauto-brain batch collect --integration — new opt-in, collect-only flag
      (also triggered by - integration: yes in the batch record at dispatch).
      Builds one throwaway worktree root per slot,
      ~/Code/PyAutoLabs-wt/integration-<slot>/, with integration/<slot> per
      affected repo cut from origin/main and every member's PR head merged in
      dispatch order. A conflicting member is left out and named with its
      conflicting paths
      — that report is the deliverable, not a failure (exit code
      unchanged). Nothing is pushed; no remote ref is touched. Refuses non-local-dev
      lanes with a pointer, like --fetch.
    • Evidence JSON PR rows gain head_ref / head_sha / head_repo; --json
      output and pasted evidence docs gain a top-level integration block; collect
      never rewrites the --evidence file.
    • Packet gains a sentinel-bounded integration region; report gains
      ## Integration branches; record gains an - integration-root: stamp
      (the human's - integration: yes request line survives).
    • bin/worktree.sh: PYAUTO_WT_BRANCH overrides the per-task branch name
      (default unchanged: feature/<task>).
    • New opt-in read-only network leg in the Brain: git fetch origin, documented
      in the batch AGENTS.md beside --fetch.
    • Additive and opt-in throughout; no migration.

    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, so gh failed the
    whole request and every --fetch scored UNOBSERVABLE. Now mergedAt, with
    merged derived.

    Tests

    • Full PyAutoBrain suite on the task worktree: 815 passed, 1 deselected —
      test_cortex_conductor.py::test_a_fixture_tree_finds_the_schema_its_checkout_ships,
      a known worktree-symlink artefact that passes on the canonical checkout and is
      untouched by this change. No other exclusions.
    • New tests/test_batch_integration.py (19 tests) and additions to
      tests/test_batch_collect.py.
    • Laptop smoke on the real repos: a conflicted member reported with its paths, a
      second run reproduced identical trees, root and integration/* branches
      removed afterwards, canonical repos left on main and clean.

    PyAutoHeart readiness

    YELLOW (score 80) — acknowledged by the human at plan approval; both reasons
    are unrelated to this change:

    • PyAutoArray: open PR 10d old
    • release validation incomplete: no rehearsal for current source

    No RED reasons.

    Not in this PR

    Phase 3 (--push, sweep expiry) deferred to a later prompt.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01NR2L4MT5kTP8Lu9eR7dPUP

  2. Jammy2211 commented on Sep 2, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    Batch review now has an opt-in integration leg: batch collect --integration builds one throwaway worktree root per slot, merging every member's head branch per repo, so the reviewer sees the members combined rather than one PR at a time. Conflicts are reported, not resolved — a conflicting merge is surfaced in the packet as a finding and left for a human — and nothing is ever pushed: the integration root is disposable and origin is untouched. Phase 1's head fields now flow through into the evidence packet, and the collector's fetch fix replaces the non-existent merged field with mergedAt so merged members are detected correctly.

    Phase 3 (the push leg) is filed as draft/feature/pyautobrain/batch_review_integration_branches_p3_push.md in PyAutoMind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions