Skip to content

fix(roadmap): rebase the branch before its first push #4380

Closed

Description

@dan-petty

Problem Description

The implement job opens pull requests whose branch is behind main. Pull request #4378 (draft, branch feat/4004-allow-list-builder-for-planner-read) has one commit, wip: 1 of 2 tasks of group 1, on merge-base 52d5eb0. The job cloned at 14:05Z. It pushed the branch and opened the pull request at 14:26Z. In those 20 minutes main gained 3 commits (#4374, #4353, #4376). The branch was 3 commits behind when the pull request opened.

The job syncs only at two points in src/devops_cli/roadmap/implement/implement_run.py: at the start of the run (_start, which calls _sync) and at the final push (_push, which calls _sync). Every other push skips the sync:

  • the push of a wip: commit (_keep calls _push_passed);
  • the checkpoint push between groups (_checkpoint calls _push_passed);
  • the push at a stop (stop calls _push_passed);
  • the first push of a Planned item (_push_passed calls _publish, which runs git push -u origin <branch>).

The stage job has the same gap. _commit_and_push in src/devops_cli/roadmap/stage/stage.py pushes the plan branch from the staged commit with no rebase, after a run of 20 to 45 minutes. _moved_for fetches origin/<default> before the publish, but nothing rebases the branch onto it.

The repository does not require a branch that is up to date (this is on purpose), so GitHub does not enforce it. The job must do it.

Reproduction Steps

  1. Start an implement run on a Planned item with two or more tasks in group 1.
  2. While the first step runs, merge a commit into main.
  3. The step commits the first task as a wip: commit. The job pushes it and opens the draft.
  4. Run git merge-base origin/<branch> origin/main. It is not the tip of origin/main.

Expected vs Actual Behavior

Expected: before the first push of a branch, and before each later push, the job fetches the default branch and rebases onto it. A conflict follows the existing conflict path (abort, stop with the rebase reason, give the files to the next step).

Actual: the first push, the wip: pushes, the checkpoint pushes and the stop push send a branch that is behind main. The stage job also sends a plan branch that is behind.

Environment Diagnostics

Service runner, devops-cli 0.107.1 (main at 7d86a2b when the run started).

Logs, Traces, or Terminal Output

git log --format='%h %aI %s' origin/feat/4004-allow-list-builder-for-planner-read: one commit, 42d7879, wip: 1 of 2 tasks of group 1, authored 14:26:03Z. Merge-base 52d5eb0 from 14:05Z.

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate. Issue feat(roadmap): rebase staged branch onto main before implement #4076 asks for a --no-rebase option on the existing rebases; it does not cover the pushes that skip the sync.

Proposed design

Problem statement

Both roadmap jobs push branches that are behind the default branch. Only the start of the implement run and its final push rebase. The wip: push, the checkpoint push, the stop push, the first push of a Planned item and the stage push send a branch that is behind. The change fetches and rebases before each of those pushes, and a conflict takes the existing conflict path.

Acceptance criteria

Requirement: Every implement push rebases first

The implement job SHALL fetch the default branch and rebase the item branch onto it before each push of that branch.

Scenario: A checkpoint push after the default branch moved

  • WHEN The default branch gains a commit after the run started and the job makes a checkpoint push
  • THEN The pushed branch tip has the new tip of the default branch as an ancestor

Requirement: The first push of a Planned item is rebased

The implement job MUST rebase the new branch before _publish sends it and opens the draft pull request.

Scenario: A wip: push of a Planned item

  • WHEN A Planned item commits the first of two tasks and the default branch gained a commit
  • THEN The branch of the draft pull request has the new tip of the default branch as its merge-base

Requirement: A rebase conflict at a push stops the item

The implement job MUST stop the item when the rebase before a push conflicts, and it MUST record the unmerged files.

Scenario: A conflict at a checkpoint push

  • WHEN The default branch and the item branch change the same lines and the job rebases before a checkpoint push
  • THEN The job aborts the rebase, sets Status Blocked, and the comment and implement.conflict name the masked unmerged files

Requirement: The stop push keeps its work when the rebase conflicts

The implement job MUST push the branch at its aborted tip when the rebase before the stop push conflicts.

Scenario: A conflict at the stop push

  • WHEN The stop push rebases onto a default branch that conflicts with the branch
  • THEN The job pushes the branch at its tip with the lease, and the note of the stop names the rebase reason

Requirement: The push after a rebase carries the lease

The implement job MUST push a rebased branch with --force-with-lease on the remote tip that it read.

Scenario: A rebase rewrites a branch that is on origin

  • WHEN The job rebases a branch that origin already holds and then pushes it
  • THEN The push names the remote tip that the job read in --force-with-lease, and the branch on origin is the rebased head

Requirement: The final push checks the head that it sends

The implement job MUST run the scoped checks on the head that the final push sends.

Scenario: The default branch moves before the final push

  • WHEN The job reaches the final push and the default branch gained a commit
  • THEN implement.checked_sha and implement.published_sha equal the pushed head

Requirement: The stage job rebases the plan branch before the push

The stage job SHALL fetch the default branch and rebase the plan commit onto it before it pushes the plan branch.

Scenario: The default branch moves during the plan run

  • WHEN The default branch gains a commit while the job plans the item and the job commits the change
  • THEN The plan branch on origin has the new tip of the default branch as an ancestor

Requirement: A stage rebase conflict fails the item

The stage job MUST abort the rebase and fail the item with the reason and the unmerged files when the plan commit conflicts with the default branch.

Scenario: A conflict at the stage push

  • WHEN The plan commit and the default branch change the same lines
  • THEN The job aborts the rebase, pushes no branch, and the failure record and the run report name the masked unmerged files

Existing Tool Considered

No alternatives check has run. Git (https://git-scm.com) covers the need: git fetch and git rebase are the operation, and _sync already uses them. Git lacks nothing for the rebase. The change adds call sites, so it builds no merge code that it must keep.

Key questions

  • Which pushes of the implement job skip the fetch and the rebase today?: _start and _push are the only _sync callers. _keep, _checkpoint and stop call _push_passed, which calls _push_with_lease or _publish with no fetch or rebase. [sources: src/devops_cli/roadmap/implement/implement_run.py]
  • Does the repository require a branch that is up to date before a merge?: No. The main ruleset requires Static Analysis, Tests & Coverage and Semantic PR title, and it sets no strict up-to-date policy. GitHub does not enforce it, so the job must rebase. [sources: docs/adr/0004-ci-is-the-authoritative-gate.md]
  • Where does the implement job rebase before a push?: In _push_passed, the one funnel of every push that is not the final push: the wip: push, the checkpoint, the stop and the first publish of a Planned item. _push keeps its own _sync before the scoped checks, so the checks run on the head that it pushes. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py]
    • Chosen: _push_passed. One place covers the four pushes, and a new push site calls the same funnel.
    • Rejected: each call site. Four sites drift apart, and a new push site forgets the rebase.
    • Rejected: _publish only. The checkpoint and stop pushes stay behind the default branch.
  • What does a rebase conflict at a wip: or checkpoint push do?: It stops the item with the existing conflict path. _sync aborts the rebase and raises _StopError with the reason and the masked unmerged files. The job records them in implement.conflict for the next step. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py]
    • Chosen: stop the item. The branch is not left behind, and the unmerged files reach the next step.
    • Rejected: log the note and continue. The branch stays behind, and the conflict returns at the final push with more work at risk.
  • How does the stop push keep the last ticked task when its own rebase conflicts?: stop calls _push_passed(). On a _StopError from the rebase, it adds the reason to the note. It then calls _push_passed(rebase=False), which pushes the aborted tip with the lease. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py]
    • Chosen: push the aborted tip. The commit of the last ticked task still reaches origin.
    • Rejected: skip the push. The worktree goes, so the commit is lost.
    • Rejected: let the stop raise. A second _StopError escapes end_stopped and fails the whole run.
  • Does the push after a rebase need a lease?: Yes. A rebase rewrites the branch, so a plain push is refused. _push_with_lease sends --force-with-lease=<branch>:<remote tip> with the tip that the job read, so a push of another person is never overwritten. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py]
    • Chosen: the lease. Git accepts the rewritten branch and keeps a push of another person.
    • Rejected: a plain push. Git refuses a non-fast-forward.
    • Rejected: --force. It overwrites a push of another person.
  • Where does the stage job rebase the plan branch?: The rebase goes in _commit_and_push, after the one commit and before git push -u, on the worktree. Its fetch reads the same origin/<default> ref that _moved_for fetched before the publish. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py]
    • Chosen: after the commit, in _commit_and_push. The one plan commit is replayed onto the fetched default before the push.
    • Rejected: before the commit, by moving the worktree base. The worktree starts at the staged commit that _moved_for compares, so the moved-path report would change.
    • Rejected: in _stage_one after the push. The push is inside _commit_and_push, so the rebase would come after it.
  • What does a stage rebase conflict do to the item?: It aborts the rebase, pushes no branch, and fails the item with the reason and the masked unmerged files. The failure record and the run report name them, and a later round re-plans the item after the wait of its class. (best practice) [sources: src/devops_cli/roadmap/stage/stage.py]
    • Chosen: fail the item with the reason. The plan no longer applies to the moved tree, and a later round re-plans it.
    • Rejected: return the item to New. The plan is not at fault, and a return loses the review of the plan.
    • Rejected: push the branch without the rebase. That is the defect.
  • Do both jobs share the conflict listing?: Yes. A new helper src/devops_cli/roadmap/rebase.py holds fetch_and_rebase(path, default). It fetches, rebases, aborts on a conflict and returns the raw output with the masked unmerged files. Each job builds its own message from it. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py, src/devops_cli/roadmap/stage/stage.py]
    • Chosen: a shared helper. One fetch, rebase and abort path, and one masked file list.
    • Rejected: a copy in each job. Two listings of unmerged files drift apart.
    • Rejected: stage imports the private helpers of implement_run. A job module must not import another job's private functions.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 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/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. Every implement run produces a PR behind main, degrading review but not blocking delivery.
    • Value: Medium. Larger diffs and missed conflicts slow review and increase merge risk for every task.
    • Effort: Medium. Multiple push paths in implement_run.py and stage.py need a rebase call plus conflict handling.
    • Related: feat(roadmap): rebase staged branch onto main before implement #4076, which asks for a different change. Both add a rebase before push, but #4076 covers the gap between stage and implement start while the candidate covers wip, checkpoint, stop, and first pushes inside the run.
  3. added
    priority/p2-medium
    owner/agent
    on Nov 10, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 10, 2026
  5. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 04db2fc (see proposed design in issue body).

  6. added
    status/in-review
    and removed
    status/ready
    on Nov 10, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 10, 2026
  8. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-10 16:07 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/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions