Skip to content

feat(roadmap): automated rebase and plan rewrite for open plan branches #3969

Closed

Description

@dan-petty

Problem

devops roadmap plan-recheck --confirm can mechanically rewrite plans on the default branch. It updates missing verification commands and applies syntactic fixes.

However, open plan pull requests live on feature branches. When project conventions change (such as adding the $ prefix to verification lines or moving files), open plan branches become invalid. Currently, no automated mechanism applies mechanical plan rewrites or cleanly rebases open plan branches. Engineers must manually checkout the branch, rebase, edit files, and push.

Proposed change

Add automated rebase and mechanical plan rewrite support for open plan branches.

  1. Allow plan-recheck (or a dedicated command) to target open plan pull request branches.
  2. Check whether the branch can be cleanly rebased onto the default branch.
  3. Apply mechanical rewrites from plan_rewrite to update tasks.md format and verification commands.
  4. When the rewritten plan passes validation, commit and push the updated branch with lease protection.
  5. If merge conflicts occur, leave the branch unchanged and record the conflict reason.

Acceptance criteria

  1. A command or service row can evaluate and rewrite open plan pull request branches.
  2. The command cleanly rebases branches without conflicts onto the default branch.
  3. The command applies plan_rewrite transformations to tasks.md.
  4. The updated branch is pushed and CI checks are triggered.
  5. Unit tests verify clean rebasing, mechanical rewriting, and conflict avoidance.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

No open tool combines git branch rebasing with custom OpenSpec syntactic plan repairs. Building this feature requires approximately 30,000 tokens to build and 6,000 tokens annually to maintain. Elapsed time is approximately 4 hours.

Proposed design

Problem statement

Open plan pull request branches become stale when project conventions change. Engineers must manually rebase, edit and push each branch. The change adds a plan-recheck --branches path that rebases open plan branches, applies mechanical plan rewrites, validates the result, and pushes with lease protection. It leaves conflicting branches unchanged and reports the reason.

Acceptance criteria

Requirement: Branch target option

The devops roadmap plan-recheck command SHALL accept a --branches option that processes open plan pull request branches.

Scenario: Select open plan branches

  • WHEN A user runs devops roadmap plan-recheck --branches --confirm.
  • THEN The command lists open plan pull request branches and processes each returned branch.

Requirement: Clean rebase

The command SHALL rebase each open plan branch onto the current default branch before it applies plan_rewrite.

Scenario: Rebase a clean branch

  • WHEN The open plan branch has no conflicting changes with the default branch.
  • THEN The command completes git rebase origin/<default> in a temporary worktree and the worktree has the default branch as its base.

Requirement: Mechanical plan rewrite

The command SHALL apply plan_rewrite to the tasks.md of each rebased plan branch.

Scenario: Rewrite tasks.md

  • WHEN The rebased branch contains an OpenSpec change folder.
  • THEN The command runs rewrite_plan on the folder and stages only the lines that the rewrite changes.

Requirement: Validation before push

The command MUST validate the rewritten plan before it commits or pushes the branch.

Scenario: Reject an invalid rewrite

  • WHEN The rewritten plan fails the existing plan validation.
  • THEN The command leaves the branch unchanged and reports the validation failure.

Requirement: Lease-protected push

The command SHALL commit the rewritten plan and push the branch with --force-with-lease.

Scenario: Push with lease

  • WHEN The rewritten plan passes validation and the remote head still matches the fetched head.
  • THEN The command pushes the commit with --force-with-lease.

Requirement: Conflict avoidance

The command MUST leave the branch unchanged when a rebase conflict occurs.

Scenario: Rebase conflict

  • WHEN The branch conflicts with the default branch.
  • THEN The command aborts the rebase and reports the conflict reason.

Requirement: CI trigger

The command SHALL dispatch the repository CI workflow for the new head branch after a successful push.

Scenario: Dispatch CI after push

  • WHEN The command pushes the updated branch successfully.
  • THEN The command dispatches the CI workflow for the new head branch.

Requirement: Unit test coverage

The change MUST include unit tests for clean rebase, mechanical rewrite, and conflict avoidance.

Scenario: Run roadmap unit tests

  • WHEN The roadmap unit test suite runs.
  • THEN The tests cover a clean rebase, a plan_rewrite update, and a conflict that leaves the branch unchanged.

Existing Tool Considered

No alternatives check has run. The issue body states that no open tool combines git branch rebasing with custom OpenSpec syntactic plan repairs. The written cost is approximately 30,000 tokens to build, 6,000 tokens annually to maintain, and 4 hours elapsed.

Key questions

  • Which module applies mechanical plan rewrites?: src/devops_cli/roadmap/plan_rewrite.py holds rewrite_plan. src/devops_cli/roadmap/plan_recheck.py calls it. [sources: src/devops_cli/roadmap/plan_rewrite.py, src/devops_cli/roadmap/plan_recheck.py]
  • How should the feature be exposed?: Extend devops roadmap plan-recheck with a --branches option. (best practice) [sources: src/devops_cli/commands/roadmap.py, src/devops_cli/roadmap/plan_recheck.py]
    • Chosen: Extend plan-recheck with --branches. It reuses the existing rewrite, validation and confirm logic.
    • Rejected: Add a new plan-rebase command. It duplicates command wiring and validation.
    • Rejected: Add a service row only. It adds scheduling and runner work that this item does not need.
  • Which open pull request branches are in scope?: Open draft pull requests with a docs(openspec) title that contain an OpenSpec change folder. (best practice) [sources: CONTEXT.md]
    • Rejected: All open pull requests. Most open pull requests do not hold a plan.
    • Chosen: Open docs(openspec) draft pull requests with a change folder. It matches the staging definition of a plan pull request.
    • Rejected: Branches with a plan/ name. The repository does not define that branch name.
  • How should the command rebase and rewrite a branch?: Use a temporary worktree. Rebase onto origin/<default> first. Then apply plan_rewrite and validate the result. (best practice) [sources: CONTEXT.md, src/devops_cli/roadmap/plan_recheck.py, src/devops_cli/roadmap/plan_rewrite.py]
    • Chosen: Temporary worktree, rebase then rewrite then validate. It leaves the user checkout untouched and validates the final tree.
    • Rejected: In-place checkout, rewrite then rebase. It risks local state and can reintroduce old formatting.
    • Rejected: GitHub merge API only. It cannot run local rewrite or validation.
  • How should the command push the updated branch?: Commit the rewrite and push with --force-with-lease after fetching the remote head. (best practice) [sources: src/devops_cli/roadmap/plan_recheck.py]
    • Chosen: --force-with-lease. It protects a concurrent push and meets the lease requirement.
    • Rejected: Force push. It overwrites a concurrent push.
    • Rejected: Normal push. It rejects the rewritten history.
  • What should the command do when a rebase conflict occurs?: Abort the rebase. Leave the branch and pull request unchanged. Report the conflict reason. (best practice) [sources: src/devops_cli/roadmap/plan_recheck.py]
    • Chosen: Abort and leave unchanged. It avoids a partial state and satisfies conflict avoidance.
    • Rejected: Push conflict markers. It breaks the plan and CI.
    • Rejected: Close the pull request. It discards work that a person can resolve.
  • How should the command trigger CI after a push?: Dispatch ci.yml on the new head branch through the existing devops pr update --dispatch-ci path. (best practice) [sources: docs/adr/0004-ci-is-the-authoritative-gate.md]
    • Chosen: Dispatch CI explicitly. ADR 0004 uses --dispatch-ci for unattended branch updates.
    • Rejected: Rely on the push event only. The repository's unattended path does not rely on it.
  • Should a roadmap service row schedule the command?: No. This item adds the command only. A schedule is a separate item. (best practice) [sources: CONTEXT.md, src/devops_cli/commands/roadmap.py]
    • Chosen: Command only. It meets the command-or-service-row criterion and keeps one pull request.
    • Rejected: New service row. It adds scheduling, runner and budget work beyond this item.
    • Rejected: Both command and service row. It increases the size and risk of the pull request.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-09: partly.
Tool: cli/cli (https://github.com/cli/cli), MIT, last activity 2026-11-07, maintained.

Activity

  1. added
    source/agent
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It removes manual rebase work for engineers but does not block delivery or fix a defect.
    • Value: Medium. It saves repeated manual checkout, rebase, edit, and push cycles for each stale open plan branch.
    • Effort: Medium. The body estimates about 4 hours and 30,000 tokens, covering rebase logic, rewrite application, lease push, and unit tests.
    • Related: feat(roadmap): detect drift against default branch on open plan PRs #3968, which asks for a different change. Both address open plan PRs becoming stale after default-branch changes, but #3968 detects the drift while the candidate rebases and rewrites the branch to fix it.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 1f03ee3 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: The searches turned up no open tool that combines rebasing open plan branches with this project's OpenSpec plan_rewrite/validation, so the bespoke part of the item stays. The GitHub CLI (gh, with gh pr update-branch over the update-branch API) does cover the branch side: it selects open pull requests, updates their branch from the default branch, fails on a conflicting update, and pushes the new head so CI runs.

    Tool: cli/cli (https://github.com/cli/cli)

    • License: MIT
    • Last activity: 2026-11-07
    • Maintained: yes

    Covers:

    • Lists and selects open plan pull request branches (by title, draft state) through gh pr list.
    • Updates a pull request branch from the default branch server-side with gh pr update-branch, without checking the branch out locally.
    • Reports a conflict instead of writing a partial result when the update cannot be applied.
    • Pushes the new head to the remote branch, which triggers the branch's CI checks.

    Lacks:

    • Applies no mechanical rewrite: it cannot run rewrite_plan over the tasks.md of an OpenSpec change folder.
    • No local validation of the rewritten plan before the push, so an invalid rewrite is not rejected.
    • No control over history rewriting: it cannot commit a rewrite and push with --force-with-lease against the fetched remote head.
    • No temporary-worktree flow (rebase, then rewrite, then validate) and no recorded conflict reason on the branch.

    Tools considered:

    Searches run:

    • gh pr update-branch rebase pull request branch GitHub CLI, results: 5
    • tool to automatically rebase open pull request branches onto default branch, results: 5
    • "update-branch" REST API pull request branch GitHub docs, results: 5
    • Mergify auto rebase pull requests merge queue bot, results: 5
    • Renovate rebaseWhen configuration documentation, results: 5
    • Kodiak bot auto update pull request branch, results: 5
    • pre-commit run --all-files autoupdate hooks rewrite files, results: 5
    • gh pr update-branch documentation GitHub CLI manual, results: 5
    • git worktree rebase script automation rewrite files commit push force-with-lease, results: 5
    • automated branch rebase bot for open pull requests self-hosted, results: 5

    Sources:

    Checked on 2026-11-09. A person decides what this means for the item. The check changes no label and closes no issue.

  7. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the iteration lane plan (2026-11-11)

    This issue is child 5 of #4667. The scope adds one rule.

    Acceptance:

    • The scope names the push gate.
    • A test shows no push when only the base moved and the pull request has no conflict.

    Depends on: #4670.

  8. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the hooks review plan (2026-11-11)

    This issue is also child 3 of #4771 (hooks item P03). The scope comment of the iteration lane above holds the same change: the command pushes only when the plan rewrite changes the plan, and it pushes through push_branch of #4670.

    The hooks plan adds one acceptance criterion:

    • A test shows exactly one push when the rewrite changes tasks.md.

    Depends on: #4670.

  9. 16 remaining items

  10. added
    status/in-review
    and removed
    status/in-progress
    on Nov 18, 2026
  11. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Pull request #6310 is ready for review. The checks passed.

    Spend: 431 model requests, 52740004 input tokens, 178531 output tokens.

  12. removed
    status/in-review
    owner/service
    on Nov 18, 2026
  13. devops-cli-service commented on Nov 18, 2026

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

    @devops-cli-service
    Contributor

    Live since 2026-11-18 17:44 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/mediumpriority/p2-mediumscope/roadmapsource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions