Answer product-owner round 2: 0 🔴, 1 🟡 (0 misread); exit 0 on awaited merges, so the finished chunk's window closes and the next run reads the plan

This commit is contained in:
Lilleman
2026-11-19 23:30:30 +01:00
parent 1a23aa05b0
commit 356ae263e1
6 changed files with 34 additions and 19 deletions
+17 -12
View File
@@ -76,13 +76,16 @@ def room_of(windows: list[tmux.Listed], own: str | None, leaving: bool, limit: i
return Room(running, stopped, restart, room - len(restart))
def may_start(plan: NextChunk | NoItem, running: list[str], held: set[int], room: int) -> list[str] | Failure:
"""The chunks to start now beside the running ones, whose chunks hold the items in held: the plan's next item and the items touch_predictions picks to run beside it, in the plan's order, up to room of them. Each leaves out an item in held, and one whose `Touches:` prediction overlaps a held item's, or where either has none. A plan without an item starts NO_ITEM, and only alone. A plan whose NoItem names pull requests that await a person's merge starts none: where nothing runs, a Failure names them."""
if isinstance(plan, NoItem) and plan.awaits_merge:
# Where nothing runs, the loop stops on the pull requests plan.why names, rather than start a worker only to report them.
return [] if running else Failure(plan.why)
@dataclasses.dataclass(frozen=True)
class AwaitedMerges:
"""Why no chunk starts and none runs: every item left awaits a person's merge of the pull requests that why names."""
why: str
def may_start(plan: NextChunk | NoItem, running: list[str], held: set[int], room: int) -> list[str]:
"""The chunks to start now beside the running ones, whose chunks hold the items in held: the plan's next item and the items touch_predictions picks to run beside it, in the plan's order, up to room of them. Each leaves out an item in held, and one whose `Touches:` prediction overlaps a held item's, or where either has none. A plan without an item starts NO_ITEM, and only alone; none where its NoItem names pull requests that await a person's merge."""
if isinstance(plan, NoItem):
return [] if running or room < 1 else [NO_ITEM]
return [] if running or room < 1 or plan.awaits_merge else [NO_ITEM]
beside = chunks_beside(plan.items, plan.first)
picked = [plan.first.id, *(beside.picked if isinstance(beside, Beside) else [])]
details = {item.id: item.detail for item in plan.items}
@@ -111,8 +114,8 @@ def next_plan(root: str, home: pathlib.Path, effects: Effects) -> NextChunk | No
return planned(held.plan, held.cut, ref, config.branch, None if config.tracked("plan") else config.plan_label)
def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Mapping[str, str], launcher: pathlib.Path, effects: Effects) -> list[str] | Failure:
"""Starts a loop-claude in a new window for each chunk of loop_run's project that may start now, and returns the chunks started. leaving says that loop_run's own chunk finished, so its window no longer counts as running; without it, the human started loop-claude. A Failure says why no chunk may start, or why one could not; those before it run."""
def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Mapping[str, str], launcher: pathlib.Path, effects: Effects) -> list[str] | AwaitedMerges | Failure:
"""Starts a loop-claude in a new window for each chunk of loop_run's project that may start now, and returns the chunks started. leaving says that loop_run's own chunk finished, so its window no longer counts as running; without it, the human started loop-claude. AwaitedMerges where chunks_to_start returns it. A Failure says why no chunk may start, or why one could not; those before it run."""
config = located(loop_run.root, paths.home)
if isinstance(config, Failure):
return config
@@ -125,7 +128,7 @@ def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Map
if refused := refusal(session, windows, loop_run.root, effects.tmux):
return refused
chunks = chunks_to_start(windows, loop_run, leaving, config.parallel_chunks, paths, effects)
if isinstance(chunks, Failure):
if isinstance(chunks, AwaitedMerges):
return chunks
for chunk in chunks:
started = tmux.start_chunk(tmux.Window(session, chunk, ""), loop_run.root, handed, [str(launcher), CHUNK_FLAG, chunk, loop_run.task], windows, True, effects.tmux)
@@ -144,8 +147,8 @@ def refusal(session: str, windows: list[tmux.Listed], root: str, run: tmux.Tmux)
return None
def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool, limit: int, paths: Paths, effects: Effects) -> list[str] | Failure:
"""The chunks to start beside windows, the session's: the stopped ones room_of restarts, then those of the plan that may_start picks. A plan that cannot be read starts NO_ITEM, as a plan without an item does. A Failure where no chunk runs or restarts and every item left waits on a person's merge: it names the pull requests."""
def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool, limit: int, paths: Paths, effects: Effects) -> list[str] | AwaitedMerges:
"""The chunks to start beside windows, the session's: the stopped ones room_of restarts, then those of the plan that may_start picks. A plan that cannot be read starts NO_ITEM, as a plan without an item does. AwaitedMerges where no chunk runs or restarts and every item left awaits a person's merge."""
room = room_of(windows, loop_run.chunk, leaving, limit)
if not room.left:
return room.restart
@@ -155,8 +158,10 @@ def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool
say(f"starting a chunk without a plan item, since the plan cannot be read: {plan.reason}", effects)
plan = NoItem(plan.reason)
held = held_items(room.running + room.stopped, project_key(loop_run.root, paths.home), paths.claude_code_transcripts)
if isinstance(plan, NoItem) and plan.awaits_merge and not room.running + room.restart:
return AwaitedMerges(plan.why)
picked = may_start(plan, room.running + room.restart, held, room.left)
return picked if isinstance(picked, Failure) else room.restart + [chunk for chunk in picked if chunk not in room.stopped]
return room.restart + [chunk for chunk in picked if chunk not in room.stopped]
def held_beside(chunk: str, root: str, paths: Paths, effects: Effects) -> list[int]: