diff --git a/docs/ROADMAP_WORKFLOW.md b/docs/ROADMAP_WORKFLOW.md index 2fa1b0ee30..0266b1ff7e 100644 --- a/docs/ROADMAP_WORKFLOW.md +++ b/docs/ROADMAP_WORKFLOW.md @@ -144,6 +144,7 @@ These are all the keys of the job record, by the job that writes them: | Implement | `implement.result` | How the run of the Job ended: `ready`, `stopped`, `yielded` or `returned`. The Job writes it as the last mark of its end and clears it in its first record write. The Service clears it when it records a new Job. A Job with `ready`, `yielded` or `returned` caused no stop, so the Service sets no stop for the Status that it left. A Job with no result, such as a killed pod, gets its class from its log | | Implement | `implement.checked_sha`, `implement.published_sha` | The head that passed the scoped checks, and the head that the job pushed. A Job that starts at the same head skips that phase, so a Job that was killed does not repeat it. The job writes each one when its phase passes, and clears both at ready and at a return to New | | Implement | `implement.job`, `implement.job_state`, `implement.job_digest` | The runner Job that the Service made, its state after a round reported it, and the digest of the runner image that the Job ran | +| Implement | `implement.needs_fix` | The draft pull request that the Service logged as left out for the label `plan/needs-fix`. A round that judges the Item and does not leave it out for the label clears it, so a new label is logged again | | Implement | `implement.continuations` | The count of the Jobs that the Service made to continue a run that ended with no result. It holds a count and no other data, and it stays after a clear | | Implement | `implement.digest_clears`, `implement.digest_clear_commented_at` | The clears of a stop by a new runner image (the class, the digest and the time of each), which stay after a clear, and the time of the last comment of such a clear | diff --git a/docs/roadmap/implement.md b/docs/roadmap/implement.md index 1e41c72062..b5ee2cf5a7 100644 --- a/docs/roadmap/implement.md +++ b/docs/roadmap/implement.md @@ -57,7 +57,7 @@ The effort of an item picks its pass: the job runs one pass for each value of th The job leaves out a Planned item whose title has no Conventional Commit type, or whose title summary has more than 60 characters. It judges the title before it reads the plan or makes a model request. `devops roadmap retitle` shortens such a title. -The job also leaves out an item whose plan fails the stage gates, or whose plan the reader cannot read. The job checks a Staged item on its branch, and a Planned item on the default branch. The job names the first problem in the report and in `devops roadmap explain`. No runner Job starts for such an item. A run lists the files of the default branch and reads its base specs one time. The job gives them to the check of every item. The check lists the branch of each Staged item for that item. +The job also leaves out an item whose plan fails the stage gates, or whose plan the reader cannot read. The job checks a Staged item on its branch, and a Planned item on the default branch. The job names the first problem in the report and in `devops roadmap explain`. No runner Job starts for such an item. The job also leaves out a Staged item while its draft holds the label `plan/needs-fix`, which the review of the stage job sets on a plan with an open finding. The reason names the label and the pull request. The Service logs such an item once for each draft and records the draft in `implement.needs_fix`. When the label is gone, the job takes the item again. A run lists the files of the default branch and reads its base specs one time. The job gives them to the check of every item. The check lists the branch of each Staged item for that item. - A **Staged** item has its staged branch and draft on `origin`. - A **Planned** item has its change folder on the default branch and no branch. The job makes the branch `/-` there, with the slug of the folder. It opens the draft when the branch first holds a commit. diff --git a/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/.openspec.yaml b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/.openspec.yaml new file mode 100644 index 0000000000..2a7773d65e --- /dev/null +++ b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-11 diff --git a/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/design.md b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/design.md new file mode 100644 index 0000000000..d70e08b471 --- /dev/null +++ b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/design.md @@ -0,0 +1,16 @@ +# Design + +## Decisions + +- The judge reads the label from the `PullStatus` that `_pull_reason` reads already. The check needs no new request, and it applies to the plan of the Service and to the plan of the runner Job (`--item`), because both call `plan_implement`. +- The check uses the constant `PLAN_NEEDS_FIX_LABEL` of `stage_verify.py`, the one that the stage job applies and the row `stage_ready` reads. The messages take the label as a value, so the code holds no second copy of the label text. +- The judge keeps the items that it leaves out for the label, and `ImplementPlan.needs_fix` returns them. The judge stays free of writes, because the module plans only. +- The row `implement` logs an item once for each draft. It records the draft in `implement.needs_fix`, as the row `stage_ready` records `stage.needs_fix` when it tells about the label once. A round clears the mark only for an item that its plan judged: with the limit 1 of the Service, the walk stops after the first item that it takes, and an item that it did not judge keeps its mark, so a later round does not log it again. +- When the label is gone, the item is free again at once: the judge reads the label in each round, and the mark gates only the log line. + +## Rejected alternatives + +- Leave out every unmerged plan, as #4078 and #4041 propose. That changes the Staged route of the job, which takes a plan on its staged branch by design. This change keeps that route and reads only the label that the review sets already. +- Read the check runs of the plan, as #3976 proposes. A plan with an open finding can pass every check, so the check runs do not show the finding. +- Comment on the issue when the job leaves the item out. The stage comment already lists the open findings, and the row `stage_ready` comments on the draft. A third comment adds noise for a person, so the Service logs the skip once and the plan report and `devops roadmap explain` give the reason. +- Log the skip in each round. The row runs every seven minutes, so a held item would add a log line in each round. diff --git a/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/proposal.md b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/proposal.md new file mode 100644 index 0000000000..364194b857 --- /dev/null +++ b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/proposal.md @@ -0,0 +1,44 @@ +# Proposal + +## Why + +The implement job takes a Staged item while the draft pull request of its plan holds the label `plan/needs-fix`. The stage job sets the label when the model review of the plan finds an open finding (`_label_needs_fix` in `src/devops_cli/roadmap/stage/stage.py`, constant `PLAN_NEEDS_FIX_LABEL` in `src/devops_cli/roadmap/stage/stage_verify.py`). The row `stage_ready` keeps such a draft a draft, but `_Judge._pull_reason` in `src/devops_cli/roadmap/implement/implement.py` accepts every open draft. On 2026-11-10 the Service started a runner Job for #3443 6 minutes after its plan #4352 got the label, and for #3451 7 minutes after its plan #4353 got the label. Both Jobs stopped on `limit_reached`, and each spent its step budget on a plan that the review refused (#4477). + +## What Changes + +- `_Judge._pull_reason` leaves out an open draft that holds `PLAN_NEEDS_FIX_LABEL`, with a reason that names the label and the pull request. The judge reads the labels from the `PullStatus` that it reads already, so the change adds no request. The judge keeps such items, and `ImplementPlan.needs_fix` returns them. +- The row `implement` of the Service logs each such item once for each draft. The round records the draft in the new mark `implement.needs_fix`, and returns only the items that it did not record yet. A round that judges the item and does not leave it out for the label clears the mark, so a new label is logged again. +- When the label is gone, the judge takes the item again, because it reads the label in each round. +- `docs/roadmap/implement.md` and the record table of `docs/ROADMAP_WORKFLOW.md` name the reason and the mark. +- The change fits one pull request. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `roadmap-implement-job`: The job leaves out a Staged item whose draft holds the label `plan/needs-fix` + +## Impact + +- Code: `src/devops_cli/roadmap/implement/implement.py`, `src/devops_cli/roadmap/implement/implement_submit.py`, `src/devops_cli/roadmap/run.py`, `src/devops_cli/roadmap/stores/store.py`, `src/devops_cli/lang/en/messages.py` +- Documents: `docs/roadmap/implement.md`, `docs/ROADMAP_WORKFLOW.md` +- Tests: `tests/roadmap/implement/test_roadmap_implement_selection.py`, `tests/roadmap/implement/test_roadmap_implement_submit.py`, `tests/support/roadmap_implement.py` +- Settings: none. The live ConfigMap needs no change. + +## Feasibility + +- `devops gh api repos/dan-petty/devops-cli/issues/4352/events` showed the label `plan/needs-fix` set by the App at 2026-11-10T10:51:32Z and removed by a person at 13:47:05Z. The same read of #4353 showed 11:40:27Z and 14:16:43Z. +- `kubectl -n devops get jobs` showed `devops-cli-runner-20261110-105724-b626` (args `roadmap implement --item 3443 --confirm`, start 10:57:29Z) and `devops-cli-runner-20261110-114742-c187` (args `--item 3451`, start 11:47:47Z). `kubectl -n devops logs` of both showed `Failure class limit_reached. Action left: raise_limit.` and `stopped 1`. +- `grep -rn "needs-fix\|NEEDS_FIX" src/devops_cli/roadmap/implement/` found nothing. `_label_needs_fix` in `stage.py` sets the label, and `_settle` in `stage_ready.py` reads it from `PullStatus.labels`. +- `_Judge._pull_reason` in `implement.py` reads `PullStatus` with `client.get_pull_status` and checks only `is_open_draft`. `PullStatus.labels` in `src/devops_cli/github/client.py` holds the label names. +- `run_implement_round` in `implement_submit.py` calls `plan_implement` for the Service, and the runner Job calls it with `--item`, so one check in the judge covers both. +- First check: `uv run devops ci test tests/roadmap/implement/test_roadmap_implement_selection.py tests/roadmap/implement/test_roadmap_implement_submit.py`. +- Second check: `uv run devops openspec check`. + +## Existing Tool Considered + +The change uses the label that the stage review sets already, the `PullStatus` that the judge reads already, and the record marks of the store. `stage_ready.py` uses the same pattern for `stage.needs_fix`: it tells about the label once and records the draft. No open tool decides which roadmap item a job takes. Written cost: about 30k tokens to build, keep and fix, and 1.5 hours of elapsed time. diff --git a/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/specs/roadmap-implement-job/spec.md b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/specs/roadmap-implement-job/spec.md new file mode 100644 index 0000000000..ec111accb5 --- /dev/null +++ b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/specs/roadmap-implement-job/spec.md @@ -0,0 +1,20 @@ +## ADDED Requirements + +### Requirement: The job leaves out a Staged item whose draft holds the label plan/needs-fix +The implement selection SHALL leave out a Staged item while its open draft pull request holds the label `plan/needs-fix`, with a reason that names the label and the pull request. The row `implement` of the Service SHALL log such an item once for each draft and record the draft in `implement.needs_fix`. The selection SHALL take the item again when the label is gone, and a round that judges the item and does not leave it out for the label SHALL clear the mark. + +#### Scenario: The draft holds the label +- **WHEN** the open draft of a Staged item holds the label `plan/needs-fix` +- **THEN** `plan_implement` returns no target for the item, and its reason names the label and the pull request + +#### Scenario: The Service logs the item once +- **WHEN** two rounds of the row `implement` judge the item while its draft holds the label +- **THEN** no round creates a Job, the log holds one line for the item, and `implement.needs_fix` holds the number of the draft + +#### Scenario: The label is gone +- **WHEN** a round judges the item after the label was removed from its draft +- **THEN** the round creates the Job of the item and clears `implement.needs_fix` + +#### Scenario: The label comes back +- **WHEN** the label comes back on the draft after a round judged the item without it +- **THEN** the next round logs the item again and creates no Job diff --git a/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/tasks.md b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/tasks.md new file mode 100644 index 0000000000..e4d1efe200 --- /dev/null +++ b/openspec/changes/archive/2026-11-11-4477-implement-takes-a-plan-that-needs/tasks.md @@ -0,0 +1,21 @@ +# Tasks + +## 1. Leave out a Staged item whose draft holds the label plan/needs-fix + +Reads: `src/devops_cli/roadmap/implement/implement.py`, `src/devops_cli/roadmap/implement/implement_submit.py`, `src/devops_cli/roadmap/run.py`, `src/devops_cli/roadmap/stores/store.py`, `src/devops_cli/roadmap/stage/stage_verify.py`, `src/devops_cli/roadmap/stage/stage_ready.py`, `src/devops_cli/github/client.py`, `src/devops_cli/lang/en/messages.py`, `tests/support/roadmap_implement.py`, `tests/roadmap/implement/test_roadmap_implement_selection.py`, `tests/roadmap/implement/test_roadmap_implement_submit.py`, `tests/roadmap/implement/test_roadmap_implement_record_readers.py`. Changes: `src/devops_cli/roadmap/implement/implement.py`, `src/devops_cli/roadmap/implement/implement_submit.py`, `src/devops_cli/roadmap/run.py`, `src/devops_cli/roadmap/stores/store.py`, `src/devops_cli/lang/en/messages.py`, `tests/support/roadmap_implement.py`, `tests/roadmap/implement/test_roadmap_implement_selection.py`, `tests/roadmap/implement/test_roadmap_implement_submit.py`, `tests/roadmap/implement/test_roadmap_implement_record_readers.py`. + +- [x] 1.1 Add to `tests/roadmap/implement/test_roadmap_implement_selection.py` a test that a Staged item whose open draft holds `plan/needs-fix` gets no target and a reason that names the label and the pull request. Add to `tests/roadmap/implement/test_roadmap_implement_submit.py` a test that two rounds create no Job, log the item once and record `implement.needs_fix`, a test that a round after the label is gone creates the Job and clears the mark, and a test that a label that comes back is logged again. Add `implement.needs_fix` to the table of `tests/roadmap/implement/test_roadmap_implement_record_readers.py` + - Verification: `uv run devops ci test tests/roadmap/implement/test_roadmap_implement_selection.py tests/roadmap/implement/test_roadmap_implement_submit.py tests/roadmap/implement/test_roadmap_implement_record_readers.py` fails on the base +- [x] 1.2 Leave out an open draft with `PLAN_NEEDS_FIX_LABEL` in `_Judge._pull_reason`, keep the item in `ImplementPlan.needs_fix`, add `ImplementRecordKey.NEEDS_FIX`, record and clear the mark in `run_implement_round`, and log each new item in the row `implement` of `run.py` + - Verification: `uv run devops ci test tests/roadmap/implement/test_roadmap_implement_selection.py tests/roadmap/implement/test_roadmap_implement_submit.py tests/roadmap/implement/test_roadmap_implement_record_readers.py` passes + +## 2. Name the reason and the mark in the documents + +Reads: `docs/roadmap/implement.md`, `docs/ROADMAP_WORKFLOW.md`. Changes: `docs/roadmap/implement.md`, `docs/ROADMAP_WORKFLOW.md`. + +- [x] 2.1 Add the label to the reasons that the implement job leaves an item out in `docs/roadmap/implement.md`, and add `implement.needs_fix` to the record table of `docs/ROADMAP_WORKFLOW.md` + - Verification: `uv run devops ci docs` passes + +## Workflow follow-up + +- Pending a person: review the diff in tuicr (tuicr -r ..HEAD). diff --git a/openspec/specs/roadmap-implement-job/spec.md b/openspec/specs/roadmap-implement-job/spec.md index a0452f83c5..13b639727a 100644 --- a/openspec/specs/roadmap-implement-job/spec.md +++ b/openspec/specs/roadmap-implement-job/spec.md @@ -1853,3 +1853,22 @@ The record `implement.spend` SHALL hold, for each step that got the one extensio #### Scenario: No extension - **WHEN** no step of the run got an extension - **THEN** the comment of the item lists no budget extension + +### Requirement: The job leaves out a Staged item whose draft holds the label plan/needs-fix +The implement selection SHALL leave out a Staged item while its open draft pull request holds the label `plan/needs-fix`, with a reason that names the label and the pull request. The row `implement` of the Service SHALL log such an item once for each draft and record the draft in `implement.needs_fix`. The selection SHALL take the item again when the label is gone, and a round that judges the item and does not leave it out for the label SHALL clear the mark. + +#### Scenario: The draft holds the label +- **WHEN** the open draft of a Staged item holds the label `plan/needs-fix` +- **THEN** `plan_implement` returns no target for the item, and its reason names the label and the pull request + +#### Scenario: The Service logs the item once +- **WHEN** two rounds of the row `implement` judge the item while its draft holds the label +- **THEN** no round creates a Job, the log holds one line for the item, and `implement.needs_fix` holds the number of the draft + +#### Scenario: The label is gone +- **WHEN** a round judges the item after the label was removed from its draft +- **THEN** the round creates the Job of the item and clears `implement.needs_fix` + +#### Scenario: The label comes back +- **WHEN** the label comes back on the draft after a round judged the item without it +- **THEN** the next round logs the item again and creates no Job diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 94eba76ffd..b24e7aa931 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -3030,6 +3030,10 @@ class RoadmapMessages: implement_left_no_branch: str = "Its staged branch `{branch}` is not on origin." implement_left_foreign: str = "Its branch has a commit by {author}, not by {bot}." implement_left_pull: str = "Its pull request #{pull} is not an open draft." + implement_left_needs_fix: str = ( + "Its pull request #{pull} holds the label `{label}`: the review of its plan found an open " + "finding. The job takes the item again when the label is gone." + ) implement_left_plan: str = "Its plan fails the stage check: {problem}" implement_left_plan_git: str = "Its plan cannot be read from git: {reason}" implement_job_title: str = "# Implement plan for {repo}" @@ -3097,6 +3101,10 @@ class RoadmapMessages: implement_job_applied: str = "Took {ready} item(s) to a ready pull request, stopped {stopped}." implement_job_yielded: str = "Left {yielded} item(s) to the owner that claimed them." implement_round_left: str = "Left #{number}: an agent or a person claimed it since the plan." + implement_round_needs_fix: str = ( + "Left #{number}: its pull request #{pull} holds the label `{label}`. The row takes the item " + "again when the label is gone." + ) implement_round_effort: str = "The round selected an item in effort pass {effort}." implement_round_fallback: str = "The round uses the fallback pass." implement_boundary_group: str = "the start of group {group}" diff --git a/src/devops_cli/roadmap/implement/implement.py b/src/devops_cli/roadmap/implement/implement.py index 2ff2a05e24..7643ae0672 100644 --- a/src/devops_cli/roadmap/implement/implement.py +++ b/src/devops_cli/roadmap/implement/implement.py @@ -29,9 +29,10 @@ a commit by anyone but the App (a clean merge by a person does not count, #3392), a worktree holds the issue, its plan fails the stage gates of `check_proposal` or the reader cannot read it (#3393; a branch whose change the job archived already passed them, and a retry takes it, #3645), -its pull request is not an open draft, or, for a Planned item, a branch of `origin` holds the issue, -its change is archived, it has no branch name, its change has no `tasks.md` on the default branch, -or every task of its change is ticked. A run takes at most `--limit` items, +its pull request is not an open draft or holds the label `plan/needs-fix` of a plan with an open +finding (the job takes the item again when the label is gone, #4477), or, for a Planned item, a +branch of `origin` holds the issue, its change is archived, it has no branch name, its change has +no `tasks.md` on the default branch, or every task of its change is ticked. A run takes at most `--limit` items, the highest priority first. `--item` takes the one item it names and does not apply the filter or the limit. @@ -108,6 +109,7 @@ ) from devops_cli.roadmap.stage.stage_change import check_proposal from devops_cli.roadmap.stage.stage_paths import StagedTree +from devops_cli.roadmap.stage.stage_verify import PLAN_NEEDS_FIX_LABEL from devops_cli.roadmap.status_sync import job_holds from devops_cli.roadmap.step_files import parse_task_groups from devops_cli.roadmap.stores.store import ( @@ -188,14 +190,23 @@ def new_branch(self) -> BranchParts | None: return parse_branch(self.branch) if self.planned else None +class NeedsFix(NamedTuple): + """An item that the job leaves out while its draft `pull` holds the label `plan/needs-fix` + (#4477).""" + + item: Item + pull: int + + @dataclass(frozen=True) class ImplementPlan: """What a run does: the items to implement, and the items the filter names that the job leaves out, each with its reason. `unmatched` holds the open items that the filter does not name, only when the plan was asked for them (`--why`). `beyond` holds the numbers of the items that pass every rule but come after the limit (`walk_named`). `effort` is the effort of the pass that - takes the run, and `fallback` is true when that pass is a later value of the set (#3385). A dry - run holds the requests of a run and nothing else.""" + takes the run, and `fallback` is true when that pass is a later value of the set (#3385). + `needs_fix` holds the left-out items whose draft holds the label `plan/needs-fix`. A dry run + holds the requests of a run and nothing else.""" repo: str selected: tuple[ImplementTarget, ...] = () @@ -207,6 +218,7 @@ class ImplementPlan: beyond: tuple[int, ...] = () effort: str = "" fallback: bool = False + needs_fix: tuple[NeedsFix, ...] = () class RecordedBranch(NamedTuple): @@ -287,6 +299,7 @@ def __init__( self._default_rev = f"origin/{planned.default}" self._pull_status = pull_status self._bot = load_settings().service.github_app.bot_login + self.needs_fix: dict[int, NeedsFix] = {} def judge(self, item: Item) -> ImplementTarget | str: """The target for `item`, or the reason the job leaves it out.""" @@ -314,7 +327,7 @@ def judge(self, item: Item) -> ImplementTarget | str: why = ( self._branch_reason(item, route.branch) or self._plan_reason(item, f"origin/{route.branch}") - or self._pull_reason(route.pull) + or self._pull_reason(item, route.pull) ) return why if why is not None else ImplementTarget(item, route.branch, route.pull, retry) @@ -431,14 +444,21 @@ def _branch_reason(self, item: Item, branch: str) -> str | None: return texts.implement_left_foreign.format(author=other, bot=self._bot) return stray_branch_reason(self._source, branch, self._heads) - def _pull_reason(self, pull: int) -> str | None: + def _pull_reason(self, item: Item, pull: int) -> str | None: + """Why the job leaves out the draft `pull` of `item`, or None when it takes it. A draft + with the label `plan/needs-fix` holds a plan with an open finding: the job leaves it out + until the label is gone, and keeps the item in `needs_fix`.""" + texts = MESSAGES.roadmap try: status = self._pull_status(pull) except GitHubNotFoundError: - return MESSAGES.roadmap.implement_left_pull.format(pull=pull) - return ( - None if status.is_open_draft else MESSAGES.roadmap.implement_left_pull.format(pull=pull) - ) + return texts.implement_left_pull.format(pull=pull) + if not status.is_open_draft: + return texts.implement_left_pull.format(pull=pull) + if PLAN_NEEDS_FIX_LABEL in status.labels: + self.needs_fix[item.number] = NeedsFix(item, pull) + return texts.implement_left_needs_fix.format(pull=pull, label=PLAN_NEEDS_FIX_LABEL) + return None def _left(item: Item, why: str) -> LeftOut: @@ -529,7 +549,7 @@ def plan_implement( ) if item_number is not None: selected, left_out = _named(judge, store, item_number) - return ImplementPlan(repo, selected, left_out) + return ImplementPlan(repo, selected, left_out, needs_fix=tuple(judge.needs_fix.values())) efforts = implement_efforts() walked, in_use = _walk_passes(store, effort_passes(filters, efforts), judge, limit, probe) explicit = "effort" in filters.families @@ -541,6 +561,7 @@ def plan_implement( beyond=walked.beyond, effort=in_use, fallback=bool(in_use) and not explicit and in_use != efforts[0], + needs_fix=tuple(judge.needs_fix.values()), ) @@ -598,6 +619,7 @@ def render_implement_plan(plan: ImplementPlan) -> str: "GIT_OPERATION", "ImplementPlan", "ImplementTarget", + "NeedsFix", "RecordedBranch", "dry_run_implement", "parse_implement_filters", diff --git a/src/devops_cli/roadmap/implement/implement_submit.py b/src/devops_cli/roadmap/implement/implement_submit.py index bd86987640..9110b568d0 100644 --- a/src/devops_cli/roadmap/implement/implement_submit.py +++ b/src/devops_cli/roadmap/implement/implement_submit.py @@ -46,6 +46,11 @@ and names the class and the action left in its comment. The runner pod is not scraped, so the Service counts. +**Needs fix.** The plan leaves out a Staged item while its draft holds the label `plan/needs-fix` +of a plan with an open finding (`implement.py`, #4477). The round returns such an item once for +each draft, for the row to log, and records the draft in `implement.needs_fix`. A round that judges +the item and does not leave it out for the label clears the mark, so a new label is logged again. + **Status.** After it reports the Jobs, and again after it creates one, the round sets the Status label of each item from the record and the plans on the default branch (`status_sync.py`, #2920): Planned once the plan is merged, and In Progress as soon as the record names a Job. The round reads @@ -98,7 +103,9 @@ from devops_cli.roadmap.implement.consecutive_failures import get_consecutive_failures from devops_cli.roadmap.implement.implement import ( GIT_OPERATION, + ImplementPlan, ImplementTarget, + NeedsFix, parse_implement_filters, plan_implement, ) @@ -134,7 +141,8 @@ class SubmitResult: """What a round did: the Jobs it reported, whether a running Job held it, the Job it created, and the item it left because an agent or a person claimed it after the plan (#2910), and the items whose Status it could not set, and the items whose stop it cleared (#2912). `effort` and - `fallback` name the effort pass that selected the item (#3385).""" + `fallback` name the effort pass that selected the item (#3385). `needs_fix` holds the items + that the round left out for the label `plan/needs-fix` and had not logged yet.""" reported: tuple[str, ...] = () waiting: bool = False @@ -144,6 +152,7 @@ class SubmitResult: cleared: tuple[int, ...] = () effort: str = "" fallback: bool = False + needs_fix: tuple[NeedsFix, ...] = () def _record(item: Item, key: ImplementRecordKey) -> str | None: @@ -426,6 +435,29 @@ def _create( return name +def _note_needs_fix(store: RoadmapStore, plan: ImplementPlan) -> tuple[NeedsFix, ...]: + """The items that `plan` leaves out for the label `plan/needs-fix` and that no round noted for + the same draft. The round records the draft in `implement.needs_fix`, and clears the mark of + an item that the plan judged and did not leave out for the label.""" + new = tuple( + held + for held in plan.needs_fix + if held.item.job_record.get(ImplementRecordKey.NEEDS_FIX) != str(held.pull) + ) + for held in new: + store.set_marks(held.item, {ImplementRecordKey.NEEDS_FIX: str(held.pull)}) + judged = { + *(left.number for left in plan.left_out), + *(target.item.number for target in plan.selected), + *plan.beyond, + } + free = judged - {held.item.number for held in plan.needs_fix} + for item in store.items(): + if item.number in free and item.job_record.get(ImplementRecordKey.NEEDS_FIX) is not None: + store.set_marks(item, {ImplementRecordKey.NEEDS_FIX: None}) + return new + + def _runs(api: ClusterJobs, label: str) -> bool: """Whether a runner Job of the repository with `label` has not ended.""" jobs = api.list_jobs({CONST_ROADMAP_IMPLEMENT_JOB_LABEL: label}) @@ -464,11 +496,18 @@ def run_implement_round( limit=DEFAULT_ROADMAP_IMPLEMENT_LIMIT, planned=planned, ) + needs_fix = _note_needs_fix(store, plan) if not plan.selected: - return SubmitResult(reported=reported, status_failed=failed, cleared=stops.cleared) + return SubmitResult( + reported=reported, status_failed=failed, cleared=stops.cleared, needs_fix=needs_fix + ) if _runs(api, label): return SubmitResult( - reported=reported, waiting=True, status_failed=failed, cleared=stops.cleared + reported=reported, + waiting=True, + status_failed=failed, + cleared=stops.cleared, + needs_fix=needs_fix, ) number = plan.selected[0].item.number size = _size_of(source, planned, plan.selected[0]) @@ -482,6 +521,7 @@ def run_implement_round( cleared=stops.cleared, effort=plan.effort, fallback=plan.fallback, + needs_fix=needs_fix, ) diff --git a/src/devops_cli/roadmap/run.py b/src/devops_cli/roadmap/run.py index c7e9929612..98fd71a4d9 100644 --- a/src/devops_cli/roadmap/run.py +++ b/src/devops_cli/roadmap/run.py @@ -147,6 +147,7 @@ ) from devops_cli.roadmap.stage.stage_ready import mark_stage_ready from devops_cli.roadmap.stage.stage_toolbox import ToolboxModel +from devops_cli.roadmap.stage.stage_verify import PLAN_NEEDS_FIX_LABEL from devops_cli.roadmap.status_sync import sync_statuses from devops_cli.roadmap.stores.store import Change, ChangeKind, RoadmapStore from devops_cli.roadmap.trust import is_person_comment @@ -656,6 +657,12 @@ def _run_implement_adapter( ) if result.left is not None: logger.info(MESSAGES.roadmap.implement_round_left.format(number=result.left)) + for held in result.needs_fix: + logger.info( + MESSAGES.roadmap.implement_round_needs_fix.format( + number=held.item.number, pull=held.pull, label=PLAN_NEEDS_FIX_LABEL + ) + ) if result.created is not None and result.effort: logger.info(MESSAGES.roadmap.implement_round_effort.format(effort=result.effort)) if result.fallback: diff --git a/src/devops_cli/roadmap/stores/store.py b/src/devops_cli/roadmap/stores/store.py index d63b7a4948..80879bcc26 100644 --- a/src/devops_cli/roadmap/stores/store.py +++ b/src/devops_cli/roadmap/stores/store.py @@ -287,7 +287,9 @@ class ImplementRecordKey(StrEnum): the earlier Job: the next Job hands them to its first step and clears them. `implement.spend_counted` holds the tokens of `implement.spend` that the token counter already holds (#4200): the Service writes it when it reports a Job, and a retry and a return to New - clear it with the spend.""" + clear it with the spend. `implement.needs_fix` holds the draft that the Service logged as left + out for the label `plan/needs-fix`, so it logs the item once (#4477); a round that judges + the item and does not leave it out for the label clears the mark.""" GROUP = "implement.group" SHA = "implement.sha" @@ -313,6 +315,7 @@ class ImplementRecordKey(StrEnum): DIGEST_CLEAR_COMMENTED_AT = "implement.digest_clear_commented_at" CONTINUATIONS = "implement.continuations" REPAIR_ROUNDS = "implement.repair_rounds" + NEEDS_FIX = "implement.needs_fix" class RetitleRecordKey(StrEnum): diff --git a/tests/roadmap/implement/test_roadmap_implement_record_readers.py b/tests/roadmap/implement/test_roadmap_implement_record_readers.py index 6e19fc9db1..69ae4567d6 100644 --- a/tests/roadmap/implement/test_roadmap_implement_record_readers.py +++ b/tests/roadmap/implement/test_roadmap_implement_record_readers.py @@ -51,6 +51,7 @@ "implement.digest_clear_commented_at": ("code", f"{ROADMAP}/digest_clears.py"), "implement.continuations": ("code", f"{ROADMAP}/stop_clear.py"), "implement.repair_rounds": ("code", f"{ROADMAP}/implement/implement_submit.py"), + "implement.needs_fix": ("code", f"{ROADMAP}/implement/implement_submit.py"), } diff --git a/tests/roadmap/implement/test_roadmap_implement_selection.py b/tests/roadmap/implement/test_roadmap_implement_selection.py index c671144a71..760d306b8b 100644 --- a/tests/roadmap/implement/test_roadmap_implement_selection.py +++ b/tests/roadmap/implement/test_roadmap_implement_selection.py @@ -26,6 +26,7 @@ from tests.support.fakes.roadmap_store import InMemoryRoadmapStore from tests.support.roadmap_implement import ( BRANCH, + NEEDS_FIX_DRAFT, PULL, push_staged_branch, route_pull_status, @@ -414,6 +415,21 @@ def test_an_item_whose_pull_request_is_not_an_open_draft_is_left_out( assert _reasons(plan) == {number: f"Its pull request #{PULL} is not an open draft."} +def test_an_item_whose_draft_holds_the_label_plan_needs_fix_is_left_out_with_the_label_as_reason( + store: InMemoryRoadmapStore, staged_repo: StageRepo, github_api: GitHubApiFake +) -> None: + route_pull_status(github_api, NEEDS_FIX_DRAFT) + number = seed_staged(store) + + plan = _plan(store, staged_repo) + + assert plan.selected == () + assert _reasons(plan) == { + number: f"Its pull request #{PULL} holds the label `plan/needs-fix`: the review of its " + "plan found an open finding. The job takes the item again when the label is gone." + } + + def test_an_item_that_a_worktree_holds_is_left_out( store: InMemoryRoadmapStore, staged_repo: StageRepo, api: GitHubApiFake ) -> None: diff --git a/tests/roadmap/implement/test_roadmap_implement_submit.py b/tests/roadmap/implement/test_roadmap_implement_submit.py index efa34fa91c..f0ee4ea2b1 100644 --- a/tests/roadmap/implement/test_roadmap_implement_submit.py +++ b/tests/roadmap/implement/test_roadmap_implement_submit.py @@ -41,6 +41,7 @@ from tests.support.fakes.roadmap_store import InMemoryRoadmapStore from tests.support.paths import REPO_ROOT from tests.support.roadmap_implement import ( + NEEDS_FIX_DRAFT, PULL, TASKS, merge_plan, @@ -1389,6 +1390,75 @@ def plan_then_claim(*args: Any, **kwargs: Any) -> Any: ) +def test_a_round_creates_no_job_while_the_draft_holds_the_label_plan_needs_fix_and_logs_it_once( + store: InMemoryRoadmapStore, + staged_repo: StageRepo, + api: GitHubApiFake, + kube: FakeCluster, + caplog: pytest.LogCaptureFixture, +) -> None: + route_pull_status(api, NEEDS_FIX_DRAFT) + number = seed_staged(store) + + with caplog.at_level(logging.INFO, logger="devops_cli.roadmap.run"): + _round(store, staged_repo) + _round(store, staged_repo) + + assert [line for line in caplog.messages if line.startswith(f"Left #{number}")] == [ + f"Left #{number}: its pull request #{PULL} holds the label `plan/needs-fix`. " + "The row takes the item again when the label is gone." + ] + assert _creates(kube) == [] + assert _record(store, number) == { + "stage.branch": "fix/1-the-job-drops-a-comment", + "stage.pr": "5", + "implement.needs_fix": "5", + } + + +def test_a_round_creates_the_job_once_the_label_plan_needs_fix_is_gone_and_clears_its_note( + store: InMemoryRoadmapStore, staged_repo: StageRepo, api: GitHubApiFake, kube: FakeCluster +) -> None: + route_pull_status(api, NEEDS_FIX_DRAFT) + number = seed_staged(store) + _round(store, staged_repo) + noted = _record(store, number)["implement.needs_fix"] + route_pull_status(api) + + _round(store, staged_repo) + + (job,) = _jobs(kube) + record = _record(store, number) + assert (noted, record["implement.needs_fix"]) == ("5", None) + assert record["implement.job"] == job["metadata"]["name"] + + +def test_a_round_logs_the_label_plan_needs_fix_again_when_it_comes_back_after_it_was_gone( + store: InMemoryRoadmapStore, + staged_repo: StageRepo, + api: GitHubApiFake, + kube: FakeCluster, + caplog: pytest.LogCaptureFixture, +) -> None: + route_pull_status(api, NEEDS_FIX_DRAFT) + number = seed_staged(store) + _round(store, staged_repo) + route_pull_status(api) + store.as_actor("alice").add_label(number, "owner/human") + _round(store, staged_repo) + store.as_actor("alice").remove_label(number, "owner/human") + route_pull_status(api, NEEDS_FIX_DRAFT) + + with caplog.at_level(logging.INFO, logger="devops_cli.roadmap.run"): + _round(store, staged_repo) + + assert [line for line in caplog.messages if line.startswith(f"Left #{number}")] == [ + f"Left #{number}: its pull request #{PULL} holds the label `plan/needs-fix`. " + "The row takes the item again when the label is gone." + ] + assert _creates(kube) == [] + + def test_the_report_of_a_job_keeps_the_claim_of_a_person_and_stops_nothing( store: InMemoryRoadmapStore, staged_repo: StageRepo, api: GitHubApiFake, kube: FakeCluster ) -> None: diff --git a/tests/support/roadmap_implement.py b/tests/support/roadmap_implement.py index e5230cbbd2..e6d9705fc3 100644 --- a/tests/support/roadmap_implement.py +++ b/tests/support/roadmap_implement.py @@ -107,6 +107,8 @@ "base": {"ref": "main", "sha": ""}, "labels": [], } +# The draft after the review of its plan found an open finding: the stage job labels it (#3264). +NEEDS_FIX_DRAFT = {**OPEN_DRAFT, "labels": [{"name": "plan/needs-fix"}]} def branch_of(number: int, slug: str = "the-job-drops-a-comment") -> str: