Skip to content

feat(batch): hold a library only while its worker runs; merge its PRs in order (M3.6j) - #684

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/shift-merges-in-order
Nov 19, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/shift-merges-in-order

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A shift used to hold a library repo from a task's start until its PR merged (#680). A PR waiting for the human's /prm (decision-taken, judge, public name) therefore stalled every later named task on that library for the rest of the shift: 4 of 7 tasks unstarted in shift 2026-11-18-pm, 2 of 4 in -pm2, about an hour idle each time.

Now a shift holds a library for starting only while a worker on it is live, and serialises the merges instead (M3.6j):

  • The next named task on a library starts once the earlier task's worker ends, even with its PR open. Never two live workers on one library. A later worker gets a sibling note naming the open PRs: branch from main, read their diffs, end obsolete if a sibling already fixed it.
  • A later PR's close-out waits (no slot, no refusal) while an earlier PR of the shift on the same library is open. Earlier = lower PR number on the same repo, which is start order.
  • Once the earlier PR merges (unattended or by /prm), a short update session runs gh pr update-branch (a merge from main, never a rebase or force-push) and ends. A later tick runs the normal close-out once CI is green on the new head; the close-out checks the earlier merge commit is an ancestor of the head. A conflict, red CI on the new head, or a third update refuses it to /prm.
  • A workspace PR waits behind its own task's library PR instead of being refused.
  • The digest gets "waits behind — merge first", the updated states and a per-library Merge order block; events get a waiting kind.

The human's rulings a–f (2026-11-19, "approved, all six yes") are recorded in AUTONOMY.md. Ruling (a): only the update session pushes, and only via gh pr update-branch; the watcher still writes no repository.

Closes #683

API Changes

None to the public API — internal changes to the batch watcher only. New template agents/conductors/batch/closeout_update_template.md; the held-library rejection text changes.
See full details below.

Test Plan

  • Full suite: 2410 passed, 1 skipped (worker run); tests/test_batch_*.py tests/test_orchestrator_*.py 695 passed, 1 skipped (re-run before push)
  • New tests fail on main: named-task starts while a PR is open/refused (×5), three-task hold names the live worker, dropped never-started pick frees, sibling note in the spawn argv; close-out wait / no-wait / unreadable-blocks / update session / updated→running→grace→healthy / FAILED on new head / conflict / third update / workspace wait / wait near review-at / carry_in behind; digest Merge order; events waiting
  • Regression guard (passes on main by design): question, park, pending re-dispatch and in-shift restart still hold
  • Skill line budget OK; tenant firewall OK; project discovery OK
  • Independent review (fresh Sonnet agent, not shown the worker's reasoning): FINDINGS, no blocker. F1, F2, F5 fixed in b7c04fa (tests fail on 6b89afe); full suite 2413 passed, 1 skipped
  • After merge: fast-forward the watcher's Brain checkout between shifts, then run tasks 6–7 (PyAutoGalaxy) as the first live test
Full API Changes (for automation & release notes)

Added

  • _orchestrator: SIBLING_NOTE, sibling_prs, UPDATE_TEMPLATE, update_prompt, after_step, _known_prs, _earlier_prs, _merge_blockers, _merged_after_start, _gh_once; constants UPDATE_CHECKS_GRACE_S = 600, UPDATE_LIMIT = 2; counters key merge_waits
  • closeout_update_template.md; {after_step} in closeout_template.md
  • _digest: waits-behind / updating / updated / current states, ### Merge order; _events: waiting kind

Changed Behaviour

  • released_picks(counters, live=): any finished pick without a question is released (park, pending re-dispatch, in-shift restart still hold); a dropped pick with no live worker is released
  • _start_closeouts: waits, update sessions, re-examines updated/current; reap_closeouts: updated/current verdicts; carry_in: carries updated/current and behind
  • Held-library reasons: "will start once X's worker ends" / "while its worker runs"

Deviations from the plan (worker's)

  • _status.py unchanged — the live view already uses _digest.task_state, so waits show there.
  • A full close-out with earlier PRs gets after= and before= (step 4b).
  • The update limit is checked before a third update session starts (refused without spawning).
  • A PR in updated/current within the review-at cutoff is left alone, not refused.

Review fixes (b7c04fa)

  • F1 — a notify worker's in-turn merge could jump the order: bin/merge_slot.py take now refuses (exit 1) while an earlier shift PR on the same library is open, using the close-out's own _merge_blockers rule via in_turn_merge_blockers; the worker ends at PR-open and the watcher's wait/update path takes over. Unreadable counters exit 2.
  • F2 — never two workers on one library: the spawn loop (_library_holder) refuses a task whose library a live, parked or re-dispatch-pending task holds, whatever the plan's ranking.
  • F5 — after a branch update, the watcher requires the PR head to equal the head the update made before reading CI; no head yet → wait; moved head → refused for /prm, slot freed.

Known gaps

  • F3: a library is released when .done is read, a moment before the worker session exits.
  • F4: a task resumed from an earlier shift's park counts its branch as cut at this shift's spawn, so it may skip the update; the close-out still re-runs CI and the witness.
  • F6: a PR the human merges while updated can get one wasted close-out session (reaped as merged-outside, slot released).
  • A waiting PR that the human merges out of order stays shown as waiting until the shift ends.
  • The update session's prompt is template-tested, not yet run against a live claude --bg.

Heart (dev-ship gate for PyAutoBrain; reasons shown, not blocking)

  • manifest drift ×2 (yellow); release validation incomplete: no rehearsal for current source

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

Jammy2211 and others added 3 commits November 19, 2026 08:39
…es wait in PR order (M3.6j, #683)

- released_picks: a finished pick frees its library for a start, PR open or
  not; questions, parks, pending re-dispatch and answered restarts still hold;
  a /drop'ped task with no live worker holds nothing.
- New worker on a library with this shift's open PRs gets SIBLING_NOTE
  (branch from main, never stack; ruling e for worktree_check_conflict).
- _start_closeouts: a library PR waits (no close-out, no slot, no refusal)
  behind any earlier known PR on the same repo until GitHub says MERGED or
  CLOSED (rulings b, c, f); counters["merge_waits"] rebuilt each tick; a
  workspace PR waits behind its own task's library PR.
- A PR cut before an earlier PR merged gets a branch-update session
  (closeout_update_template.md: gh pr update-branch, never force; ruling a)
  under its merge slot; `updated`/`current` re-checked each tick; merge
  close-out only on CI green at the new head, with a merge-order step 4b.
  UPDATE_LIMIT 2, UPDATE_CHECKS_GRACE_S 600.
- carry_in carries updated/waiting PRs with what they waited behind.
- Digest: waits-behind / updated states and a per-library "Merge order"
  block; events: `waiting`, and a refused PR names how many wait behind it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…683)

- batch AGENTS.md: replace the #679 paragraph (a library is held while its
  worker runs; merges wait in PR order) and add the branch-update step to
  the close-out description.
- skills/batch/batch.md: the planner's new held-library reason.
- AUTONOMY.md: rulings a-f dated 2026-11-19 under "Unattended glance
  merges", and the per-tick blocking-PR read in the network surface.
- test: a non-library example repo for the workspace-PR wait (tenant firewall).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…F5; #683)

- F1: `merge-slot take` refuses a notify worker's in-turn merge while an
  earlier shift PR on the same library is open (in_turn_merge_blockers,
  the close-out's rule; unreadable blocks, unreadable counters exit 2);
  worker_template and SIBLING_NOTE say: end at PR-open.
- F2: the spawn loop refuses a task whose library a live, parked or
  re-dispatch-pending task holds, whatever the plan's order made of it.
- F5: gh_pr_state also reads headRefOid; an `updated` PR's CI is read only
  once GitHub shows the update's head; a head that moved refuses for /prm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 3f1ba6a into main Nov 19, 2026
2 checks passed
@Jammy2211
Jammy2211 deleted the feature/shift-merges-in-order branch November 19, 2026 09:05
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): hold a library only while its worker runs; merge its PRs in order (M3.6j)

1 participant