Answer stability round 1: 1 🔴, 4 🟡 (1 misread); run chunk-pr by its path, say why a clean left the worktree, test the working-branch move

This commit is contained in:
2026-12-03 14:02:59 +01:00
parent e8ab4ef9d8
commit 57fef64105
4 changed files with 44 additions and 18 deletions
+18 -9
View File
@@ -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()