Skip to content

fix(roadmap): the stage orphan cleanup strands a kept branch #6668

Done

Description

@dan-petty

Problem

The orphan cleanup of stage keeps the App-only branch of a Ready item, but it also clears the stage.pending mark of that item. _remove_staged (src/devops_cli/roadmap/stage/stage.py, about line 4186) sets every key of STAGE_REMOVAL_KEYS to None, and the set holds stage.pending. _resumable_branches (about line 3204) resumes a branch only while stage.pending is set. So after the cleanup the item has a kept branch and no mark, and every later round leaves it out as "held by a pushed branch". The docstring of _remove_staged says that the branch is kept "so the stage pipeline can resume on it". No real record can do that.

Evidence

A review of #6664 ran this with the real git stage_repo fixture, on main 637e425 and on the branch of #6664. Both gave the same result:

  1. A stage Job stops after its push. The record keeps stage.pending, and origin keeps the App-only branch.
  2. The Service row run_stage_round selects the item as an orphan. StageWriter.begin keeps the branch and clears stage.pending.
  3. The next Job runs plan_stage for the item. Result: nothing staged, no model call, and the item is left out with "Issue 1 is held by a pushed branch".

The item stays stuck until a person deletes the branch.

Expected

When the cleanup keeps the branch, it keeps stage.pending too, so the next round resumes on the branch. _stage_one already writes the mark again before its push and clears it on success.

Acceptance criteria

  • A test with the real git stage_repo fixture: after the orphan cleanup keeps the App-only branch of a Ready item, the next round resumes on it and stages the item.

Source

Source: #6664

Alternatives check of 2026-11-21: none.
Tool: none found.
Reason: Searches for resumable stage pipelines and kept-branch resume found no tool or library. The defect is in the project's own _remove_staged and _resumable_branches code, which no external tool covers; #6528 owns the fix.

Lacks:

  • Keeps stage.pending when an App-only branch is kept
  • Resumes the next stage round on the kept branch
  • Real git stage_repo test for the orphan-cleanup resume case

Proposed design

Problem statement

The stage orphan cleanup keeps the App-only branch of a Ready item but clears stage.pending, the mark that _resumable_branches needs to resume on that branch, so every later round leaves the item out as held by a pushed branch and a person must delete the branch. The cleanup SHALL keep the mark when it keeps the branch, clear it when it deletes the branch, and clear it when a plan stops on the budget so the stop and its owner question stand; a test with the real git stage_repo fixture proves the next round resumes on the kept branch.

Acceptance criteria

Requirement: Kept branch keeps the resume mark

The stage orphan cleanup SHALL keep stage.pending set when it keeps the App-only branch of a Ready item.

Scenario: Cleanup keeps the mark

  • WHEN A test calls _remove_staged for a Ready item whose record holds stage.pending and whose App-only branch the cleanup keeps.
  • THEN The record still holds stage.pending, and every other key of STAGE_REMOVAL_KEYS is None.

Requirement: Deleted branch clears the resume mark

The stage orphan cleanup SHALL clear stage.pending when it deletes the branch of an item.

Scenario: Cleanup deletes the branch

  • WHEN A test calls _remove_staged for an item whose branch the cleanup deletes from origin.
  • THEN The record has stage.pending set to None.

Requirement: Budget stop clears the kept mark

A stage round that stops a Ready item on the token budget MUST clear stage.pending, so the next round does not resume the item and the stop stands.

Scenario: Stop keeps its owner question

  • WHEN A test resumes a Ready item on its kept branch and the plan stops on the budget through _stop_on_budget.
  • THEN The record holds stage.needs_split and stage.file_cap and has stage.pending set to None, and the next round judges no orphan for the item.

Requirement: Kept branch resumes in the next round

The next stage round SHALL resume on the kept App-only branch and stage the Ready item.

Scenario: Next round resumes

  • WHEN A test with the real git stage_repo fixture removes a Ready item whose stage Job stopped after its push, origin holds its App-only branch, and the next round runs plan_stage.
  • THEN The next round stages the item on the kept branch, makes its model call, and does not leave the item out as held by a pushed branch.

Existing Tool Considered

