Repository navigation
Description
Problem or Motivation
The orphan rule (stage.py:1973), the rejected plans (stage.py:2006, stage_rejected.py:218) and the drafts of closed items (stage.py:2707) run only inside the stage round on the model lane. Stage waits behind refine there and gets one turn of 3 items in about 1.5-2 h (stage-drought C04). 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 push.pending 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. Start after push-step: it gives push.pending, and it merges after PR #4966, whose stage.py hunks (:1906-:1966) are next to _orphans (:1973).
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/).
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
-
chore(roadmap): hold incremental stage and implement work #6521 (hold: incremental work on the stage, implement and fix-checks jobs waits for the re-architecture)
-
fix(roadmap): the final push of the implement Job can miss the latest main #4957 (push-step: fix(roadmap): one push step holds main at every push)
-
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-21: not-applicable.
Class: refactor, no search.
Tool: none found.
Proposed design
Problem statement
Do not start this item until #6521 closes; the re-architecture holds it. Merge after PR #4966. The stage round runs the cleanup of the roadmap on the model lane and waits behind refine, while the cleanup calls no model. The change moves the cleanup to a cleanup row of the status lane and keeps the stage round 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 cleanupwith--dry-run. - THEN The step writes its JSON result line, sends no request and 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 row list
STATUS_LANE_ROWSof a repository is built. - THEN The list holds
cleanupandtests/roadmap/test_roadmap_status_rows.pyasserts it.
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 reports 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 names the delete in its result line.
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 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.
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 names each delete in its result line.
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 test
tests/roadmap/test_roadmap_run_metrics.pyasserts the gauge namedevops_cli_roadmap_issue_branchesand its issue label.
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 for the alert rule against two branches of one issue for more than 1 h. - THEN The check passes and the alert fires.
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, and the stage tests pass.
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 reports the pull request as judged.
Existing Tool Considered
The alternatives check of 2026-11-21 in the issue body gives not-applicable for this refactor item 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, the live unit and the App-only branches. The change builds src/devops_cli/roadmap/steps/cleanup.py and the cleanup row. The written cost is about 0.5M tokens and 0.5 agent-day.
Key questions
- Which lane runs the stage cleanup after the change?: The status lane. The cleanup runs as the short row
cleanupofSTATUS_LANE_ROWSon each tick. The stage round keeps only the planning. The cleanup uses no model, and stage waits behind refine on the model lane. After feat(roadmap): run the reconcile sweep on a cluster schedule #4574 builds the sweep, the row becomes a step of the sweep. (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:116, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:173, src/devops_cli/roadmap/run.py:1207]- 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 and gets one turn of 3 items in about 1.5-2 h.
- 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?: Three sites of
src/devops_cli/roadmap/stage/stage.pymove._reconcilecloses the draft and deletes the branch of each closed item._orphanscloses the draft and deletes the branch of an item that holdsstage.pendingand no pull request._rejectionswrites the evidence of a plan pull request that a person closed with no merge and deletes its branch._orphansis atsrc/devops_cli/roadmap/stage/stage.py:3136. The readclosed_plansis atsrc/devops_cli/roadmap/stage/stage_rejected.py:218. [sources: src/devops_cli/roadmap/stage/stage.py, src/devops_cli/roadmap/stage/stage.py:3136, src/devops_cli/roadmap/stage/stage_rejected.py:218] - Which mark does the orphan rule read, and how old is it?: The orphan rule reads
stage.pending. This JSON mark holds the branch name and the time in the item's job record (StageRecordKey.PENDING).orphan_markinsrc/devops_cli/roadmap/stage/stage_pending.pyreads it. A mark younger thanCONST_ROADMAP_STAGE_ORPHAN_AGE_SECONDSof 3600 s gives no action.push.pending, which the issue body names, is no mark in this repository at this commit. The push step of fix(roadmap): the final push of the implement Job can miss the latest main #4957 owns the push. [sources: src/devops_cli/roadmap/stage/stage_pending.py, src/devops_cli/config/constants.py:4341, docs/ROADMAP_WORKFLOW.md:148] - How does a branch delete refuse a moved tip?: Delete with
git push --force-with-lease=refs/heads/<branch>:<sha> origin :refs/heads/<branch>against the commit that the job judged. The lease names that tip, so a tip that moved after the judge refuses the delete. The step runs one lease check before each delete. (best practice) [sources: docs/SDLC.md:323, openspec/changes/archive/2026-11-06-3503-a-rejected-plan-leaves-its-evidence/design.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:229]- Chosen:
git push --force-with-leasewith the judged tip. The repository already has git. 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, and when?: The cleanup deletes an orphan branch with a
stage.pendingmark older than 3600 s. The branch has no pull request. Its item has no live unit of work. The cleanup also deletes the App-only branches of closed items. It deletes 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 and replaces the 1-hour delete of an App-only branch of a Ready item with an adopt. (best practice) [sources: docs/ROADMAP_WORKFLOW.md:148, src/devops_cli/roadmap/stage/stage_pending.py]- Chosen: orphan rule plus the App-only rules of the owner decision. The owner decision of 2026-11-13 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 item builds the gauge
devops_cli_roadmap_issue_branchesfor each issue. It builds an alert ink8s/devops/monitoring/prometheus-rules-values.yamlwhen one issue has two branches onoriginfor more than 1 h. It adds a promtool rule test intests/prometheus/test_k8s_monitoring_alerting.py. The-ncandidate suffix stays out, because D2 builds it only when the check finds a real case. The 24 h live proof after release is deferred to test(roadmap): prove the cleanup step runs as the App for 24 h #5996. (best practice) [sources: k8s/devops/monitoring/prometheus-rules-values.yaml:284, docs/CLUSTER.md:166, docs/TELEMETRY.md:136, tests/prometheus/test_k8s_monitoring_alerting.py, tests/fixtures/prometheus_rules/roadmap_service_activity_tests.yaml]- Chosen: the gauge, the alert and a promtool rule test. The owner decision of 2026-11-13 asks for the gauge and the alert. Its checklist asks for the promtool rule test.
- Rejected: build the
-ncandidate suffix now. D2 builds the suffix only when the check finds a real case. feat(roadmap): a job can run candidates and a judge #5533 owns the candidate branches. - 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?: The cleanup is one module
src/devops_cli/roadmap/steps/cleanup.pynext to the other step modules. It has the commanddevops roadmap step cleanupof the groupdevops roadmap step. It has the interface of a roadmap step. It has one module and one command, one JSON result line, and exit 0, 1 or 75. It sends no request with--dry-run. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md:233, docs/CLI_REFERENCE.md:326, src/devops_cli/roadmap/steps/ready.py]- 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. The body states that 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 the two candidate rules and their tests to the cleanup step. It keeps the candidate branches
<branch>-<i>while the judge of their item runs and deletes them 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 run. 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.
- Where does the status-lane row list live, and which test asserts the new row?: The row list is
STATUS_LANE_ROWSinsrc/devops_cli/roadmap/run.py:1207. The test that asserts the row names istests/roadmap/test_roadmap_status_rows.py:96, withSTATUS_ROW_NAMESattests/roadmap/test_roadmap_status_rows.py:56. The filetests/roadmap/steps/test_roadmap_due_steps.pytestsdue_steps(state)of the watch row, not the lane rows. [sources: src/devops_cli/roadmap/run.py:1207, 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?: The cleanup writes the judgement as the rejection evidence of the item. It reads that evidence before it sends a judge request. A second tick finds the evidence and sends no second request. The existing
closed_plansread insrc/devops_cli/roadmap/stage/stage_rejected.py:218supplies the closed plan pull requests. (best practice) [sources: src/devops_cli/roadmap/stage/stage_rejected.py:218, 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 model request again and again for one closed plan.
Fit
Fits in one pull request.
Suspected block
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.