Read a team's own repo labels as do-epic's picks, and treat an item a person filed sub-tasks under as split
CI / tests (pull_request) Has been cancelled

This commit is contained in:
Lilleman
2026-11-19 15:33:51 +01:00
parent 017cf33611
commit 95535b4fb3
20 changed files with 278 additions and 119 deletions
+28 -21
View File
@@ -9,11 +9,11 @@ from do_epic.epic_record import CAP
from chunk_driver.claims import CHUNK_FLAG, epic_chunks, HANDED, loop_chunks, project_lock, starting
from do_epic.backend.protocol import EpicIssue
from failure import Failure
from do_epic.repo_pick import HumanTask, recorded, Repo
from do_epic.repo_pick import HumanTask, Pick, recorded, Repo, LabelRepos
from project_config.settings import PARALLEL_CHUNKS
from do_epic.parked import parked_chunks
from chunk_pr.approval import PARKS
from do_epic.split import SPLIT_LABEL
from do_epic.split import is_split
from agent_cycle import tmux
# Under the home folder, a folder per epic key holds the epic's lock file, which `claims.LOCK` names. A chunk without a repo works there.
@@ -71,6 +71,8 @@ class Epic:
# The do-epic script each window runs.
launcher: pathlib.Path
env: typing.Mapping[str, str]
# The team's own labels for its repos.
team: LabelRepos
@property
def folder(self) -> pathlib.Path:
@@ -88,39 +90,44 @@ def held_up(issues: list[EpicIssue]) -> dict[str, list[str]]:
by_key = {issue.key: issue for issue in issues}
held: dict[str, list[str]] = {}
for issue in issues:
if not issue.done and SPLIT_LABEL not in issue.labels:
if not issue.done and not is_split(issue, issues):
for key in open_blockers(issue, by_key):
held.setdefault(key, []).append(issue.key)
return held
def chunks(issues: list[EpicIssue]) -> tuple[list[Chunk], list[Waits]]:
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. An item split by repo is worked through its sub-tasks, and what blocks it blocks them. A blocker outside the epic blocks until the human removes the link, since its state is unknown. A human's task gets a window only while it holds up another issue and nothing holds it up; that window waits for the human."""
def chunks(issues: list[EpicIssue], team: LabelRepos) -> tuple[list[Chunk], list[Waits]]:
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. A split item is worked through its sub-tasks, and what blocks it blocks them. team maps the team's own labels to repos."""
by_key = {issue.key: issue for issue in issues}
holding = held_up(issues)
found: list[Chunk] = []
waits: list[Waits] = []
for issue in issues:
if issue.done or SPLIT_LABEL in issue.labels:
if issue.done or is_split(issue, issues):
continue
pick = recorded(issue)
blocking = open_blockers(issue, by_key)
outside = [key for key in blocking if key not in by_key]
if isinstance(pick, Failure):
waits.append(Waits(issue.key, pick.reason))
elif pick is None:
waits.append(Waits(issue.key, "no label names its repo"))
elif isinstance(pick, HumanTask) and not blocking and issue.key in holding:
found.append(Chunk(issue.key, None, human=True))
elif isinstance(pick, HumanTask):
waits.append(Waits(issue.key, "it is a human's task"))
elif blocking:
waits.append(Waits(issue.key, f"{' and '.join(blocking)} block{'s' if len(blocking) == 1 else ''} it" + (f"; do-epic cannot see {' and '.join(outside)}, outside the epic, finish: remove such a link in Jira once its issue is done" if outside else "")))
turn = turn_of(issue, recorded(issue, team), open_blockers(issue, by_key), by_key, issue.key in holding)
if isinstance(turn, Chunk):
found.append(turn)
else:
found.append(Chunk(issue.key, pick.name if isinstance(pick, Repo) else None))
waits.append(turn)
return found, waits
def turn_of(issue: EpicIssue, pick: Pick | None | Failure, blocking: list[str], by_key: dict[str, EpicIssue], holds: bool) -> Chunk | Waits:
"""The open issue's chunk, or why it waits. blocking are its open blockers, and holds says it holds up another open issue. A human's task gets a window only while it holds up another issue and nothing holds it up; that window waits for the human. A blocker outside the epic blocks until the human removes the link, since its state is unknown."""
if isinstance(pick, Failure):
return Waits(issue.key, pick.reason)
if pick is None:
return Waits(issue.key, "no label names its repo")
if isinstance(pick, HumanTask):
return Chunk(issue.key, None, human=True) if holds and not blocking else Waits(issue.key, "it is a human's task")
if blocking:
outside = [key for key in blocking if key not in by_key]
unseen = f"; do-epic cannot see {' and '.join(outside)}, outside the epic, finish: remove such a link in Jira once its issue is done" if outside else ""
return Waits(issue.key, f"{' and '.join(blocking)} block{'s' if len(blocking) == 1 else ''} it{unseen}")
return Chunk(issue.key, pick.name if isinstance(pick, Repo) else None)
def refusal(repo: str, room: RepoRoom) -> str | None:
"""Why the repo takes no further chunk; None where it takes one."""
if room.loop_claude:
@@ -133,7 +140,7 @@ def refusal(repo: str, room: RepoRoom) -> str | None:
def start_chunks(epic: Epic, issues: list[EpicIssue], finishing: bool, own: str | None, run: tmux.Tmux) -> Started | Failure:
"""Starts a do-epic in a new window for each of the epic's chunks that may start now. Where finishing is set, no issue is open, and the one chunk to start is the epic's finishing (finish.py), in a window named for the epic's key. own is the key of the chunk that asks, which has finished or parked: it counts as running nowhere, and no stopped chunk starts again. Where own is None, the human's `do-epic <EPIC-KEY>` asks, and each stopped chunk starts again. A parked chunk waits in its window; one without a live window, as after a reboot, starts again as a stopped chunk does, whatever the limits, since it goes on parked. A Failure says why a window could not start; those before it run."""
session = tmux.session_name(tmux.EPIC, epic.key)
found, waits = chunks(issues)
found, waits = chunks(issues, epic.team)
if finishing:
found.append(Chunk(epic.key, None))
started: list[str] = []