From 5a31cc9607c1cfc53a59bc5670f9ed96808acdd6 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 12:43:07 +0100 Subject: [PATCH 01/10] Clean up a do-epic chunk whose pull request merged without waiting for a running slot --- README.md | 2 +- bin/do_epic/gates.py | 4 +++- bin/do_epic/main.py | 6 +++-- bin/do_epic/parking.py | 28 ++++++++++++++++++---- bin/do_epic/test_gates.py | 6 +++-- bin/do_epic/test_main.py | 29 +++++++++++++++++++++++ bin/do_epic/test_parking.py | 2 +- docs/decisions.md | 2 +- docs/reading-cost.md | 47 +++++++++++++++++++++++++++++++++++++ 9 files changed, 113 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d4fc0a09..8fa34c3a 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `epic_run.py` holds what stays the same through one run of do-epic, such as its config, its Jira store and its paths, and starts the chunks that may start now. - `planning.py` settles, before the chunks start, where each open issue is worked, its scores and the order the issues start in, through `split.py`, `repo_pick.py`, `issue_scores.py` and `ranking.py`. - `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. - - `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `parking.py` parks such a chunk after a cycle and polls the gate until its worker has something to do. + - `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `parking.py` parks such a chunk after a cycle and polls the gate until its worker has something to do, or until its pull request merged, when it removes the worktree itself with `chunk-pr clean` and finishes the chunk without a worker or a running slot. - `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. - `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. - `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. diff --git a/bin/do_epic/gates.py b/bin/do_epic/gates.py index 41b94784..d88f6d35 100644 --- a/bin/do_epic/gates.py +++ b/bin/do_epic/gates.py @@ -38,6 +38,8 @@ class Open: @dataclasses.dataclass(frozen=True) class Unopened(Open): """An Open whose worktree stands though no pull request is open at its head: one that was merged or closed, whose chunk still has its worktree to remove.""" + # The chunk's worktree. + worktree: str @dataclasses.dataclass(frozen=True) @@ -65,7 +67,7 @@ def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human: forge = forge_of(origin) pull = open_pull(forge, branch, head, run) if not isinstance(pull, str): - return pull or Unopened(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already") + return pull or Unopened(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already", worktree) decision = review_decision(forge, pull, head, run) if not isinstance(decision, str): return decision or Open(f"pull request #{pull} is a draft") diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index 5eaec2c3..ab2d6c17 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -34,8 +34,8 @@ from claude_code.reply import Limited from text_files.markdown_text import listed from do_epic.repos import locate from chunk_driver.this_loop import Loop +from do_epic.parking import Merged, parked_through from chunk_driver.project.model_choice import Models, overridden -from do_epic.parking import parked_through from chunk_driver.project.premises import read_premises from git_cli.git_repo import record_chunk_base from forge.commands import Run, runner @@ -67,7 +67,7 @@ A chunk whose worker ends its run while its pull request waits on its checks, an is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull -request is ready, with nothing else to wait on, the window's name says `awaits your merge`, and its worker goes on once you merged it. A parked chunk survives a reboot: run do-epic again to go on polling. +request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place; a pull request closed unmerged goes on to its worker. A parked chunk survives a reboot: run do-epic again to go on polling. --status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when. --dry-run runs the planning and the scheduling against the epic as Jira holds it. It doesn't write anything to Jira, start a window or ask a question, and it doesn't start any issue in Jira as a real run's chunk does. It prints each label, sub-task, comment, score and rank move that planning would write, each move of a parent issue whose sub-tasks a person filed, the order the issues would start in, each chunk that would start and why each other issue waits. A sub-task not yet filed shows a key such as ABC-new1. A question planning would ask is printed instead of asked. Planning's claude calls still run. A repo that is missing isn't cloned. Planning then stops there, so its writes are only those made before it, and the issues of that repo wait, and a chunk of another repo may start in the place a real run gives them; a real run would clone it and go on. @@ -265,6 +265,8 @@ def chunk_run(key: str, epic: EpicRun) -> Stop: while True: if isinstance(news, Stop): return news + if isinstance(news, Merged): + return handed_on(key, epic, Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH) run = dataclasses.replace(run, cycle_number=run.cycle_number + 1) cycle = next_cycle(run, loop, repo is not None, epic, news) if isinstance(cycle, Stop): diff --git a/bin/do_epic/parking.py b/bin/do_epic/parking.py index 17926e46..56005611 100644 --- a/bin/do_epic/parking.py +++ b/bin/do_epic/parking.py @@ -15,10 +15,15 @@ from agent_cycle import tmux DRIVER_PARKED = f"{chunk_prompt.DRIVER} parked the chunk while" -def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool, based: str | None) -> str | Stop: - """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. +@dataclasses.dataclass(frozen=True) +class Merged: + """What `parked_through` returns for a chunk whose pull request merged and whose worktree do-epic removed itself: the chunk is finished.""" - Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can (`Poll.first_gate`), and what the worker must still do is news (`news_after`). + +def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool, based: str | None) -> str | Stop | Merged: + """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. Or Merged, where the chunk's pull request merged and `merged_and_cleaned` removed its worktree, which needs no worker and no running slot. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. + + Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can (`Poll.first_gate`), and what the worker must still do is news (`news_after`), unless the pull request merged already and do-epic removes the worktree itself. A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again. """ @@ -34,6 +39,8 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finis if key in recorded_as: return resumed_news(poll, recorded_as[key].on, shown=None) entered = None if told is None else poll.first_gate(again=finished) + if finished and poll.by_human and isinstance(entered, gates.Unopened) and (done := merged_and_cleaned(poll, entered)): + return done if not isinstance(entered, gates.Gate): if isinstance(entered, Failure): say(f"cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: {entered.reason}", epic.effects, stdout=True) @@ -102,12 +109,14 @@ class Poll: return failed -def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop: - """Reads the gate of the parked chunk every POLL_SECONDS until its worker has something to do and a running slot is free, then removes its file: what to tell that worker. on is the gate the chunk's file says it is parked on, and shown what its window's name says it awaits, None where nothing yet. A gate that cannot be read leaves the chunk parked as it was.""" +def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop | Merged: + """Reads the gate of the parked chunk every POLL_SECONDS until its worker has something to do and a running slot is free, then removes its file: what to tell that worker. on is the gate the chunk's file says it is parked on, and shown what its window's name says it awaits, None where nothing yet. A gate that cannot be read leaves the chunk parked as it was. A chunk whose pull request merged is Merged at once, without waiting for a slot (`merged_and_cleaned`).""" told = Told(poll, shown) while True: now = poll.gate() if isinstance(now, gates.Open): + if isinstance(now, gates.Unopened) and (done := merged_and_cleaned(poll, now)): + return done full = resumed(poll.repo, poll.loop, poll.epic) if full is None: return unparked(poll, on, now) @@ -140,6 +149,15 @@ class Told: self.reason = reason +def merged_and_cleaned(poll: Poll, unopened: gates.Unopened) -> Merged | Stop | None: + """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file: Merged where it removed the worktree. None where it didn't, so that the worker decides, as for a pull request closed unmerged. chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files, so a worktree that holds work the merge lacks stays.""" + if isinstance(poll.epic.forge_at(unopened.worktree)(["chunk-pr", "clean"]), Failure): + return None + say(f"pull request merged: removed {unopened.worktree}", poll.epic.effects, stdout=True) + failed = parked.unpark(poll.folder, poll.key) + return Stop(1, failed.reason) if failed else Merged() + + def unparked(poll: Poll, on: str, now: gates.Open) -> str | Stop: """Removes the file of the chunk that was parked on the gate on: what to tell its worker, which now says why it resumes.""" failed = parked.unpark(poll.folder, poll.key) diff --git a/bin/do_epic/test_gates.py b/bin/do_epic/test_gates.py index 681268da..8d090674 100644 --- a/bin/do_epic/test_gates.py +++ b/bin/do_epic/test_gates.py @@ -28,7 +28,7 @@ def comment(by: str, at: str) -> dict: class Forge: """Stands in for git and the forge's CLI in the checkout and the chunk's worktree; `ran` holds each folder a command ran in. Only the CLI of origin's forge answers: `gh` fails on a Gitea origin, and `tea` on a GitHub one.""" - def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main") -> None: + def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main", merged: bool = False) -> None: self.cli = "gh" if "github.com" in origin else "tea" self.ran: list[str] = [] self.commands: list[list[str]] = [] @@ -39,6 +39,8 @@ class Forge: "git rev-parse": HEAD + "\n", "git symbolic-ref": "origin/main\n", "git config": Failure("git config: unset"), + # chunk-pr removes the worktree only of a pull request the forge reports merged at the worktree's head. + "chunk-pr clean": "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), "gh pr list": pulls, "gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state, "baseRefName": base}), "gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]), @@ -185,7 +187,7 @@ class GateOfAChunk(unittest.TestCase): for news, forge in cases.items(): with self.subTest(news=news): self.assertEqual(forge.gate(), Open(news)) - self.assertEqual(Forge(pulls="").gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already")) + self.assertEqual(Forge(pulls="").gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already", "/code/billing-ABC-21")) def test_a_read_that_fails_is_a_failure_and_says_nothing_of_the_gate(self): for command in ("git worktree", "git remote", "gh pr list", "gh pr view", "gh pr checks", "gh api graphql"): diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index b814070a..1ba6fc96 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -921,6 +921,35 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval", "ABC-20 awaits a slot", "ABC-20"]) self.assertEqual(len(prompts), 2) + def test_a_parked_chunk_whose_pull_request_merged_is_cleaned_and_finished_by_do_epic_though_no_slot_is_free(self) -> None: + self.description = DESCRIPTION.replace("2", "1") + self.forges = [awaiting(), awaiting(pulls="", merged=True)] + fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW + "ABC-22\t0\t@10\n") + code, out, err, prompts = self.parked_run(fake) + self.assertEqual((code, len(prompts)), (0, 1), err) + self.assertEqual(self.forges[1].commands.count(["chunk-pr", "clean"]), 1) + self.assertEqual({folder for folder, command in zip(self.forges[1].ran, self.forges[1].commands) if command[0] == "chunk-pr"}, {"/code/api-ABC-20"}) + self.assertFalse(self.file.exists()) + self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval"]) + self.assertIn("the chunk finished; ", out) + + def test_a_parked_chunk_whose_worktree_chunk_pr_keeps_goes_to_a_worker_as_before(self) -> None: + self.forges = [awaiting(), awaiting(pulls=""), CLEANED] + fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) + code, _, err, prompts = self.parked_run(fake) + self.assertEqual((code, len(prompts)), (0, 2), err) + self.assertEqual(self.forges[1].commands.count(["chunk-pr", "clean"]), 1) + self.assertIn("no pull request from origin's ABC-20 is open", prompts[1].split("\n\n")[0]) + + def test_where_a_person_merged_before_the_cycle_closed_a_finished_chunk_is_cleaned_by_do_epic(self) -> None: + self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8") + self.forges = [awaiting(pulls="", merged=True)] + fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) + code, out, err, prompts = self.parked_run(fake) + self.assertEqual((code, len(prompts)), (0, 1), err) + self.assertEqual(self.forges[0].commands.count(["chunk-pr", "clean"]), 1) + self.assertIn("the chunk finished; ", out) + def test_a_chunk_parks_and_resumes_though_the_next_chunk_cannot_start(self) -> None: self.forges = [awaiting(), awaiting(decision="APPROVED")] worker = self.worker() diff --git a/bin/do_epic/test_parking.py b/bin/do_epic/test_parking.py index 53e58bce..714c8fd2 100644 --- a/bin/do_epic/test_parking.py +++ b/bin/do_epic/test_parking.py @@ -9,7 +9,7 @@ from failure import Failure from do_epic.parking import news_after from do_epic.gates import Open, Unmergeable, Unopened -UNOPENED = Unopened("no pull request is open") +UNOPENED = Unopened("no pull request is open", "/code/api-ABC-20") UNCLEANED = f"{chunk_prompt.DRIVER} keeps the chunk open while its worktree stands: no pull request is open." UNMERGEABLE = Unmergeable("pull request #7 conflicts with its base branch") UNLEVELLED = f"{chunk_prompt.DRIVER} keeps the chunk open while its pull request doesn't merge into its base: pull request #7 conflicts with its base branch." diff --git a/docs/decisions.md b/docs/decisions.md index 2ee3e59d..5514d393 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -173,7 +173,7 @@ Valid while `~/.claude` is a checkout of this repo. - **Releases.** An epic item has no release. It ships into its repo's unreleased work: where the repo publishes something others consume, a bullet under `CHANGELOG.md` → `## Unreleased`, or nothing where the repo's plan is in Jira. The issue is no item of the repo's plan, so the chunk's worker writes the bullet in its branch and runs `chunk-pr merge` without `--finish`. - **Repos.** A repo's name is its main checkout's folder name, and a project config names that checkout. A missing checkout is cloned from the host of the epic's other repos; where unsure, do-epic asks. Unsure means the other repos don't all sit under one host and owner (the same host spelt as https and as ssh counts as two), an origin can't be read or isn't an https, ssh or scp-style address, the folder to clone into holds something else, or the clone fails. A repo no config names is cloned into the clone folder, and the human is asked to write its config. Each chunk uses its repo's model, routing, and language for commits and PRs. Jira text is in the epic's language, or else the machine's default. - **Running.** The epic caps the chunks running at once, and each repo's `parallel-chunks` still applies. do-epic and loop-claude never run chunks in the same repo at once. The cap is a line of the epic's description, `**Max parallel chunks:** 2`, and 1 without it, as `parallel-chunks` is. A repo's `parallel-chunks` counts the chunks of every epic in its checkout. Each window is named for its issue's key, and a tmux window option, `@chunk-root`, names the folder its chunk works in, which is how loop-claude sees do-epic's chunks in a checkout. do-epic and loop-claude each hold the checkout's `starting` lock from checking the checkout's chunks to starting a window there. A chunk without a repo works in `~/.local/state/do-epic//`. do-epic archives its cycles under `~/.claude/do-epic-transcripts/`, not in loop-claude's archive, whose readers parse loop-claude's prompts. An open issue runs once a label records its repo; until do-epic picks repos itself, an issue without one waits, and `do-epic ` says so. -- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic ` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits. In a repo whose config sets `merge = "human"`, the merge itself is a gate: `chunk-pr merge` leaves the pull request ready, the chunk parks on `your merge` once nothing else holds the pull request, and it resumes when the forge no longer reports the pull request open, to clean up and finish. It resumes too once the pull request conflicts with its base branch, or is behind it where GitHub's branch protection requires an up-to-date branch, so the person finds a pull request they can merge. The worker then runs `chunk-pr merge` again, which levels the branch, waits for the checks and leaves the pull request ready. A chunk whose cycle ends on such a pull request is not handed on: its worker is told after each cycle until the pull request merges into its base. While GitHub still computes whether the pull request merges, the chunk stays parked until the next read. Gitea also reports a pull request as not mergeable for the seconds it checks for conflicts. A read in those seconds resumes the chunk for a run that doesn't change anything, which costs less than reading every gate twice to tell the two apart. The judge may rule such a chunk finished while its pull request is open, since its worker ends each run there. So do-epic reads a gate it could not read again before it hands the chunk on, and tells the worker once to remove a worktree whose pull request is no longer open. +- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic ` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits. In a repo whose config sets `merge = "human"`, the merge itself is a gate: `chunk-pr merge` leaves the pull request ready, the chunk parks on `your merge` once nothing else holds the pull request, and it resumes when the forge no longer reports the pull request open, to clean up and finish. It resumes too once the pull request conflicts with its base branch, or is behind it where GitHub's branch protection requires an up-to-date branch, so the person finds a pull request they can merge. The worker then runs `chunk-pr merge` again, which levels the branch, waits for the checks and leaves the pull request ready. A chunk whose cycle ends on such a pull request is not handed on: its worker is told after each cycle until the pull request merges into its base. While GitHub still computes whether the pull request merges, the chunk stays parked until the next read. Gitea also reports a pull request as not mergeable for the seconds it checks for conflicts. A read in those seconds resumes the chunk for a run that doesn't change anything, which costs less than reading every gate twice to tell the two apart. The judge may rule such a chunk finished while its pull request is open, since its worker ends each run there. So do-epic reads a gate it could not read again before it hands the chunk on, and removes a worktree whose pull request is no longer open itself, with `chunk-pr clean`, which acts only on a pull request the forge reports merged at the worktree's head and on a worktree without uncommitted or untracked files: the chunk then finishes without a worker and, where it was parked, without a running slot. Where `chunk-pr clean` refuses, as for a pull request closed unmerged, it tells the worker once to remove the worktree, and a parked chunk waits for a slot as for any other news. - **Human tasks.** do-epic leaves a human task's issue as the team filed it. The task gets a window of its own while it is open, no issue blocks it, and it blocks another open issue. The window DMs the human once, through the notifier of the first repo whose project config names one (the repos of the issues it holds up come first, then those of the epic's other issues; where none does, the window says so), shows as parked (`awaits a human's task`) so that it doesn't take a running slot, and polls the epic every minute until the task no longer holds up an open issue. Then the issues it held up may start. A window that starts again, as after a reboot, DMs again. - **Findings.** A finding about the epic's goals is filed in the epic. A finding about a repo's goals follows that repo's rules. Where unsure which, do-epic asks. A set of new items toward an epic goal needs the human's approval before work starts; a finding filed during a chunk doesn't. - **Finishing.** When the epic holds no open item: release-review passes on each repo the epic changed, then the items they file, then the human confirms each achieve goal and that no maintain goal has a defect. For a goal that isn't met, do-epic proposes items for approval. Then a summary comment on the epic, and closing the epic in Jira, as the very last step. diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 877bb13a..5433ee0b 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -3923,3 +3923,50 @@ Read most (opens and searches): ## Reading cost, chunk 4257e532ff74, finished 2026-12-03T10:09:57Z 48515 new input tokens before the first commit. + +## Reading cost, chunk 08904df4e666, finished 2026-12-03T10:28:33Z + +39964 new input tokens before the first commit. + +Read most (opens and searches): + +- `skills/larv-review/SKILL.md` 3 + +## Reading cost, chunk 9e8e2f1e6b3d, finished 2026-12-03T10:37:48Z + +45071 new input tokens before the first commit. + +Read most (opens and searches): + +- `skills/larv-review/SKILL.md` 5 +- `agents/prose-reviewer.md` 2 +- `CHANGELOG.md` 1 +- `README.md` 1 + +## Reading cost, chunk b9912b901933, finished 2026-12-03T11:10:26Z + +44273 new input tokens before the first commit. + +Read most (opens and searches): + +- `skills/larv-review/SKILL.md` 4 +- `README.md` 1 +- `agents/product-owner-reviewer.md` 1 +- `ci.sh` 1 + +## Reading cost, chunk ec0bf3d2900f, finished 2026-12-03T11:37:41Z + +209593 new input tokens before the first commit. + +Read most (opens and searches): + +- `README.md` 4 +- `bin/chunk_driver/project/records.py` 3 +- `bin/machine_load/slots.py` 2 +- `bin/repo_checks/__init__.py` 2 +- `bin/run_heavy/path_entry/docker` 2 +- `todo.md` 2 +- `bin/chunk_preflight/facts.py` 1 +- `bin/deploy_release/trace.py` 1 +- `bin/do_epic/main.py` 1 +- `bin/loop_state/paths.py` 1 -- 2.52.0 From 0ea7c1367363c33b52f72b39f495eaa8955f87a1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 13:03:37 +0100 Subject: [PATCH 02/10] Kill the mutants of the merged-chunk cleanup --- bin/do_epic/main.py | 9 +++++++-- bin/do_epic/test_gates.py | 3 +++ bin/do_epic/test_main.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index ab2d6c17..f0dc3850 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -266,7 +266,7 @@ def chunk_run(key: str, epic: EpicRun) -> Stop: if isinstance(news, Stop): return news if isinstance(news, Merged): - return handed_on(key, epic, Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH) + return handed_on(key, epic, landed_in(repo, based)) run = dataclasses.replace(run, cycle_number=run.cycle_number + 1) cycle = next_cycle(run, loop, repo is not None, epic, news) if isinstance(cycle, Stop): @@ -284,7 +284,7 @@ def chunk_run(key: str, epic: EpicRun) -> Stop: news = parked_through(repo, loop, epic, told=news, finished=isinstance(concluded.verdict, Finished), based=based) if repo is not None else "" # A chunk that was parked has work again, whatever the judge ruled before its pull request passed the gate. if isinstance(concluded.verdict, Finished) and news == "": - return handed_on(key, epic, Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH if repo is not None else Landed.NOWHERE) + return handed_on(key, epic, landed_in(repo, based)) def epic_based(key: str, root: str, epic: EpicRun) -> str | None | Stop: @@ -354,6 +354,11 @@ class Landed(enum.Enum): ON_EPIC_BRANCH = enum.auto() +def landed_in(repo: str | None, based: str | None) -> Landed: + """Where the work of a chunk in the repo called repo landed: on the epic's working branch where based names it, else on the repo's default branch, nowhere for a chunk without a repo.""" + return Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH if repo is not None else Landed.NOWHERE + + class How(enum.Enum): """How a finished chunk's issue moves when it doesn't move to a status the config names.""" # do-epic neither moves nor awaits it. diff --git a/bin/do_epic/test_gates.py b/bin/do_epic/test_gates.py index 8d090674..6b7969ee 100644 --- a/bin/do_epic/test_gates.py +++ b/bin/do_epic/test_gates.py @@ -187,6 +187,9 @@ class GateOfAChunk(unittest.TestCase): for news, forge in cases.items(): with self.subTest(news=news): self.assertEqual(forge.gate(), Open(news)) + long_head = Forge(pulls="") + long_head.answers["git rev-parse"] = "abc" * 13 + "\n" + self.assertEqual(long_head.gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already", "/code/billing-ABC-21")) self.assertEqual(Forge(pulls="").gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already", "/code/billing-ABC-21")) def test_a_read_that_fails_is_a_failure_and_says_nothing_of_the_gate(self): diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index 1ba6fc96..e6c52793 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -933,6 +933,21 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval"]) self.assertIn("the chunk finished; ", out) + def test_where_the_parked_file_of_a_merged_chunk_cannot_be_removed_the_loop_stops(self) -> None: + self.forges = [awaiting(), awaiting(pulls="", merged=True)] + fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) + fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=lambda seconds: self.file.parent.chmod(0o555)) # type: ignore[method-assign] + self.addCleanup(lambda: self.file.parent.chmod(0o755)) + code, out, err, prompts = self.parked_run(fake) + self.assertEqual((code, len(prompts)), (1, 1)) + self.assertIn("pull request merged: removed /code/api-ABC-20\n", out) + self.assertIn("Permission denied", err) + + def test_the_work_of_a_finished_chunk_landed_where_its_repo_and_working_branch_say(self) -> None: + self.assertEqual(main.landed_in("api", None), main.Landed.ON_DEFAULT_BRANCH) + self.assertEqual(main.landed_in("api", "ABC-12"), main.Landed.ON_EPIC_BRANCH) + self.assertEqual(main.landed_in(None, None), main.Landed.NOWHERE) + def test_a_parked_chunk_whose_worktree_chunk_pr_keeps_goes_to_a_worker_as_before(self) -> None: self.forges = [awaiting(), awaiting(pulls=""), CLEANED] fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) -- 2.52.0 From d2bb2c56e166a6221b46e12b490e133383b0b970 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 13:07:27 +0100 Subject: [PATCH 03/10] =?UTF-8?q?Answer=20product-owner=20round=201:=201?= =?UTF-8?q?=20=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(1=20misread);=20finish?= =?UTF-8?q?=20a=20chunk=20whose=20clean=20removed=20the=20worktree=20befor?= =?UTF-8?q?e=20failing,=20say=20its=20reason,=20and=20reword=20the=20help?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/do_epic/gates.py | 1 - bin/do_epic/main.py | 4 ++-- bin/do_epic/parking.py | 11 +++++++---- bin/do_epic/test_gates.py | 6 +++--- bin/do_epic/test_main.py | 12 ++++++++++-- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bin/do_epic/gates.py b/bin/do_epic/gates.py index d88f6d35..126321f6 100644 --- a/bin/do_epic/gates.py +++ b/bin/do_epic/gates.py @@ -38,7 +38,6 @@ class Open: @dataclasses.dataclass(frozen=True) class Unopened(Open): """An Open whose worktree stands though no pull request is open at its head: one that was merged or closed, whose chunk still has its worktree to remove.""" - # The chunk's worktree. worktree: str diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index f0dc3850..c7df8282 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -67,7 +67,7 @@ A chunk whose worker ends its run while its pull request waits on its checks, an is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull -request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place; a pull request closed unmerged goes on to its worker. A parked chunk survives a reboot: run do-epic again to go on polling. +request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place. Where it cannot, as for a pull request closed unmerged or a worktree with unsaved files, the worker goes on once a place is free. A parked chunk survives a reboot: run do-epic again to go on polling. --status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when. --dry-run runs the planning and the scheduling against the epic as Jira holds it. It doesn't write anything to Jira, start a window or ask a question, and it doesn't start any issue in Jira as a real run's chunk does. It prints each label, sub-task, comment, score and rank move that planning would write, each move of a parent issue whose sub-tasks a person filed, the order the issues would start in, each chunk that would start and why each other issue waits. A sub-task not yet filed shows a key such as ABC-new1. A question planning would ask is printed instead of asked. Planning's claude calls still run. A repo that is missing isn't cloned. Planning then stops there, so its writes are only those made before it, and the issues of that repo wait, and a chunk of another repo may start in the place a real run gives them; a real run would clone it and go on. @@ -355,7 +355,7 @@ class Landed(enum.Enum): def landed_in(repo: str | None, based: str | None) -> Landed: - """Where the work of a chunk in the repo called repo landed: on the epic's working branch where based names it, else on the repo's default branch, nowhere for a chunk without a repo.""" + """Where the work of a chunk in the repo called repo landed: on the epic's working branch where based names it, otherwise on the repo's default branch, or nowhere for a chunk without a repo.""" return Landed.ON_EPIC_BRANCH if based is not None else Landed.ON_DEFAULT_BRANCH if repo is not None else Landed.NOWHERE diff --git a/bin/do_epic/parking.py b/bin/do_epic/parking.py index 56005611..66a6c2b6 100644 --- a/bin/do_epic/parking.py +++ b/bin/do_epic/parking.py @@ -21,7 +21,7 @@ class Merged: def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool, based: str | None) -> str | Stop | Merged: - """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. Or Merged, where the chunk's pull request merged and `merged_and_cleaned` removed its worktree, which needs no worker and no running slot. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. + """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. Or Merged, where the chunk's pull request merged and `merged_and_cleaned` removed its worktree: the chunk then needs no worker and no running slot. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can (`Poll.first_gate`), and what the worker must still do is news (`news_after`), unless the pull request merged already and do-epic removes the worktree itself. @@ -150,10 +150,13 @@ class Told: def merged_and_cleaned(poll: Poll, unopened: gates.Unopened) -> Merged | Stop | None: - """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file: Merged where it removed the worktree. None where it didn't, so that the worker decides, as for a pull request closed unmerged. chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files, so a worktree that holds work the merge lacks stays.""" - if isinstance(poll.epic.forge_at(unopened.worktree)(["chunk-pr", "clean"]), Failure): + """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file once the worktree is gone: Merged then. None where the worktree stands, so that its worker decides, as for a pull request closed unmerged. + + chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files. It removes the worktree before it fails on the main checkout (another branch checked out, unsaved files or commits origin lacks), so a failure with the worktree gone still leaves the chunk merged, and its reason is said.""" + cleaned = poll.epic.forge_at(unopened.worktree)(["chunk-pr", "clean"]) + if isinstance(cleaned, Failure) and gates.worktree_of(poll.key, poll.epic.forge_at(poll.loop.root)) is not None: return None - say(f"pull request merged: removed {unopened.worktree}", poll.epic.effects, stdout=True) + say(f"pull request merged: removed {unopened.worktree}" + (f", but {cleaned.reason}" if isinstance(cleaned, Failure) else ""), poll.epic.effects, stdout=True) failed = parked.unpark(poll.folder, poll.key) return Stop(1, failed.reason) if failed else Merged() diff --git a/bin/do_epic/test_gates.py b/bin/do_epic/test_gates.py index 6b7969ee..453786b6 100644 --- a/bin/do_epic/test_gates.py +++ b/bin/do_epic/test_gates.py @@ -28,7 +28,7 @@ def comment(by: str, at: str) -> dict: class Forge: """Stands in for git and the forge's CLI in the checkout and the chunk's worktree; `ran` holds each folder a command ran in. Only the CLI of origin's forge answers: `gh` fails on a Gitea origin, and `tea` on a GitHub one.""" - def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main", merged: bool = False) -> None: + def __init__(self, origin: str = "git@github.com:o/billing.git", pulls: str = f"7\t{HEAD}\tfalse\n", draft: bool = False, decision: str = "REVIEW_REQUIRED", buckets: tuple[str, ...] = ("pass",), threads: tuple[dict, ...] = (), status: str = '{"state": "success", "total_count": 1}', mergeable: str = "MERGEABLE", merge_state: str = "CLEAN", worktrees: str = WORKTREES, fails: str = "", reviews: tuple[dict, ...] = (), comments: tuple[dict, ...] = (), title: str = "Add x", base: str = "main", merged: bool = False, clean_fails: str = "") -> None: self.cli = "gh" if "github.com" in origin else "tea" self.ran: list[str] = [] self.commands: list[list[str]] = [] @@ -39,8 +39,8 @@ class Forge: "git rev-parse": HEAD + "\n", "git symbolic-ref": "origin/main\n", "git config": Failure("git config: unset"), - # chunk-pr removes the worktree only of a pull request the forge reports merged at the worktree's head. - "chunk-pr clean": "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), + # chunk-pr clean fails unless the forge reports the pull request merged at the worktree's head. + "chunk-pr clean": Failure(f"chunk-pr clean: {clean_fails}") if clean_fails else "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), "gh pr list": pulls, "gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state, "baseRefName": base}), "gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]), diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index e6c52793..2d45a71c 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -767,7 +767,7 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): def test_where_a_person_merges_it_parks_on_that_merge_and_works_again_once_merged(self) -> None: self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8") - self.forges = [awaiting(), awaiting(decision="APPROVED"), awaiting(pulls=""), CLEANED] + self.forges = [awaiting(), awaiting(decision="APPROVED"), awaiting(pulls=""), awaiting(pulls=""), CLEANED] fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("unfinished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, out, err, prompts = self.parked_run(fake) self.assertEqual(code, 0, err) @@ -948,8 +948,16 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): self.assertEqual(main.landed_in("api", "ABC-12"), main.Landed.ON_EPIC_BRANCH) self.assertEqual(main.landed_in(None, None), main.Landed.NOWHERE) + def test_a_merged_chunk_whose_clean_failed_after_removing_the_worktree_is_finished_and_the_reason_said(self) -> None: + self.forges = [awaiting(), awaiting(pulls="", clean_fails="its main checkout has uncommitted files"), CLEANED] + fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) + code, out, err, prompts = self.parked_run(fake) + self.assertEqual((code, len(prompts)), (0, 1), err) + self.assertIn("pull request merged: removed /code/api-ABC-20, but chunk-pr clean: its main checkout has uncommitted files\n", out) + self.assertFalse(self.file.exists()) + def test_a_parked_chunk_whose_worktree_chunk_pr_keeps_goes_to_a_worker_as_before(self) -> None: - self.forges = [awaiting(), awaiting(pulls=""), CLEANED] + self.forges = [awaiting(), awaiting(pulls=""), awaiting(pulls=""), CLEANED] fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, _, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 2), err) -- 2.52.0 From 2c5f52e58e5f1a65764da375337b9747fbd2e4a6 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 13:07:27 +0100 Subject: [PATCH 04/10] =?UTF-8?q?Answer=20prose=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(1=20misread);=20reword=20th?= =?UTF-8?q?e=20decision=20and=20the=20README=20sentence=20about=20the=20me?= =?UTF-8?q?rged=20chunk's=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/decisions.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8fa34c3a..62963285 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `epic_run.py` holds what stays the same through one run of do-epic, such as its config, its Jira store and its paths, and starts the chunks that may start now. - `planning.py` settles, before the chunks start, where each open issue is worked, its scores and the order the issues start in, through `split.py`, `repo_pick.py`, `issue_scores.py` and `ranking.py`. - `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. - - `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `parking.py` parks such a chunk after a cycle and polls the gate until its worker has something to do, or until its pull request merged, when it removes the worktree itself with `chunk-pr clean` and finishes the chunk without a worker or a running slot. + - `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `parking.py` parks such a chunk after a cycle and polls the gate until its worker has something to do, or until its pull request merged, when it removes the worktree with `chunk-pr clean` and finishes the chunk itself. - `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. - `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. - `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. diff --git a/docs/decisions.md b/docs/decisions.md index 5514d393..28bd90ad 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -173,7 +173,7 @@ Valid while `~/.claude` is a checkout of this repo. - **Releases.** An epic item has no release. It ships into its repo's unreleased work: where the repo publishes something others consume, a bullet under `CHANGELOG.md` → `## Unreleased`, or nothing where the repo's plan is in Jira. The issue is no item of the repo's plan, so the chunk's worker writes the bullet in its branch and runs `chunk-pr merge` without `--finish`. - **Repos.** A repo's name is its main checkout's folder name, and a project config names that checkout. A missing checkout is cloned from the host of the epic's other repos; where unsure, do-epic asks. Unsure means the other repos don't all sit under one host and owner (the same host spelt as https and as ssh counts as two), an origin can't be read or isn't an https, ssh or scp-style address, the folder to clone into holds something else, or the clone fails. A repo no config names is cloned into the clone folder, and the human is asked to write its config. Each chunk uses its repo's model, routing, and language for commits and PRs. Jira text is in the epic's language, or else the machine's default. - **Running.** The epic caps the chunks running at once, and each repo's `parallel-chunks` still applies. do-epic and loop-claude never run chunks in the same repo at once. The cap is a line of the epic's description, `**Max parallel chunks:** 2`, and 1 without it, as `parallel-chunks` is. A repo's `parallel-chunks` counts the chunks of every epic in its checkout. Each window is named for its issue's key, and a tmux window option, `@chunk-root`, names the folder its chunk works in, which is how loop-claude sees do-epic's chunks in a checkout. do-epic and loop-claude each hold the checkout's `starting` lock from checking the checkout's chunks to starting a window there. A chunk without a repo works in `~/.local/state/do-epic//`. do-epic archives its cycles under `~/.claude/do-epic-transcripts/`, not in loop-claude's archive, whose readers parse loop-claude's prompts. An open issue runs once a label records its repo; until do-epic picks repos itself, an issue without one waits, and `do-epic ` says so. -- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic ` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits. In a repo whose config sets `merge = "human"`, the merge itself is a gate: `chunk-pr merge` leaves the pull request ready, the chunk parks on `your merge` once nothing else holds the pull request, and it resumes when the forge no longer reports the pull request open, to clean up and finish. It resumes too once the pull request conflicts with its base branch, or is behind it where GitHub's branch protection requires an up-to-date branch, so the person finds a pull request they can merge. The worker then runs `chunk-pr merge` again, which levels the branch, waits for the checks and leaves the pull request ready. A chunk whose cycle ends on such a pull request is not handed on: its worker is told after each cycle until the pull request merges into its base. While GitHub still computes whether the pull request merges, the chunk stays parked until the next read. Gitea also reports a pull request as not mergeable for the seconds it checks for conflicts. A read in those seconds resumes the chunk for a run that doesn't change anything, which costs less than reading every gate twice to tell the two apart. The judge may rule such a chunk finished while its pull request is open, since its worker ends each run there. So do-epic reads a gate it could not read again before it hands the chunk on, and removes a worktree whose pull request is no longer open itself, with `chunk-pr clean`, which acts only on a pull request the forge reports merged at the worktree's head and on a worktree without uncommitted or untracked files: the chunk then finishes without a worker and, where it was parked, without a running slot. Where `chunk-pr clean` refuses, as for a pull request closed unmerged, it tells the worker once to remove the worktree, and a parked chunk waits for a slot as for any other news. +- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic ` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits. In a repo whose config sets `merge = "human"`, the merge itself is a gate: `chunk-pr merge` leaves the pull request ready, the chunk parks on `your merge` once nothing else holds the pull request, and it resumes when the forge no longer reports the pull request open, so that its worktree is removed and the chunk finishes. It resumes too once the pull request conflicts with its base branch, or is behind it where GitHub's branch protection requires an up-to-date branch, so the person finds a pull request they can merge. The worker then runs `chunk-pr merge` again, which levels the branch, waits for the checks and leaves the pull request ready. A chunk whose cycle ends on such a pull request is not handed on: its worker is told after each cycle until the pull request merges into its base. While GitHub still computes whether the pull request merges, the chunk stays parked until the next read. Gitea also reports a pull request as not mergeable for the seconds it checks for conflicts. A read in those seconds resumes the chunk for a run that doesn't change anything, which costs less than reading every gate twice to tell the two apart. The judge may rule such a chunk finished while its pull request is open, since its worker ends each run there. So do-epic reads a gate it could not read again before it hands the chunk on, and does the removal itself where it can. For a chunk whose pull request is no longer open, do-epic runs `chunk-pr clean` in the chunk's worktree. That command acts only on a pull request the forge reports merged at the worktree's head, and refuses a worktree with uncommitted or untracked files. Where it removed the worktree, the chunk finishes without a worker and, where it was parked, without a running slot, even if the command then failed on the main checkout, whose reason do-epic says. Where it left the worktree, as for a pull request closed unmerged, do-epic tells the worker once to remove it, and a parked chunk waits for a slot as for any other news. - **Human tasks.** do-epic leaves a human task's issue as the team filed it. The task gets a window of its own while it is open, no issue blocks it, and it blocks another open issue. The window DMs the human once, through the notifier of the first repo whose project config names one (the repos of the issues it holds up come first, then those of the epic's other issues; where none does, the window says so), shows as parked (`awaits a human's task`) so that it doesn't take a running slot, and polls the epic every minute until the task no longer holds up an open issue. Then the issues it held up may start. A window that starts again, as after a reboot, DMs again. - **Findings.** A finding about the epic's goals is filed in the epic. A finding about a repo's goals follows that repo's rules. Where unsure which, do-epic asks. A set of new items toward an epic goal needs the human's approval before work starts; a finding filed during a chunk doesn't. - **Finishing.** When the epic holds no open item: release-review passes on each repo the epic changed, then the items they file, then the human confirms each achieve goal and that no maintain goal has a defect. For a goal that isn't met, do-epic proposes items for approval. Then a summary comment on the epic, and closing the epic in Jira, as the very last step. -- 2.52.0 From e8ab4ef9d81cd1924cba0ee0f090040ad8d4bbe3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 13:25:03 +0100 Subject: [PATCH 05/10] Test the merged-chunk cleanup where the mutation tool reaches it --- bin/do_epic/test_landed.py | 22 +++++++++++++ bin/do_epic/test_main.py | 24 +++++++++++--- bin/do_epic/test_parking.py | 62 +++++++++++++++++++++++++++++++++++-- 3 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 bin/do_epic/test_landed.py diff --git a/bin/do_epic/test_landed.py b/bin/do_epic/test_landed.py new file mode 100644 index 00000000..724af9f4 --- /dev/null +++ b/bin/do_epic/test_landed.py @@ -0,0 +1,22 @@ +import pathlib +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from do_epic.main import Landed, landed_in + + +class WhereTheWorkOfAFinishedChunkLanded(unittest.TestCase): + def test_it_landed_on_the_epics_working_branch_where_the_chunk_has_one(self) -> None: + self.assertEqual(landed_in("api", "ABC-12"), Landed.ON_EPIC_BRANCH) + + def test_it_landed_on_the_default_branch_of_a_repo_without_one(self) -> None: + self.assertEqual(landed_in("api", None), Landed.ON_DEFAULT_BRANCH) + + def test_a_chunk_without_a_repo_landed_nowhere(self) -> None: + self.assertEqual(landed_in(None, None), Landed.NOWHERE) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index 2d45a71c..e65a9e5e 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -943,11 +943,6 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): self.assertIn("pull request merged: removed /code/api-ABC-20\n", out) self.assertIn("Permission denied", err) - def test_the_work_of_a_finished_chunk_landed_where_its_repo_and_working_branch_say(self) -> None: - self.assertEqual(main.landed_in("api", None), main.Landed.ON_DEFAULT_BRANCH) - self.assertEqual(main.landed_in("api", "ABC-12"), main.Landed.ON_EPIC_BRANCH) - self.assertEqual(main.landed_in(None, None), main.Landed.NOWHERE) - def test_a_merged_chunk_whose_clean_failed_after_removing_the_worktree_is_finished_and_the_reason_said(self) -> None: self.forges = [awaiting(), awaiting(pulls="", clean_fails="its main checkout has uncommitted files"), CLEANED] fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) @@ -956,6 +951,25 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): self.assertIn("pull request merged: removed /code/api-ABC-20, but chunk-pr clean: its main checkout has uncommitted files\n", out) self.assertFalse(self.file.exists()) + def test_where_the_teams_automation_moves_issues_a_merged_parked_chunk_waits_for_the_move_as_a_finished_one_does(self) -> None: + (self.home / ".claude-projects" / "do-epic" / "config.toml").write_text(SETTINGS + 'jira-unblocking-statuses = ["Release Ready", "Shipped"]\njira-automation-moves-issues = true\n', encoding="utf-8") + store = MemoryEpic("ABC-12", [*self.issues[:-1], issue("ABC-22", "do-epic-claude", blockers=("ABC-20",))]) + self.backend = lambda config, key: (store, EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type] + self.forges = [awaiting(), awaiting(pulls="", merged=True)] + fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) + slept: list[float] = [] + + def sleep(seconds: float) -> None: + slept.append(seconds) + if len(slept) == 3: + store.change("ABC-20", status="Release Ready") + fake.effects = lambda made=fake.effects(): dataclasses.replace(made, sleep=sleep) # type: ignore[method-assign] + code, out, err, prompts = self.parked_run(fake) + self.assertEqual((code, len(prompts)), (0, 1), err) + self.assertEqual([(each.status, each.done) for each in store.issues if each.key == "ABC-20"], [("Release Ready", False)]) + self.assertIn("ABC-20 is To Do: it waits for the team's automation to move it to Release Ready or Shipped", out) + self.assertIn("the chunk finished; started ABC-22\n", out) + def test_a_parked_chunk_whose_worktree_chunk_pr_keeps_goes_to_a_worker_as_before(self) -> None: self.forges = [awaiting(), awaiting(pulls=""), awaiting(pulls=""), CLEANED] fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) diff --git a/bin/do_epic/test_parking.py b/bin/do_epic/test_parking.py index 714c8fd2..912705fa 100644 --- a/bin/do_epic/test_parking.py +++ b/bin/do_epic/test_parking.py @@ -1,13 +1,19 @@ +import contextlib +import io import pathlib import sys +import tempfile +import types import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from do_epic import chunk_prompt +from do_epic import chunk_prompt, parked from failure import Failure -from do_epic.parking import news_after +from loop_effects.doubles import FakeEffects +from do_epic.parking import Merged, merged_and_cleaned, news_after, Poll from do_epic.gates import Open, Unmergeable, Unopened +from agent_cycle.stop import Stop UNOPENED = Unopened("no pull request is open", "/code/api-ABC-20") UNCLEANED = f"{chunk_prompt.DRIVER} keeps the chunk open while its worktree stands: no pull request is open." @@ -40,5 +46,57 @@ class TheNewsOfAChunkThatIsNotParked(unittest.TestCase): self.assertEqual(news_after(UNMERGEABLE, finished=True, by_human=True, told=UNLEVELLED), UNLEVELLED) +class TheCleanupOfAChunkWhosePullRequestIsNoLongerOpen(unittest.TestCase): + def setUp(self) -> None: + made = tempfile.TemporaryDirectory() + self.addCleanup(made.cleanup) + self.folder = pathlib.Path(made.name) + parked.park(self.folder, parked.Parked("ABC-20", "/code/api-ABC-20", "7", "session", "your merge")) + self.ran: list[tuple[str, list[str]]] = [] + self.clean: str | Failure = "" + # What `git worktree list` says once chunk-pr clean ran. + self.listed = "worktree /code/api\nbranch refs/heads/main\n" + effects = FakeEffects().effects() + self.poll = Poll("ABC-20", "api", True, self.folder, types.SimpleNamespace(root="/code/api"), types.SimpleNamespace(effects=effects, forge_at=self.forge_at)) # type: ignore[arg-type] + + def forge_at(self, folder: str): + def run(command: list[str]) -> str | Failure: + self.ran.append((folder, command)) + return self.clean if command[0] == "chunk-pr" else self.listed + return run + + def cleaned(self) -> tuple[Merged | Stop | None, str]: + out = io.StringIO() + with contextlib.redirect_stdout(out): + return merged_and_cleaned(self.poll, UNOPENED), out.getvalue() + + def test_a_clean_that_removed_the_worktree_finishes_the_chunk_and_unparks_it(self) -> None: + done, out = self.cleaned() + self.assertEqual(done, Merged()) + self.assertIn(" pull request merged: removed /code/api-ABC-20\n", out) + self.assertEqual(self.ran[0], ("/code/api-ABC-20", ["chunk-pr", "clean"])) + self.assertEqual(parked.parked_chunks(self.folder), {}) + + def test_a_clean_that_failed_with_the_worktree_standing_leaves_the_chunk_to_its_worker(self) -> None: + self.clean = Failure("chunk-pr clean: no merged pull request") + self.listed = "worktree /code/api\nbranch refs/heads/main\n\nworktree /code/api-ABC-20\nbranch refs/heads/ABC-20\n" + done, out = self.cleaned() + self.assertEqual((done, out), (None, "")) + self.assertEqual(self.ran[1], ("/code/api", ["git", "worktree", "list", "--porcelain"])) + self.assertEqual(list(parked.parked_chunks(self.folder)), ["ABC-20"]) + + def test_a_clean_that_failed_after_removing_the_worktree_finishes_the_chunk_and_says_why(self) -> None: + self.clean = Failure("chunk-pr clean: its main checkout has uncommitted files") + done, out = self.cleaned() + self.assertEqual(done, Merged()) + self.assertIn(" pull request merged: removed /code/api-ABC-20, but chunk-pr clean: its main checkout has uncommitted files\n", out) + + def test_a_parked_file_that_cannot_be_removed_stops_the_loop(self) -> None: + self.folder.joinpath(parked.FOLDER).chmod(0o555) + self.addCleanup(lambda: self.folder.joinpath(parked.FOLDER).chmod(0o755)) + done, _ = self.cleaned() + self.assertEqual(done, Stop(1, f"cannot remove {parked.file_of(self.folder, 'ABC-20')}: Permission denied")) + + if __name__ == "__main__": unittest.main() -- 2.52.0 From 57fef64105f5b764f36dcc1bbda254352081c495 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 14:02:59 +0100 Subject: [PATCH 06/10] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(1=20misread);=20run=20chunk?= =?UTF-8?q?-pr=20by=20its=20path,=20say=20why=20a=20clean=20left=20the=20w?= =?UTF-8?q?orktree,=20test=20the=20working-branch=20move?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/do_epic/parking.py | 27 ++++++++++++++++++--------- bin/do_epic/test_gates.py | 3 ++- bin/do_epic/test_main.py | 18 ++++++++++++++---- bin/do_epic/test_parking.py | 14 ++++++++++---- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/bin/do_epic/parking.py b/bin/do_epic/parking.py index 66a6c2b6..b63f8cf6 100644 --- a/bin/do_epic/parking.py +++ b/bin/do_epic/parking.py @@ -7,12 +7,15 @@ from do_epic.epic_run import chunks_started, EpicRun, POLL_SECONDS, scheduled_ep from project_config.main import located as config_located from failure import Failure from chunk_driver.this_loop import Loop +from loop_state.paths import RELEASE_ROOT from loop_effects.effects import say from agent_cycle.stop import Stop from agent_cycle import tmux # How the news for a chunk that was parked opens. DRIVER_PARKED = f"{chunk_prompt.DRIVER} parked the chunk while" +# do-epic's PATH holds only what its user linked there, so chunk-pr is run by its path. +CHUNK_PR = str(RELEASE_ROOT / "bin" / "chunk-pr") @dataclasses.dataclass(frozen=True) @@ -39,8 +42,11 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finis if key in recorded_as: return resumed_news(poll, recorded_as[key].on, shown=None) entered = None if told is None else poll.first_gate(again=finished) - if finished and poll.by_human and isinstance(entered, gates.Unopened) and (done := merged_and_cleaned(poll, entered)): - return done + if finished and poll.by_human and isinstance(entered, gates.Unopened): + left = merged_and_cleaned(poll, entered) + if not isinstance(left, gates.Unopened): + return left + entered = left if not isinstance(entered, gates.Gate): if isinstance(entered, Failure): say(f"cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: {entered.reason}", epic.effects, stdout=True) @@ -115,8 +121,11 @@ def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop | Merged: while True: now = poll.gate() if isinstance(now, gates.Open): - if isinstance(now, gates.Unopened) and (done := merged_and_cleaned(poll, now)): - return done + if isinstance(now, gates.Unopened): + left = merged_and_cleaned(poll, now) + if not isinstance(left, gates.Unopened): + return left + now = left full = resumed(poll.repo, poll.loop, poll.epic) if full is None: return unparked(poll, on, now) @@ -149,13 +158,13 @@ class Told: self.reason = reason -def merged_and_cleaned(poll: Poll, unopened: gates.Unopened) -> Merged | Stop | None: - """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file once the worktree is gone: Merged then. None where the worktree stands, so that its worker decides, as for a pull request closed unmerged. +def merged_and_cleaned(poll: Poll, unopened: gates.Unopened) -> Merged | Stop | gates.Unopened: + """Runs `chunk-pr clean` in the worktree of a chunk whose pull request is no longer open, and removes the chunk's file once the worktree is gone: Merged then. Where the worktree stands, so that its worker decides, as for a pull request closed unmerged: unopened, its news adding why chunk-pr left it. - chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files. It removes the worktree before it fails on the main checkout (another branch checked out, unsaved files or commits origin lacks), so a failure with the worktree gone still leaves the chunk merged, and its reason is said.""" - cleaned = poll.epic.forge_at(unopened.worktree)(["chunk-pr", "clean"]) + chunk-pr acts only on a pull request the forge reports merged at the commit checked out, and refuses a worktree with uncommitted or untracked files. It removes the worktree before it fails on the main checkout (another branch checked out, uncommitted or untracked files, or commits origin lacks), so a failure with the worktree gone still leaves the chunk merged, and its reason is said.""" + cleaned = poll.epic.forge_at(unopened.worktree)([CHUNK_PR, "clean"]) if isinstance(cleaned, Failure) and gates.worktree_of(poll.key, poll.epic.forge_at(poll.loop.root)) is not None: - return None + return dataclasses.replace(unopened, news=f"{unopened.news}; {cleaned.reason}") say(f"pull request merged: removed {unopened.worktree}" + (f", but {cleaned.reason}" if isinstance(cleaned, Failure) else ""), poll.epic.effects, stdout=True) failed = parked.unpark(poll.folder, poll.key) return Stop(1, failed.reason) if failed else Merged() diff --git a/bin/do_epic/test_gates.py b/bin/do_epic/test_gates.py index 453786b6..d735eec1 100644 --- a/bin/do_epic/test_gates.py +++ b/bin/do_epic/test_gates.py @@ -6,6 +6,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from do_epic.gates import APPROVAL, CHECKS, gate, Gate, MERGE, NEW_REVIEW, Open, Unmergeable, Unopened +from do_epic.parking import CHUNK_PR from failure import Failure WORKTREES = "worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n\nworktree /code/billing-ABC-21\nHEAD abc\nbranch refs/heads/ABC-21\n" @@ -40,7 +41,7 @@ class Forge: "git symbolic-ref": "origin/main\n", "git config": Failure("git config: unset"), # chunk-pr clean fails unless the forge reports the pull request merged at the worktree's head. - "chunk-pr clean": Failure(f"chunk-pr clean: {clean_fails}") if clean_fails else "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), + f"{CHUNK_PR} clean": Failure(f"chunk-pr clean: {clean_fails}") if clean_fails else "" if merged else Failure("chunk-pr clean: no merged pull request, so its worktree and branch stay"), "gh pr list": pulls, "gh pr view": json.dumps({"isDraft": draft, "reviewDecision": decision, "author": {"login": "worker"}, "reviews": list(reviews), "comments": list(comments), "mergeable": mergeable, "mergeStateStatus": merge_state, "baseRefName": base}), "gh pr checks": json.dumps([{"bucket": bucket} for bucket in buckets]), diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index e65a9e5e..0c13cb5f 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -12,6 +12,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) +from do_epic.parking import CHUNK_PR from do_epic import chunk_prompt, epic_run, main, planning from chunk_driver.chunk_run import ChunkRun from project_config.doubles import configured @@ -927,8 +928,8 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW + "ABC-22\t0\t@10\n") code, out, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 1), err) - self.assertEqual(self.forges[1].commands.count(["chunk-pr", "clean"]), 1) - self.assertEqual({folder for folder, command in zip(self.forges[1].ran, self.forges[1].commands) if command[0] == "chunk-pr"}, {"/code/api-ABC-20"}) + self.assertEqual(self.forges[1].commands.count([CHUNK_PR, "clean"]), 1) + self.assertEqual({folder for folder, command in zip(self.forges[1].ran, self.forges[1].commands) if command[0] == CHUNK_PR}, {"/code/api-ABC-20"}) self.assertFalse(self.file.exists()) self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval"]) self.assertIn("the chunk finished; ", out) @@ -975,7 +976,7 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, _, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 2), err) - self.assertEqual(self.forges[1].commands.count(["chunk-pr", "clean"]), 1) + self.assertEqual(self.forges[1].commands.count([CHUNK_PR, "clean"]), 1) self.assertIn("no pull request from origin's ABC-20 is open", prompts[1].split("\n\n")[0]) def test_where_a_person_merged_before_the_cycle_closed_a_finished_chunk_is_cleaned_by_do_epic(self) -> None: @@ -984,7 +985,7 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest): fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW) code, out, err, prompts = self.parked_run(fake) self.assertEqual((code, len(prompts)), (0, 1), err) - self.assertEqual(self.forges[0].commands.count(["chunk-pr", "clean"]), 1) + self.assertEqual(self.forges[0].commands.count([CHUNK_PR, "clean"]), 1) self.assertIn("the chunk finished; ", out) def test_a_chunk_parks_and_resumes_though_the_next_chunk_cannot_start(self) -> None: @@ -1198,6 +1199,15 @@ class AnEpicsWorkingBranch(DoEpicTest): self.assertIn("The chunk's pull request goes into the epic's working branch `ABC-12`", prompts[0]) self.assertIn(("config", "branch.ABC-20.chunk-base", "ABC-12"), [args for args, _ in self.git_calls]) + def test_a_parked_chunk_whose_pull_request_merged_into_the_branch_gets_its_issue_moved_by_do_epic_as_no_automation_does_it(self) -> None: + self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-automation-moves-issues = true\njira-pull-request-open-status = "Code Review"\njira-pull-request-merged-status = "Release Ready"\n') + self.forges = [self.recorded(base="ABC-12"), self.recorded(base="ABC-12", pulls="", merged=True)] + fake = self.with_git(FakeEffects(streams=[self.worker()], claude=[judged("finished")], windows=PARKED_WINDOW)) + code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS) + self.assertEqual(code, 0, err) + self.assertIn("pull request merged: removed /code/api-ABC-20\n", out) + self.assertEqual([write for write in self.store.writes if write.startswith("move ")], ["move ABC-20 to Code Review", "move ABC-20 to Release Ready"]) + def test_a_chunk_parked_on_a_persons_merge_into_the_default_branch_stays_parked_until_its_pull_request_goes_into_the_branch(self) -> None: self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n') session = main.session_named("A ABC-12 do-epic ABC-20", paths_from(self.home).claude_code_transcripts) diff --git a/bin/do_epic/test_parking.py b/bin/do_epic/test_parking.py index 912705fa..0cca3b48 100644 --- a/bin/do_epic/test_parking.py +++ b/bin/do_epic/test_parking.py @@ -1,5 +1,6 @@ import contextlib import io +import os import pathlib import sys import tempfile @@ -8,6 +9,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) +from do_epic.parking import CHUNK_PR from do_epic import chunk_prompt, parked from failure import Failure from loop_effects.doubles import FakeEffects @@ -62,26 +64,30 @@ class TheCleanupOfAChunkWhosePullRequestIsNoLongerOpen(unittest.TestCase): def forge_at(self, folder: str): def run(command: list[str]) -> str | Failure: self.ran.append((folder, command)) - return self.clean if command[0] == "chunk-pr" else self.listed + return self.clean if command[0] == CHUNK_PR else self.listed return run - def cleaned(self) -> tuple[Merged | Stop | None, str]: + def cleaned(self) -> tuple[Merged | Stop | Unopened, str]: out = io.StringIO() with contextlib.redirect_stdout(out): return merged_and_cleaned(self.poll, UNOPENED), out.getvalue() + def test_chunk_pr_is_run_by_a_path_that_exists_since_do_epics_path_does_not_hold_it(self) -> None: + path = pathlib.Path(CHUNK_PR) + self.assertTrue(path.is_absolute() and path.is_file() and os.access(path, os.X_OK), CHUNK_PR) + def test_a_clean_that_removed_the_worktree_finishes_the_chunk_and_unparks_it(self) -> None: done, out = self.cleaned() self.assertEqual(done, Merged()) self.assertIn(" pull request merged: removed /code/api-ABC-20\n", out) - self.assertEqual(self.ran[0], ("/code/api-ABC-20", ["chunk-pr", "clean"])) + self.assertEqual(self.ran[0], ("/code/api-ABC-20", [CHUNK_PR, "clean"])) self.assertEqual(parked.parked_chunks(self.folder), {}) def test_a_clean_that_failed_with_the_worktree_standing_leaves_the_chunk_to_its_worker(self) -> None: self.clean = Failure("chunk-pr clean: no merged pull request") self.listed = "worktree /code/api\nbranch refs/heads/main\n\nworktree /code/api-ABC-20\nbranch refs/heads/ABC-20\n" done, out = self.cleaned() - self.assertEqual((done, out), (None, "")) + self.assertEqual((done, out), (Unopened("no pull request is open; chunk-pr clean: no merged pull request", "/code/api-ABC-20"), "")) self.assertEqual(self.ran[1], ("/code/api", ["git", "worktree", "list", "--porcelain"])) self.assertEqual(list(parked.parked_chunks(self.folder)), ["ABC-20"]) -- 2.52.0 From fc0a1acbaf4247b1224797a62dd4c3ddb815de73 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 14:02:59 +0100 Subject: [PATCH 07/10] =?UTF-8?q?Answer=20prose=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20the=20gate?= =?UTF-8?q?=20is=20read=20again,=20not=20resumed,=20and=20name=20the=20fil?= =?UTF-8?q?es=20chunk-pr=20refuses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/do_epic/main.py | 2 +- docs/decisions.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index c7df8282..ab1ba1a7 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -67,7 +67,7 @@ A chunk whose worker ends its run while its pull request waits on its checks, an is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull -request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place. Where it cannot, as for a pull request closed unmerged or a worktree with unsaved files, the worker goes on once a place is free. A parked chunk survives a reboot: run do-epic again to go on polling. +request is ready, with nothing else to wait on, the window's name says `awaits your merge`. Once you merged it, do-epic removes the chunk's worktree with `chunk-pr clean` and finishes the chunk, without a worker or a place. Where it cannot, as for a pull request closed unmerged or a worktree with uncommitted or untracked files, the worker goes on once a place is free. A parked chunk survives a reboot: run do-epic again to go on polling. --status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when. --dry-run runs the planning and the scheduling against the epic as Jira holds it. It doesn't write anything to Jira, start a window or ask a question, and it doesn't start any issue in Jira as a real run's chunk does. It prints each label, sub-task, comment, score and rank move that planning would write, each move of a parent issue whose sub-tasks a person filed, the order the issues would start in, each chunk that would start and why each other issue waits. A sub-task not yet filed shows a key such as ABC-new1. A question planning would ask is printed instead of asked. Planning's claude calls still run. A repo that is missing isn't cloned. Planning then stops there, so its writes are only those made before it, and the issues of that repo wait, and a chunk of another repo may start in the place a real run gives them; a real run would clone it and go on. diff --git a/docs/decisions.md b/docs/decisions.md index 28bd90ad..b5e254cb 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -173,7 +173,7 @@ Valid while `~/.claude` is a checkout of this repo. - **Releases.** An epic item has no release. It ships into its repo's unreleased work: where the repo publishes something others consume, a bullet under `CHANGELOG.md` → `## Unreleased`, or nothing where the repo's plan is in Jira. The issue is no item of the repo's plan, so the chunk's worker writes the bullet in its branch and runs `chunk-pr merge` without `--finish`. - **Repos.** A repo's name is its main checkout's folder name, and a project config names that checkout. A missing checkout is cloned from the host of the epic's other repos; where unsure, do-epic asks. Unsure means the other repos don't all sit under one host and owner (the same host spelt as https and as ssh counts as two), an origin can't be read or isn't an https, ssh or scp-style address, the folder to clone into holds something else, or the clone fails. A repo no config names is cloned into the clone folder, and the human is asked to write its config. Each chunk uses its repo's model, routing, and language for commits and PRs. Jira text is in the epic's language, or else the machine's default. - **Running.** The epic caps the chunks running at once, and each repo's `parallel-chunks` still applies. do-epic and loop-claude never run chunks in the same repo at once. The cap is a line of the epic's description, `**Max parallel chunks:** 2`, and 1 without it, as `parallel-chunks` is. A repo's `parallel-chunks` counts the chunks of every epic in its checkout. Each window is named for its issue's key, and a tmux window option, `@chunk-root`, names the folder its chunk works in, which is how loop-claude sees do-epic's chunks in a checkout. do-epic and loop-claude each hold the checkout's `starting` lock from checking the checkout's chunks to starting a window there. A chunk without a repo works in `~/.local/state/do-epic//`. do-epic archives its cycles under `~/.claude/do-epic-transcripts/`, not in loop-claude's archive, whose readers parse loop-claude's prompts. An open issue runs once a label records its repo; until do-epic picks repos itself, an issue without one waits, and `do-epic ` says so. -- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic ` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits. In a repo whose config sets `merge = "human"`, the merge itself is a gate: `chunk-pr merge` leaves the pull request ready, the chunk parks on `your merge` once nothing else holds the pull request, and it resumes when the forge no longer reports the pull request open, so that its worktree is removed and the chunk finishes. It resumes too once the pull request conflicts with its base branch, or is behind it where GitHub's branch protection requires an up-to-date branch, so the person finds a pull request they can merge. The worker then runs `chunk-pr merge` again, which levels the branch, waits for the checks and leaves the pull request ready. A chunk whose cycle ends on such a pull request is not handed on: its worker is told after each cycle until the pull request merges into its base. While GitHub still computes whether the pull request merges, the chunk stays parked until the next read. Gitea also reports a pull request as not mergeable for the seconds it checks for conflicts. A read in those seconds resumes the chunk for a run that doesn't change anything, which costs less than reading every gate twice to tell the two apart. The judge may rule such a chunk finished while its pull request is open, since its worker ends each run there. So do-epic reads a gate it could not read again before it hands the chunk on, and does the removal itself where it can. For a chunk whose pull request is no longer open, do-epic runs `chunk-pr clean` in the chunk's worktree. That command acts only on a pull request the forge reports merged at the worktree's head, and refuses a worktree with uncommitted or untracked files. Where it removed the worktree, the chunk finishes without a worker and, where it was parked, without a running slot, even if the command then failed on the main checkout, whose reason do-epic says. Where it left the worktree, as for a pull request closed unmerged, do-epic tells the worker once to remove it, and a parked chunk waits for a slot as for any other news. +- **Long gates.** A chunk whose PR waits on a gate, such as a human approval, parks. It keeps its worktree, PR and session, and its state is in a file that survives a reboot. A parked chunk takes no running slot, and the items it blocks wait. do-epic polls the forge and resumes the chunk's session when the gate passes or a reviewer comments. It fixes reasonable feedback, replies to the rest, and changes the setup so review would have caught it. `do-epic --status` and the tmux window names show what each chunk waits on. A gate is a pull request's pending checks or, on GitHub, the approval its branch protection requires; a draft waits on neither, since its worker has yet to mark it ready. On Gitea a draft is a pull request whose title opens with `WIP:` or `[WIP]`, Gitea's default `WORK_IN_PROGRESS_PREFIXES`. Changes a reviewer requested resume the chunk only while that review was made on the pull request's head commit and the pull request's author has not commented or replied after it; once the worker pushed or replied, the chunk parks on a new review, since GitHub keeps the decision until the reviewer reviews again. The chunk's window reads the forge once a minute, which no forge's rate limit notices. A chunk resumes only into a free slot, under the limits a starting chunk meets, and stays parked until then. `do-epic ` starts a parked chunk's window again whatever the limits, since the chunk stays parked. do-epic sets `CHUNK_PR_PARKS=1` for each worker, so `chunk-pr merge` fails at once where the pull request awaits an approval, and the worker's run doesn't hold a slot while the pull request waits. In a repo whose config sets `merge = "human"`, the merge itself is a gate: `chunk-pr merge` leaves the pull request ready, the chunk parks on `your merge` once nothing else holds the pull request, and it gets its gate read again when the forge no longer reports the pull request open, so that its worktree is removed and the chunk finishes. It resumes too once the pull request conflicts with its base branch, or is behind it where GitHub's branch protection requires an up-to-date branch, so the person finds a pull request they can merge. The worker then runs `chunk-pr merge` again, which levels the branch, waits for the checks and leaves the pull request ready. A chunk whose cycle ends on such a pull request is not handed on: its worker is told after each cycle until the pull request merges into its base. While GitHub still computes whether the pull request merges, the chunk stays parked until the next read. Gitea also reports a pull request as not mergeable for the seconds it checks for conflicts. A read in those seconds resumes the chunk for a run that doesn't change anything, which costs less than reading every gate twice to tell the two apart. The judge may rule such a chunk finished while its pull request is open, since its worker ends each run there. So do-epic reads a gate it could not read again before it hands the chunk on, and does the removal itself where it can. For a chunk whose pull request is no longer open, do-epic runs `chunk-pr clean` in the chunk's worktree. That command acts only on a pull request the forge reports merged at the worktree's head, and refuses a worktree with uncommitted or untracked files. Where it removed the worktree, the chunk finishes without a worker and, where it was parked, without a running slot, even if the command then failed on the main checkout, whose reason do-epic says. Where it left the worktree, as for a pull request closed unmerged, do-epic tells the worker once to remove it, and a parked chunk waits for a slot as for any other news. - **Human tasks.** do-epic leaves a human task's issue as the team filed it. The task gets a window of its own while it is open, no issue blocks it, and it blocks another open issue. The window DMs the human once, through the notifier of the first repo whose project config names one (the repos of the issues it holds up come first, then those of the epic's other issues; where none does, the window says so), shows as parked (`awaits a human's task`) so that it doesn't take a running slot, and polls the epic every minute until the task no longer holds up an open issue. Then the issues it held up may start. A window that starts again, as after a reboot, DMs again. - **Findings.** A finding about the epic's goals is filed in the epic. A finding about a repo's goals follows that repo's rules. Where unsure which, do-epic asks. A set of new items toward an epic goal needs the human's approval before work starts; a finding filed during a chunk doesn't. - **Finishing.** When the epic holds no open item: release-review passes on each repo the epic changed, then the items they file, then the human confirms each achieve goal and that no maintain goal has a defect. For a goal that isn't met, do-epic proposes items for approval. Then a summary comment on the epic, and closing the epic in Jira, as the very last step. -- 2.52.0 From cb3255bb1279172dc17034f2cda84b6717ff7e5f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 14:02:59 +0100 Subject: [PATCH 08/10] =?UTF-8?q?Answer=20product-owner=20round=202:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20approved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From e3531f279139e0c8ddf119c666313f8408522d8d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 14:27:28 +0100 Subject: [PATCH 09/10] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20approved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From aae456240adda7226ce51b87b005e3f8639c52c1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 3 Dec 2026 14:33:17 +0100 Subject: [PATCH 10/10] Finish item 561 in the plan --- CHANGELOG.md | 1 + todo.md | 17 ----------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d04770..935b6179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- do-epic runs `chunk-pr clean` itself for a chunk whose pull request merged, finishes the chunk and closes its window, without a running slot or a worker, where it used to wait for a free slot and a worker for that. - Make `task-bench` commit the copy it runs each side's tests in, so a project's tests that call git, such as `git ls-files`, pass the baseline instead of failing with "not a git repository". - The review sweep before each round now also runs each builtin, flag or option a change adds with a value just outside each input range its docs state, and the product-owner reviewer flags a doc line that leaves out what that run printed. - larv-review fetches each web page that a changed prose claim cites as its source and hands the page to the prose reviewer, which has no web access, so it checks the claim against the page instead of marking it ❓. diff --git a/todo.md b/todo.md index 50b0a0e0..354dcfb9 100644 --- a/todo.md +++ b/todo.md @@ -22,7 +22,6 @@ | 577 | 0.18.0 | 483, 486, 575 | owner | **Test in the gate that a container holding only a stock Claude Code runs a chunk from a clone, against a mock Messages API, and that the run leaves the container's own `~/.claude` as it was.** | 3 | 1 | 2 | 4 | 6 | 3 by 9, 2 by 5 | 5.2 | | 576 | 0.18.0 | 485, 575 | owner | **Name the project `dev-factory` in the README, the prose and the tools, and say in the changelog that the repo moved.** | 2 | 2 | 2 | 4 | 4 | 2 by 1, 6 by 1 | 0.4 | | 578 | 0.18.0 | 576, 577 | owner | **Ship one chunk of this repo, to a merged pull request, from a clone of `main` that runs in the generated home, beside the untouched `~/.claude`.** | 1 | 2 | 1 | 2 | 1 | 2 by 4 | 1.2 | -| 561 | 0.18.0 | | | **Clean up a do-epic chunk whose pull request has merged without waiting for a running slot, and close its window.** | 2 | 2 | 2 | 4 | 3 | 1.5 by 2 | 0.5 | | 487 | 0.20.0 | 483 | owner | **Run larv-review's passes from a program that picks them from the diff and the item, counts rounds against the cap and decides each rerun, with each reviewer returning its findings as JSON against a schema.** | 4 | 2 | 3 | 7 | 8 | 1.1 by 5, 1.4 by 5 | 0.4 | | 498 | 0.20.0 | 487 | owner | **Drive each chunk as a state machine in `build-release`, from preflight through implementing, review, the pull request and the merge to finishing its items, with the worker as one model step that ends in a result that code checks.** | 4 | 2 | 3 | 7 | 8 | 1.1 by 4, 1.4 by 4 | 0.3 | | 488 | 0.20.0 | 498 | owner | **Cut the larv-review skill, `CLAUDE.md` and rule-hook down to what `build-release` doesn't own: the judgement the model makes and the safety guards.** | 2 | 2 | 3 | 5 | 5 | 1.4 by 4, code health by 2 | 2.3 | @@ -641,22 +640,6 @@ Touches: - `README.md` -### 561. Clean up a do-epic chunk whose pull request has merged without waiting for a running slot, and close its window. - -Today a parked chunk whose pull request is no longer open (`gates.Unopened`, `bin/do_epic/gates.py`) gets news for its worker to remove the worktree (`parking.news_after`). That worker needs a running slot, so behind the epic's `**Max parallel chunks:**` cap or the repo's `parallel-chunks`, the chunk stays parked with "it may be merged or closed already, but the chunk stays parked", and its window lingers for days. On a team epic, the issue of one such chunk was already Done while its window still read "awaits a slot". The person reads that as stuck work, and once a slot frees, a whole worker run goes to `chunk-pr clean`. - -Fix: where the pull request has merged and the worktree holds nothing the branch on origin lacks, do-epic runs `chunk-pr clean` in the worktree itself, finishes the chunk as a merged one, starts what it unblocks, and closes the window, taking no slot. A pull request closed unmerged, or a worktree with unpushed work, still goes to a worker as today. - -Touches: - -- `bin/do_epic/gates.py`: `Unopened`, `gate` (small) -- `bin/do_epic/parking.py`: `parked_through`, `news_after`, `resumed_news` -- `bin/do_epic/main.py`: `HELP` (small), `chunk_run` (small) -- `bin/do_epic/test_gates.py` -- `bin/do_epic/test_parking.py` -- `bin/do_epic/test_main.py`: `AChunkWhosePullRequestWaitsOnAGate` -- `README.md`: `#### Driving chunks` (small) - ### 487. Run larv-review's passes from a program that picks them from the diff and the item, counts rounds against the cap and decides each rerun, with each reviewer returning its findings as JSON against a schema. Part of the standalone-install plan lilleman approved on 2026-11-20. It applies the decision `loop: a step whose result a program can check …` in `docs/decisions.md`. The reviewer briefs stay prose. Start here, since larv-review holds the most sequencing rules. -- 2.52.0