The alternatives check of 2026-11-21 in the issue body records verdict none and names no tool; a further search for an open, maintained tool or library that resumes work on a kept git branch after a cleanup found none. No external tool covers the stage record of this project, so the fix stays in the project's own _remove_staged and _stop_on_budget code and their tests. The block in the issue body lists what that code lacks. The written cost to build, keep and fix that code is about 40k tokens and about one day.

Key questions

  • Which code clears the stage mark that a resume needs?: _remove_staged writes None for every key of STAGE_REMOVAL_KEYS (src/devops_cli/roadmap/stage/stage.py:4208). STAGE_REMOVAL_KEYS is every plan key but the failure ledger (src/devops_cli/roadmap/stores/store.py:327), and stage.pending is one of those keys (src/devops_cli/roadmap/stores/store.py:288). _resumable_branches resumes a branch only while stage.pending is set (src/devops_cli/roadmap/stage/stage.py:3248). [sources: src/devops_cli/roadmap/stage/stage.py:4208, src/devops_cli/roadmap/stores/store.py:327, src/devops_cli/roadmap/stores/store.py:288, src/devops_cli/roadmap/stage/stage.py:3248]
  • What does the project say the kept App-only branch is for?: The docstring of _remove_staged says the App-only branch of a Ready item is kept so the stage pipeline can resume on it (src/devops_cli/roadmap/stage/stage.py:4201), and docs/ROADMAP_WORKFLOW.md:149 and docs/roadmap/stage.md:163 say the next round resumes on the kept branch and plans the item again. The sentence of docs/roadmap/stage.md:163 that the cleanup clears the record is what the code does today; the change corrects that sentence to the kept intent mark. [sources: src/devops_cli/roadmap/stage/stage.py:4201, docs/ROADMAP_WORKFLOW.md:149, docs/roadmap/stage.md:163]
  • Which issue must land before this fix?: None. The stage-on-phases design held this fix for refactor(roadmap): run stage on Coder in the runner image #6528 (openspec/changes/archive/2026-11-21-6704-stage-on-phases/design.md:11), and that work landed as refactor(roadmap): the stage agent is stock Coder #6705, the owner decision in ADR 0036 that stage runs stock Coder with publish (docs/adr/0036-the-stage-agent-runs-stock-coder-and-publish-checks.md:13, openspec/changes/archive/2026-11-23-6705-stage-agent-stock-coder/proposal.md:5). refactor(roadmap): re-architect stage and implement on Coder #6519 is the tracker of the re-architecture, and a tracker names no blocker (docs/roadmap/refine.md:31), so this item carries no dependency and can be built now. (best practice) [sources: openspec/changes/archive/2026-11-21-6704-stage-on-phases/design.md:11, docs/adr/0036-the-stage-agent-runs-stock-coder-and-publish-checks.md:13, openspec/changes/archive/2026-11-23-6705-stage-agent-stock-coder/proposal.md:5, docs/roadmap/refine.md:31]
  • Why is the kept mark safe for a new plan and for a budget stop?: A record that holds a recorded plan holds stage.pr, and orphan_mark reads an item with a pull request as no orphan (src/devops_cli/roadmap/stage/stage_pending.py:61), while _stage_one writes the plan keys and clears stage.pending in one write (src/devops_cli/roadmap/stage/stage.py:4094). The phase stop already clears stage.pending beside the stop (src/devops_cli/roadmap/stage/stage_job_phases.py:1040); the change adds the same clear to _stop_on_budget (src/devops_cli/roadmap/stage/stage.py:4156), which --phase all uses and which today keeps the mark, so a later orphan cleanup would erase stage.needs_split and stage.file_cap and resume the stopped item. [sources: src/devops_cli/roadmap/stage/stage_pending.py:61, src/devops_cli/roadmap/stage/stage.py:4094, src/devops_cli/roadmap/stage/stage_job_phases.py:1040, src/devops_cli/roadmap/stage/stage.py:4156]
  • What should the cleanup write when it keeps the App-only branch?: Keep stage.pending and clear the other removal keys; clear the mark when the cleanup deletes the branch; and clear the mark when a plan stops on the budget, so the stop and its owner question stand. _resumable_branches then resumes on the kept branch, and _stage_one clears the mark on a successful stage. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py:4208, src/devops_cli/roadmap/stores/store.py:327, src/devops_cli/roadmap/stage/stage.py:3248, src/devops_cli/roadmap/stage/stage.py:4094, src/devops_cli/roadmap/stage/stage.py:4156, src/devops_cli/roadmap/stage/stage_job_phases.py:1040]
    • Chosen: Keep the mark when the branch is kept, clear it on a delete and on a stop. The resume needs the mark, and the clear on a stop keeps stage.needs_split and stage.file_cap and their owner question.
    • Rejected: Clear every removal key. This is the current defect: it clears stage.pending and strands the kept branch.
    • Rejected: Remove stage.pending from STAGE_REMOVAL_KEYS for every cleanup. A cleanup that deletes the branch would leave a resume mark with no branch.
    • Rejected: Keep every removal key. Stale plan keys can block a new plan.
  • Is the stage job's <60 grade a rule against this fix?: No. The grade table gives the owner action Re-architect the workflow. for a job under 60% (docs/roadmap/job-success.md:85, src/devops_cli/roadmap/job_grade.py:137), which is the owner's action for the workflow and no ban on a defect fix. The recorded hold that froze incremental work on the stage job is a line in an item's Dependencies section (openspec/specs/roadmap-refine/waits/spec.md:221) that names chore(roadmap): hold incremental stage and implement work #6521 and not the tracker refactor(roadmap): re-architect stage and implement on Coder #6519 (docs/roadmap/refine.md:31), and this body carries no such hold. [sources: docs/roadmap/job-success.md:85, src/devops_cli/roadmap/job_grade.py:137, openspec/specs/roadmap-refine/waits/spec.md:221, docs/roadmap/refine.md:31]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    scope/roadmap
    on Nov 21, 2026
  2. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor
  3. added
    status/new
    value/medium
    effort/low
    priority/p2-medium
    on Nov 21, 2026
  4. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor

    This item waits for the stage re-architecture in #6528. Stage grades under 60%, and the owner rule for such a job allows no incremental fix, only the re-architecture. #6528 must keep this case in view: when a cleanup keeps an App-only branch of a Ready item, the next stage round must resume on it.

  5. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (2)

    Searches run:

    • resumable staged pipeline orphan branch cleanup tool, results: 5
    • open source tool resume work on kept git branch after cleanup, results: 5

    Sources:

  6. dan-petty commented on Nov 22, 2026

    @dan-petty
    OwnerAuthor

    The review of #6710 (PR A of #6528) tried the fix of this item that the body asks for: _remove_staged keeps stage.pending when it keeps the App-only branch. The fix makes the resume work, but it causes two new defects. So #6710 leaves this item out, and the re-architecture in #6528 takes it with the cases below in view.

    The review ran each case with the real git stage_repo fixture on head 16c91eb.

    1. A budget stop is erased. With stage.pending kept, the Service stage round judges the item as an orphan again in each round, until a Job records a draft. Each removal sets every key of STAGE_REMOVAL_KEYS except stage.pending to None, stage.needs_split and stage.file_cap too. So the next round erases a budget stop of the resumed Job, and the item goes to a Job again while its owner question is open.
    2. A new plan is erased. _orphans has no guard for an item that a running stage Job holds. While the resumed Job runs, a Service round can judge the item as an orphan from the listing that it read first. If the Job records its draft between that read and the writes of the round, the removal erases stage.branch, stage.pr and stage.sha of the plan that the Job just published.
    3. A kept branch can stay with no record. _resumable_branches matches every App-only branch of the issue by its number, but _stage_one pushes to the branch name of the current title. If the title changes between the dead Job and the resume, the item gets a new branch, and nothing deletes the kept branch.

    A plain design for #6528:

    • The orphan judgment skips an item that a running stage Job holds. run_stage_round already reads the running Jobs for read_stage_round.
    • A cleanup that keeps the branch writes no marks, and the resume writes the plan keys again.
    • The cleanup keeps only the branch of the current title, and deletes any other branch.
  7. 5 remaining items

  8. added
    status/new
    and removed
    status/ready
    on Nov 25, 2026
  9. added
    status/ready
    and removed
    status/new
    on Nov 25, 2026
  10. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  11. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 25, 2026
  13. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor
  14. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 17:09 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions