Repository navigation
Description
Problem or Motivation
The orphan rule (_orphans, stage.py:3172), the rejected plans (_rejections, stage.py:3236, and closed_plans, stage_rejected.py:227) and the drafts of closed items (_reconcile, stage.py:3145) run only inside read_stage_round (stage.py:3397) of the stage row. That row is in STATUS_LANE_ROWS (run.py:1273) and is due every roadmap.stage.interval_minutes (37 by default), on a first run, and after a round in which refine sets an item Ready, so the cleanup waits for it. The cleanup uses no model.
Proposed Solution & Architectural Design
steps/cleanup.py and a status-lane row cleanup that runs each tick. Orphan rule: a branch with a stage.pending mark (orphan_mark in stage_pending.py) older than 3600 s, no pull request and no live unit. A lease on the judged tip goes before each delete. A closed plan pull request is judged one time. Stage keeps only the planning. Add cleanup to the sweep step list of #4574. The push step of #4957 is closed.
Cost: about 0.5M tokens and 0.5 agent-day.
Target Subsystem
Roadmap Service status lane and the stage cleanup (src/devops_cli/roadmap/stage/, new src/devops_cli/roadmap/steps/cleanup.py).
Existing Tool Considered
git push --force-with-lease with the judged tip for each branch delete.
Acceptance Criteria
- Tests: an orphan branch is deleted only after 1 h and with no live unit; a moved tip makes the lease refuse the delete; the stage tests stay green; the status-lane row list holds cleanup.
- A dry-run test sees 0 requests.
Dependencies
- fix(roadmap): the final push of the implement Job can miss the latest main #4957 (closed: the final push of the implement Job can miss the latest main)
- Part of feat(roadmap): track the Service step jobs #5014 (track the Service step jobs).
Source: #5014
Owner decision 2026-11-13
The approved pipeline split (tracker #5482, Phase 1) adds the two-branch check and changes the orphan rule later:
-
The two-branch check: the gauge
devops_cli_roadmap_issue_branchesand an alert when one issue has two branches on origin for over 1 h. The-nsuffix gets built only when this check finds a real case (D2). -
Cleanup deletes the App-only branches of closed items, and the empty App-only branches of items that are not Ready.
-
Scaffold (feat(roadmap): scaffold makes, resumes or adopts the item branch #5499) merges after this item. It replaces the 1-hour delete of an App-only branch of a Ready item with an adopt.
-
A promtool rule test for the alert.
-
Live proof: after the merge and the release, cleanup runs as the App for 24 h. A comment gives the result lines, the orphan count (target 0 after 24 h) and the issues with two branches (target 0).
Owner decision 2026-11-13: candidate branches
A job can run more than one candidate (#5533, tracker #5482 D2). Candidate i works on <branch>-<i>, and a judge writes one result on the plain branch. The default is 1 candidate, with no candidate branch.
- Candidate branches
<branch>-<i>are kept while the judge of their item runs, and deleted after the judge ends. - The two-branch check counts the plain branch and its candidate branches as one branch while the candidates or the judge of the item run.
- If this item merges before feat(roadmap): a job can run candidates and a judge #5533, feat(roadmap): a job can run candidates and a judge #5533 adds these two rules and their tests to the cleanup step.
Alternatives check of 2026-11-30: not-applicable.
Class: refactor, no model call.
Tool: none found.
Proposed design
Problem statement
The stage round runs the orphan, rejection and draft cleanup on the model lane and waits behind refine, although the cleanup calls no model. The change moves the cleanup to a cleanup row of the status lane, adds the cleanup step, the App-only branch rules, the two-branch gauge and alert, and keeps stage for planning only.
Acceptance criteria
Requirement: Cleanup step module
The change SHALL add the cleanup as one roadmap step module src/devops_cli/roadmap/steps/cleanup.py with the command devops roadmap step cleanup, one JSON result line and the exit codes 0, 1 and 75.
Scenario: Dry run sends no request
- WHEN A caller runs
devops roadmap step cleanup --dry-run. - THEN The step writes one JSON result line, the fake client records 0 requests and the process exits 0.
Requirement: Status-lane cleanup row
The status lane MUST hold the cleanup row in STATUS_LANE_ROWS of src/devops_cli/roadmap/run.py, so that each tick runs the cleanup with no model call.
Scenario: The row list holds cleanup
- WHEN The tuple
STATUS_LANE_ROWSis imported. - THEN The tuple holds a row named
cleanupanduv run pytest tests/roadmap/test_roadmap_status_rows.pypasses.
Requirement: Orphan branch age rule
The cleanup step MUST delete an orphan branch only when its stage.pending mark is older than CONST_ROADMAP_STAGE_ORPHAN_AGE_SECONDS (3600 s), the branch has no pull request and no live unit of work holds its item.
Scenario: A young orphan branch stays
- WHEN An orphan branch has a
stage.pendingmark 1800 s old, no pull request and no live unit. - THEN The step deletes no branch and its result line names the branch as too young.
Requirement: Orphan branch delete
The cleanup step SHALL delete an orphan branch whose stage.pending mark is older than 3600 s, which has no pull request and whose item has no live unit.
Scenario: An old orphan branch goes
- WHEN An orphan branch has a
stage.pendingmark 3700 s old, no pull request and no live unit. - THEN The step deletes the branch and its result line names the delete.
Requirement: Lease on the judged tip
The cleanup step MUST delete a branch with git push --force-with-lease=refs/heads/<branch>:<sha> origin :refs/heads/<branch> against the judged tip, so that a tip that moved refuses the delete.
Scenario: A moved tip refuses the delete
- WHEN The tip of the branch on
origindiffers from the judged tip. - THEN The lease refuses the push, the step deletes no branch and its result line reports the refused delete.
Requirement: App-only branch rules
The cleanup step MUST delete the App-only branches of closed items and the empty App-only branches of items that are not Ready, where an App-only branch has only commits that the App authored and an empty branch has no commit beyond the default branch.
Scenario: App-only branches go
- WHEN The cleanup step finds an App-only branch of a closed item and an empty App-only branch of an item that is not Ready.
- THEN The step deletes both branches and its result line names each delete.
Requirement: Two-branch gauge
The Service MUST expose the gauge devops_cli_roadmap_issue_branches for each issue.
Scenario: The gauge counts issue branches
- WHEN The cleanup round counts the branches of an issue on
origin. - THEN The metric registry holds
devops_cli_roadmap_issue_brancheswith the labelissueand the metric test passes.
Requirement: Two-branch alert
The Service MUST fire an alert in k8s/devops/monitoring/prometheus-rules-values.yaml when one issue has two branches on origin for more than 1 h.
Scenario: Promtool rule test
- WHEN
uv run devops ci --check --only k8sruns the promtool rule test with two branches of one issue for more than 1 h. - THEN The check passes and the test shows the two-branch alert firing.
Requirement: Stage plans only
The stage round MUST NOT run _reconcile, _orphans or _rejections after the change.
Scenario: Stage tests stay green
- WHEN A stage round runs for an item with fakes that record each cleanup call.
- THEN The round writes the plan, calls none of
_reconcile,_orphansor_rejections, anduv run pytest tests/roadmap/stagepasses.
Requirement: Closed plan pull request judged one time
The cleanup step MUST judge a closed plan pull request one time, write the judgement as the rejection evidence of the item, and MUST NOT judge it again on a later tick.
Scenario: A second tick judges nothing again
- WHEN The cleanup step runs again on a repository whose closed plan pull request it judged before.
- THEN The step sends no second judge request and its result line reports the pull request as judged.
Existing Tool Considered
The alternatives check of 2026-11-30 in the issue body gives not-applicable and names no tool. For the branch delete, git with push --force-with-lease is the open maintained tool. It lacks the roadmap rules: the stage.pending age, the pull request check, the live unit check and the App-only branch rules. The change builds src/devops_cli/roadmap/steps/cleanup.py and the cleanup row. The written cost to build, keep and fix this code is about 0.5M tokens and 0.5 agent-day.
Key questions
- Which lane runs the cleanup after the change?: The status lane. The cleanup is the short row
cleanupofSTATUS_LANE_ROWSand runs each tick with no model. The stage round keeps planning only. (best practice) [sources: CONTEXT.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, src/devops_cli/roadmap/run.py:1278]- Chosen: status-lane row
cleanup. The cleanup uses no model. The status lane runs its rows each tick. - Rejected: keep the cleanup in the stage round. Stage waits behind refine on the model lane.
- Rejected: one step job pod for each cleanup run. A short roadmap step runs in the sweep. A pod for each tick costs more than the work.
- Chosen: status-lane row
- Which cleanup sites move out of the stage round?:
_reconcile,_orphansand_rejectionsmove._reconcileis atsrc/devops_cli/roadmap/stage/stage.py:3145,_orphansatsrc/devops_cli/roadmap/stage/stage.py:3172,_rejectionsatsrc/devops_cli/roadmap/stage/stage.py:3236, andclosed_plansatsrc/devops_cli/roadmap/stage/stage_rejected.py:227. [sources: src/devops_cli/roadmap/stage/stage.py:3145, src/devops_cli/roadmap/stage/stage.py:3172, src/devops_cli/roadmap/stage/stage.py:3236, src/devops_cli/roadmap/stage/stage_rejected.py:227] - Which mark and age does the orphan rule use?: The orphan rule reads
stage.pendingwithorphan_markinsrc/devops_cli/roadmap/stage/stage_pending.py. It acts only when the mark is older thanCONST_ROADMAP_STAGE_ORPHAN_AGE_SECONDS(3600 s). [sources: src/devops_cli/roadmap/stage/stage_pending.py, src/devops_cli/config/constants.py:4494, docs/ROADMAP_WORKFLOW.md] - How does a branch delete refuse a moved tip?: The step deletes with
git push --force-with-lease=refs/heads/<branch>:<sha> origin :refs/heads/<branch>against the judged tip. The lease refuses the delete when the tip moved. (best practice) [sources: docs/SDLC.md, docs/ROADMAP_WORKFLOW.md]- Chosen:
git push --force-with-leasewith the judged tip. Git is present. The lease refuses the delete when the tip moved. - Rejected:
git push --force. It deletes a branch whose tip moved and can discard work. - Rejected: read the tip with the GitHub API and delete the ref. The read and the delete are two requests. A tip can move between them.
- Chosen:
- Which branches does the cleanup delete?: It deletes an orphan branch with a
stage.pendingmark older than 3600 s, no pull request and no live unit. It also deletes the App-only branches of closed items and the empty App-only branches of items that are not Ready. feat(roadmap): scaffold makes, resumes or adopts the item branch #5499 later replaces the 1-hour delete of an App-only branch of a Ready item with an adopt. (best practice) [sources: CONTEXT.md, docs/ROADMAP_WORKFLOW.md, src/devops_cli/roadmap/stage/stage_pending.py]- Chosen: orphan rule plus the App-only rules. The owner decision states the two App-only rules. The orphan rule keeps the age, the pull request and the live unit.
- Rejected: orphan rule alone. It leaves the App-only branches of closed items and of not-Ready items on
origin. - Rejected: delete no branch of a Ready item. The 1-hour delete of an App-only branch of a Ready item holds until feat(roadmap): scaffold makes, resumes or adopts the item branch #5499 merges and replaces it with an adopt.
- What does the two-branch check build in this item?: The gauge
devops_cli_roadmap_issue_branches, an alert ink8s/devops/monitoring/prometheus-rules-values.yamlwhen one issue has two branches for more than 1 h, and a promtool rule test. The-ncandidate suffix stays out because feat(roadmap): a job can run candidates and a judge #5533 owns it. (best practice) [sources: k8s/devops/monitoring/prometheus-rules-values.yaml, docs/TELEMETRY.md, CONTEXT.md]- Chosen: the gauge, the alert and a promtool rule test. The owner decision asks for the gauge and the alert. Its checklist asks for the promtool rule test.
- Rejected: build the
-ncandidate suffix now. feat(roadmap): a job can run candidates and a judge #5533 builds the suffix only when the check finds a real case. - Rejected: a count metric with no alert. The owner decision asks for the alert and its promtool rule test.
- Where does the cleanup step module and its command live?: One module
src/devops_cli/roadmap/steps/cleanup.pywith the commanddevops roadmap step cleanup, one JSON result line, and exit 0, 1 or 75. It sends no request with--dry-run. (best practice) [sources: CONTEXT.md, src/devops_cli/roadmap/run.py, docs/CLI_REFERENCE.md]- Chosen: one module
steps/cleanup.pywith one command. Every roadmap step is one module and one command. Every caller uses it. - Rejected: keep the rules inside
stage.py. The stage round runs on the model lane and waits behind refine.
- Chosen: one module
- Which candidate-branch rules does this item build?: None. feat(roadmap): a job can run candidates and a judge #5533 adds the two candidate rules and their tests if this item merges first. The default stays 1 candidate, with no candidate branch. (best practice) [sources: CONTEXT.md]
- Chosen: leave the candidate rules to feat(roadmap): a job can run candidates and a judge #5533. The body states that feat(roadmap): a job can run candidates and a judge #5533 adds the two rules and their tests when this item merges first.
- Rejected: build the candidate rules here. The candidate branches and their judge come with feat(roadmap): a job can run candidates and a judge #5533. This item cannot test them.
- Which test asserts the new status-lane row?:
STATUS_ROW_NAMESis attests/roadmap/test_roadmap_status_rows.py:56and its test is attests/roadmap/test_roadmap_status_rows.py:96. The filetests/roadmap/steps/test_roadmap_due_steps.pytestsdue_stepsof the watch row, not the lane rows. [sources: tests/roadmap/test_roadmap_status_rows.py:56, tests/roadmap/test_roadmap_status_rows.py:96, src/devops_cli/roadmap/steps/watch.py:240] - How does the cleanup judge a closed plan pull request one time?: It writes the judgement as the rejection evidence of the item. It reads that evidence before a judge request, so a second tick sends no second request.
closed_plansatsrc/devops_cli/roadmap/stage/stage_rejected.py:227supplies the closed plan pull requests. (best practice) [sources: src/devops_cli/roadmap/stage/stage_rejected.py:227, CONTEXT.md]- Chosen: use the rejection evidence as the marker. The evidence already exists for a closed plan. GitHub state is the first marker of a roadmap step, so a second run changes nothing.
- Rejected: keep a second ledger of judged pull requests. It adds a state file to keep and to reconcile. The evidence is the durable record.
- Rejected: judge the pull request on each tick. It sends a request again and again for one closed plan.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 12, 2026
Both touch the orphan-branch cleanup in stage.py, but #4051 fixes a specific failed-marks-write defect while the candidate moves all cleanup to a status lane for throughput.feat(roadmap): run each stage item in its own Job (#5559)
devops-cli-service commentedon Nov 15, 2026
Alternatives check: not-applicable
Class: refactor. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 16, 2026
Status set to Ready at 7e1f8a8 (see proposed design in issue body).
Moved to new items: #5996.
dan-petty commentedon Nov 20, 2026
Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.
devops-cli-service commentedon Nov 26, 2026
Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.
devops-cli-service commentedon Dec 1, 2026
Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.