Skip to content

feat(roadmap): rebase staged branch onto main before implement #4076

Closed

Description

@dan-petty

Problem or Motivation

When devops roadmap stage creates a plan pull request, it creates a topic branch from origin/main.

Implementation steps for that pull request can run much later. During the delay, other changes merge into main. The topic branch stays at the commit where it branched.

In pull request #4035 (issue #3253), the topic branch stayed 8 commits behind origin/main. Those 8 commits included a major test restructuring (pull request #4050). The GitHub pull request diff showed 216 files changed instead of the 3 files modified by the task.

When an implementation runner starts on a stale branch:

  1. The model inspects or modifies outdated files and paths.
  2. The pull request accumulates large diffs that hide the true changes.
  3. Merge conflicts occur late during step exit or PR merge rather than being detected early.

Proposed Solution & Architectural Design

  1. In src/devops_cli/roadmap/implement/implement_runner.py (or implement_step.py), fetch origin/main before running an implementation step on a staged branch.
  2. Check if the topic branch is behind origin/main. If the branch is behind and has no uncommitted changes, rebase the branch onto origin/main:
    • If the rebase succeeds cleanly, push with --force-with-lease or keep the rebased commit for the step.
    • If the rebase encounters conflicts, abort the rebase and fail early with a clear error: "Staged branch has conflicts with main; resolve conflicts before implementing".
  3. Add a CLI flag --no-rebase to devops roadmap implement to disable the automatic rebase when necessary.

Target Subsystem

AI & Agentic Review Pipeline

Existing Tool Considered

Git rebase command in git_support.py. Implementing this rebase check before step execution requires approximately 5,000 tokens to implement and test.

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 5, zero bare exceptions, tests that cover the changed lines).
  • I am willing to submit a pull request implementing this feature with accompanying tests.

Source: #3253

Proposed design

Problem statement

An implementation step can run on a staged branch that is many commits behind origin/main: the model then reads and changes outdated files, and the pull request diff grows to include other work. The job already does what the issue asks before the first step and before the push: it fetches the default branch and rebases the branch onto it, aborts and stops the item when the rebase conflicts, and pushes the result with a lease (src/devops_cli/roadmap/implement/implement_run.py:14, :641, :675, :1066). The remaining part of the issue is the escape hatch: a --no-rebase option that skips that fetch and rebase when a person runs the job.

Acceptance criteria

Requirement: The option skips the fetch and the rebase

devops roadmap implement SHALL accept a --no-rebase option that skips the fetch of the default branch and the rebase of the branch before the first step and before the push.

Scenario: The option skips both syncs

  • WHEN a runner Job runs roadmap implement --repo <owner/name> --item 7 --confirm --no-rebase in a real repository whose origin/main holds a commit that the branch lacks
  • THEN the worktree gets no git fetch -q origin main and no git rebase at the start or before the push, the branch keeps its commits, and the job pushes them with the lease

Requirement: The default run rebases before the first step

Without --no-rebase, the job SHALL fetch origin/<default> and rebase the branch onto it before the first step of an item.

Scenario: A branch behind the default branch

  • WHEN a staged branch is 8 commits behind origin/main and the job starts the item without --no-rebase
  • THEN before the first model request git merge-base --is-ancestor origin/main HEAD exits 0 in the worktree, and the branch's commits sit on top of the commit of origin/main

Requirement: A conflicting rebase stops the item

Without --no-rebase, the job SHALL abort a rebase that conflicts, leave the branch at its tip, and stop the item with the failure class conflict and the unmerged files in implement.conflict.

Scenario: A conflict with the default branch

  • WHEN git rebase origin/main stops with a conflict and the job runs without --no-rebase
  • THEN the job runs git rebase --abort, the branch head is the commit it was before the sync, and the stop comment and the record name the conflicted files

Requirement: The option is refused outside a runner

devops roadmap implement --item <n> --confirm SHALL refuse --no-rebase outside a runner, name the option and the devops k8s run-job command, and send no request.

Scenario: A workstation passes the option

  • WHEN a person runs devops roadmap implement --item 7 --confirm --no-rebase outside a runner
  • THEN the command exits 1, the message names --no-rebase and devops k8s run-job --template runner, and no cluster request is sent

Requirement: The dry run lists no rebase

devops roadmap implement --dry-run --no-rebase SHALL print the requests of the run without the rebase request.

Scenario: A dry run with the option

  • WHEN a person runs devops roadmap implement --repo owner/name --item 7 --dry-run --no-rebase
  • THEN the plan holds no git rebase origin/main request, and it still holds the push of the branch with its lease

Existing Tool Considered

