Skip to content

feat: shift close-out at PR-open, merge on green CI (M3.7b) - #689

Merged
Jammy2211 merged 3 commits into
mainfrom
feature/shift-speed-closeout-at-pr-open
Nov 19, 2026
Merged

Jammy2211 merged 3 commits into
mainfrom
feature/shift-speed-closeout-at-pr-open

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Summary

M3.7b of the autonomous-orchestrators epic (closes #688). Rulings S2, S5 and S6 (human, 2026-11-19) and the human's plan decisions A and B.

  • S5: the watcher starts a glance/notify close-out at PR-open. CI RUNNING or HEALTHY starts it; FAILED or UNKNOWN refuses with no session; NO-CHECKS waits 10 minutes from when the watcher first saw the PR, then refuses. The session runs the witness and reads the diff while CI runs, then waits in-turn (pyauto-brain ci-verdict <pr> --until <deadline>) and merges only on GREEN. The deadline is the earlier of start + 30 minutes and review-at minus 5 minutes.
  • S2: the close-out's full affected smoke is removed. The worker's targeted smoke stands; the full sweep is the cloud Workspace Smoke after merge (nightly, M3.7d; shift end, M3.7e).
  • S6: the branch update and CI rerun happen only when the PR's changed files overlap an earlier shift PR merged ahead of it on that library, a file list cannot be read (or may be truncated), or GitHub reports the PR CONFLICTING. Merge order (M3.6j rulings b, c, f) is unchanged.
  • Decision A: the watcher takes no merge slot for a merge close-out. Before spawning it only checks the cap has room, counting close-outs already running without a slot. The session runs merge-slot take itself immediately before merging, and goes on only on a taken: line. The branch-update path keeps the watcher's take. A refused close-out's slot is freed whichever side took it.
  • Decision B: a dated amendment in AUTONOMY.md "The watcher's network surface" allows read-only gh pr view --json files for a waiting library PR and the earlier shift PRs merged ahead of it, once per PR per shift (an unreadable list is cached too, never re-read); mergeable rides on the existing gh pr view.
  • The close-out pins the merge to the witnessed head (gh pr merge … --match-head-commit), and refuses if the head moved after the witness.

API Changes

None to any library. Brain internals: bin/ci_verdict.py (and pyauto-brain ci-verdict) gains --until <iso>, which re-judges every 30 seconds while PENDING, at most 540 seconds per call; exit codes are unchanged (0 GREEN, 1 RED, 2 PENDING; 64 for a bad time). _merge_slots gains a SESSION holder and a read-only room(). See full details below.

Risks

  • Two disjoint PRs that are each green can break main together. main CI and the shift-end sweep find it after the merge. Revert condition (S6): one red main CI traced to two disjoint shift PRs merged this way restores the unconditional update.
  • A close-out that starts at PR-open and then sees red CI has spent its tokens; the digest counts them as today.
  • Revert condition (S2): one red sweep traced to an unattended merge restores the close-out's full affected smoke.

Test Plan

  • Tests first: tests/test_closeout_at_pr_open.py (27 tests). 21 of them failed on the unmodified code (S5 start with CI pending, deadline and margin, NO-CHECKS grace, prompt order with no smoke, S6 disjoint with no update, unreadable-list cache, merge order with a running earlier close-out, decision A slot release, --until timing, AUTONOMY.md S2/S5/S6). The other 6 pin behaviour that stays (red CI refuses, overlap/conflict/unreadable gets the update, full cap refuses).
  • Full Brain suite: 2452 passed, 1 skipped.
  • bin/check_skill_line_counts.sh 200 PyAutoBrain: OK. Tenant firewall (organ code): OK. install.sh --check-project-discovery: OK.
  • Independent review (fresh Opus 5.5 session): round 1 FINDINGS (2 medium: a merge could land after review-at; an unreadable file list was re-read; 3 low: a merge-slot take outside a shift exited 0, the --until call could hit the tool timeout, the merge was not pinned to the witnessed head). All fixed; round 2 CLEAN.
  • Heart scoped dev-ship verdict for PyAutoBrain: green.
  • Smoke: n/a (organism repo; no downstream script surface).
Full API Changes (for automation & release notes)

Removed

  • _orchestrator.smoke_command, _orchestrator.CLOSEOUT_SMOKE_JOBS — the close-out runs no smoke (S2).

Added

  • bin/ci_verdict.py --until <iso8601> — poll while PENDING up to the deadline, at most 540 s per call.
  • _orchestrator.gh_pr_files(url, run=None) — read-only changed-file list.
  • _orchestrator.CLOSEOUT_CI_WAIT_S = 1800, CLOSEOUT_MERGE_MARGIN_S = 300.
  • _merge_slots.SESSION, _merge_slots.room(slot, pr, task, pending).

Changed Behaviour

  • _start_closeouts: starts at PR-open (S5); overlap-only branch update (S6); no watcher slot take for a merge close-out (decision A).
  • gh_pr_state also returns mergeable.
  • closeout_prompt / closeout_command / spawn_closeout take ci_until and disjoint.
  • closeout_template.md: smoke step removed; witness → diff → label/Heart → merge order → in-turn CI wait → head check → .dropped → own merge-slot take → pinned merge.

🤖 Generated with Claude Code

Jammy2211 and others added 3 commits November 19, 2026 13:06
…full smoke

Rulings S2, S5, S6 of 2026-11-19 (AUTONOMY.md "Shift speed"), decisions A
and B. PyAutoBrain#688.

- S5: `_start_closeouts` starts a close-out when `gh pr checks` reads RUNNING
  or HEALTHY; FAILED/UNKNOWN refuse with no session; NO-CHECKS waits
  UPDATE_CHECKS_GRACE_S from when the watcher first saw the PR
  (`counters["pr_seen"]`), then refuses. The same rule applies to an
  updated PR: RUNNING on the verified new head starts the merge close-out,
  which waits in-turn; its NO-CHECKS grace and head check are kept. Every
  other guard and the merge order are unchanged. The close-out gets a CI
  deadline, min(start + CLOSEOUT_CI_WAIT_S (30 min), review-at).
- Decision A: the watcher takes no merge slot for a merge close-out; it
  checks `_merge_slots.room` (read-only, counting merge close-outs already
  running without a slot, so the cap is not oversold) and refuses with no
  session when there is no room. The session runs `merge-slot take` as a
  bare call just before the merge. The reaper frees a refused close-out's
  slot whether the watcher or the session holds it for that task. The
  branch-update path keeps the watcher's take.
- S6: a branch update is needed only when the PR's changed files overlap a
  PR of the shift merged ahead of it, a file list cannot be read, or GitHub
  reports the PR CONFLICTING (`mergeable`, now a field of `gh_pr_state`).
  New read-only `gh_pr_files` (once per PR per shift, cached in
  `counters["pr_files"]`; a list of 100+ files counts as unreadable).
  Disjoint PRs are named in step 4b, not compared.
- S2: the close-out runs no full affected smoke (`smoke_command`,
  CLOSEOUT_SMOKE_JOBS removed). Template reordered: witness on the PR head
  (record headRefOid), diff + public names, label/tier, Heart, 4b, in-turn
  `ci-verdict --until`, head unchanged, .dropped, merge-slot take + /prm,
  cleanup, end.
- `ci-verdict --until <iso>`: re-judges every 30 s while PENDING, at most
  540 s per call; exit codes unchanged; a bad time is usage (64).
- Docs: AUTONOMY.md S2/S5/S6 with revert conditions, leg 2, the glance
  merges and M3.6j (a) paragraphs, network-surface amendment (decision B);
  batch AGENTS.md; worker_template; prm reference; pyauto-brain help.

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

- CI deadline = min(start + 30 min, review-at - CLOSEOUT_MERGE_MARGIN_S
  (300 s)), so a close-out started near review-at cannot merge after it
  (#632 F1).
- `_pr_files_once` caches an unreadable read (None, also when the reader
  raises) as an overlap and never reads that PR again in the shift.
- Template step 8: go on only when `merge-slot take` prints `taken: …`;
  `refused:`, `cannot tell:` or exit 0 `not in a shift` refuse
  `merge slot not taken: <first line> → /prm`. The merge is pinned with
  `gh pr merge --match-head-commit <the step-1 headRefOid>`.
- `ci-verdict --until` bounds one call by wall time from its start, gh reads
  included (reads again only while sleep + longest read fits in 540 s), and
  re-checks the deadline after each sleep. Template: run it with a Bash
  timeout of 600000 ms.
- AUTONOMY.md S5 and batch AGENTS.md mention the margin, the pin and the
  unreadable-list cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 1a120cb into main Nov 19, 2026
2 checks passed
@Jammy2211
Jammy2211 deleted the feature/shift-speed-closeout-at-pr-open branch November 19, 2026 13:28
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: shift close-out at PR-open, merge on green CI (M3.7b)

1 participant