Git, the open and maintained tool (https://git-scm.com/docs/git-push, fetched 2026-11-08; the page is current to git 2.56.0), covers the need: git fetch, git rebase, git rebase --abort and git push --force-with-lease do the work, and the job already wraps them in _ItemRun._git (src/devops_cli/roadmap/implement/implement_run.py:518) and _sync (src/devops_cli/roadmap/implement/implement_run.py:675). The body's git_support.py does not exist in this repository; the wrapper is _ItemRun._git, which calls git() of src/devops_cli/git/operations.py. Git lacks only the decision of when to skip the rebase, which is the --no-rebase option and its plumbing: about 1,000 tokens to build and test, about 500 tokens to keep and fix, over about 1 hour. The body's 5,000-token figure covered the whole rebase wiring, which already exists.

Key questions

  • Does the job already fetch origin/main and rebase the staged branch before the first step, and where does it run?: Yes. _ItemRun._start sets the step rebase and calls _sync, which runs git fetch -q origin <default> and git rebase origin/<default> before the first step; _ItemRun._push calls _sync again before the scoped checks and the push. Both calls are in src/devops_cli/roadmap/implement/implement_run.py, outside the agent step: the step runs one task group in one checkout, and the job writes the branch and the pull request, so the force push stays out of the step. [sources: src/devops_cli/roadmap/implement/implement_run.py:14, src/devops_cli/roadmap/implement/implement_run.py:641, src/devops_cli/roadmap/implement/implement_run.py:679, src/devops_cli/roadmap/implement/implement_run.py:1066, openspec/specs/roadmap-implement-job/spec.md:134, openspec/specs/roadmap-implement-step/spec.md:9, openspec/changes/archive/2026-11-05-3054-a-stopped-step-keeps-its-work/proposal.md:50]
  • Which branch does the job rebase?: The branch of the worktree that _worktree adds: the staged branch at origin/<branch> for a Staged item, or the new branch at the fetched default branch for a Planned item. One _sync covers both cases. [sources: src/devops_cli/roadmap/implement/implement_run.py:396, src/devops_cli/roadmap/implement/implement_run.py:675]
  • How does the job tell that the branch is behind origin/main?: It does not tell: after git fetch -q origin <default>, git rebase origin/<default> rebases a branch that is behind and is a no-op when HEAD already contains the default branch. One git call covers both cases, so the change adds no ancestor check. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py:679, openspec/specs/roadmap-implement-job/spec.md:134, openspec/changes/archive/2026-10-28-2415-review-session-head-commit/proposal.md:32]
    • Chosen: Rebase unconditionally after the fetch. The existing code, one git call, no output to parse; git rebase changes nothing when HEAD already contains the default branch.
    • Rejected: git merge-base --is-ancestor origin/main HEAD and its exit code. It adds a second git call and a branch for no change in behavior; its exit codes are 0 for an ancestor, 1 for not, and 128 for a commit the repository lacks.
    • Rejected: Parse git rev-list --count HEAD..origin/main. It parses a number from output and adds an error path.
  • Which push mode sends the rebased branch?: git push --force-with-lease=<branch>:<remote tip>, where the tip is the commit that the job read from origin/<branch>. A plain push is refused after a rebase rewrote the history, and --force would drop a commit that another actor pushed after the job's fetch. (best practice) [sources: src/devops_cli/roadmap/implement/implement_run.py:1131, openspec/changes/archive/2026-10-29-2665-implement-job/design.md:9, https://git-scm.com/docs/git-push/2.33.0]
    • Chosen: --force-with-lease=<branch>:<remote tip>. The job sends the tip it read, so a push over work that arrived after the fetch is refused and no commit of another actor is lost.
    • Rejected: --force. It drops a commit that another actor pushed.
    • Rejected: A plain push. It is refused after a rebase rewrites the history.
  • What does the job do when the rebase conflicts?: It reads the unmerged files with git diff --name-only --diff-filter=U, runs git rebase --abort, which puts the branch back on its tip, and stops the item with the failure class conflict. The stop comment names the branch and each conflicted file, the record holds them in implement.conflict, and a trusted person resolves the conflict and comments implement: retry. The reason is the existing text, which names the files, not the body's fixed sentence. [sources: src/devops_cli/roadmap/implement/implement_run.py:682, src/devops_cli/roadmap/implement/implement_run.py:698, openspec/specs/roadmap-implement-job/spec.md:1487, CONTEXT.md:138]
  • Is a CLI option or a setting the switch for the rebase, and does the option exist today?: A CLI option --no-rebase on devops roadmap implement, and it does not exist today: the option table holds --repo, --source, --item, --group, --filter, --limit, --format, --json, --dry-run, --plan, --confirm, --why, --context and --wait/--no-wait, and no --no-rebase. The option skips both _sync calls and nothing else: the job still commits, runs the scoped checks and pushes. The Service runs the job with no arguments, so the unattended path always rebases; a setting would let a stale branch run with no person noticing. (best practice) [sources: src/devops_cli/commands/roadmap.py:711, docs/CLI_REFERENCE.md:6836, docs/CLI_REFERENCE.md:6853, src/devops_cli/roadmap/implement/implement_run.py:641]
    • Chosen: CLI option --no-rebase only. It serves the person who debugs a branch, and it keeps the unattended path always current.
    • Rejected: A setting only. A person changes it away from the point of the run, and a wrong value stays for the Service.
    • Rejected: Both. It doubles the surface and the tests for one escape hatch.
  • How does a person pass --no-rebase to a job that runs in a runner?: With devops k8s run-job --template runner --repo <owner/name> -- roadmap implement --repo <owner/name> --item 7 --confirm --no-rebase. Outside a runner, devops roadmap implement --item 7 --confirm --no-rebase refuses the option and names that command, as --source, --filter and --limit already do through runner_only_options. (best practice) [sources: src/devops_cli/roadmap/implement/implement_outside.py:51, src/devops_cli/roadmap/implement/implement_outside.py:65, src/devops_cli/commands/roadmap.py:761]
    • Chosen: Refuse outside a runner and name the run-job command. It follows the existing runner-only options, and the person adds the option to the command that makes the Job.
    • Rejected: Forward the option into the Job args. job_args builds the args for the Service too, and a flag of a person would reach the unattended path.
  • Does the job rebase a checkout that has uncommitted changes?: No. _worktree adds the worktree from origin/<branch> or from the fetched default branch, so it is clean at the start, and a step refuses a checkout in which git status --porcelain lists a change. The person's --group path runs no sync at all. So the change adds no dirty-checkout guard and no stash. [sources: src/devops_cli/roadmap/implement/implement_run.py:396, src/devops_cli/roadmap/implement/implement_run.py:641, openspec/specs/roadmap-implement-step/spec.md:107]
  • Does a dry run fetch, rebase or push?: No. --dry-run is a request plan: it starts no process and prints the requests, which include the rebase and the push of the branch with its lease. With --no-rebase the plan omits the rebase request, which is built in implement_requests. [sources: src/devops_cli/roadmap/request_plan.py:844, src/devops_cli/roadmap/request_plan.py:855, src/devops_cli/roadmap/implement/implement.py:552, docs/CLI_REFERENCE.md:6848]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-10: partly.
Tool: git/git (https://github.com/git/git), NOASSERTION, last activity 2026-11-09, maintained.

Activity

  1. added
    source/agent
    on Nov 7, 2026
  2. added
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 7, 2026
  3. 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 prevents large misleading diffs and late merge conflicts, but the pipeline still completes without it.
    • Value: Medium. It reduces noise in pull request diffs and surfaces conflicts early, improving review quality for all implement runs.
    • Effort: Medium. It needs a fetch, a behind-check, a rebase with conflict handling, a CLI flag, and tests, roughly 5000 tokens per the body.
    • Related: feat(roadmap): devops roadmap implement runs every group of a staged change, archives it, fixes a failed check once and marks the pull request ready #2665, which asks for a different change. Both target the roadmap implement runner, but #2665 defines the group-run and archive flow while the candidate adds a rebase-onto-main step before that flow starts.
  4. added
    priority/p2-medium
    on Nov 7, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  6. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

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

  7. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: Git covers the rebase work (fetch, rebase, rebase --abort, push --force-with-lease), and the issue's own refine section says the job already wraps these in its own code. What is left is the --no-rebase option and its plumbing, which is project-specific CLI code and not something an outside tool provides. My one web search returned nothing relevant, so the Git facts come from the repository read and the issue text.

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

    • License: NOASSERTION
    • Last activity: 2026-11-09
    • Maintained: yes

    Covers:

    • git fetch of origin/main
    • git rebase onto origin/main
    • git rebase --abort on conflict
    • git push --force-with-lease

    Lacks:

    • The --no-rebase CLI option on devops roadmap implement
    • Refusing the option outside a runner
    • Leaving the rebase request out of the dry-run plan

    Tools considered:

    Searches run:

    • git rebase onto origin/main force-with-lease abort on conflict, results: 5

    Sources:

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

  8. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Close as not planned (hooks review, 2026-11-11)

    The behavior that this issue asks for exists on main:

    • _start calls _sync(push_on_conflict=False) before the first step (src/devops_cli/roadmap/implement/implement_run.py, near line 748). _sync fetches origin/<default> and rebases the branch onto it. _push calls _sync again before the push. fix(roadmap): rebase the branch before its first push #4380 (closed) delivered the rebase before the first push.
    • A rebase with a conflict aborts and stops the item with the class conflict.

    The remaining part of the refined design is the --no-rebase option. The owner requirement of 2026-11-11 makes a rebase onto the current origin/main right before each push mandatory, and #4670 does it in push_branch. The option would thus be an escape that the push gate defeats.

    Thus this issue should close as not planned (AGENTS.md rule 2). The agent run that wrote this comment could not close it, so a person closes it. It is child 4 of the hooks plan #4771.

  9. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 16, 2026
  10. removed
    status/in-review
    owner/agent
    on Nov 16, 2026
  11. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor
  12. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-16 03:02 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