Skip to content

fix(roadmap): the stage clone that is ahead of origin keeps its HEAD #3592

Closed

Description

@dan-petty

Problem or Motivation

The stage job moves its clone to the staged commit with git merge --ff-only (_move_clone in src/devops_cli/roadmap/stage.py, added for #3301). A clone that is ahead of origin/main and has no commit that origin lacks keeps its HEAD. The merge does nothing, and HEAD differs from the staged commit. The toolbox refuses that checkout (checkout_problem in src/devops_cli/roadmap/stage_tools.py). A plan with one model call and no toolbox reads the index of the clone, so its path check can accept a path that exists only in a local commit.

Proposed Solution & Architectural Design

After the fast-forward merge, check that HEAD equals the staged commit. Fail the run with the reason of git when it does not, so that no plan reads a commit it did not name.

Target Subsystem

The stage job of devops roadmap stage: _move_clone in src/devops_cli/roadmap/stage.py.

Proposed design

Problem statement

The stage job moves its clone to the staged commit with git merge --ff-only. Git reports a clone whose HEAD is ahead of the staged commit as up to date, and keeps that HEAD. A plan with no toolbox then reads a commit that the job did not name. _move_clone compares HEAD with the staged commit and fails the run, but the message names no reason and no test pins the behaviour.

Acceptance criteria

Requirement: An ahead clone stops the run

_move_clone SHALL raise GitOperationError when the clone's HEAD differs from the staged commit after the merge.

Scenario: A clone ahead of the staged commit

  • WHEN the clone's HEAD is a descendant of the staged commit and git merge --ff-only reports it up to date
  • THEN _move_clone raises GitOperationError and the clone keeps its local HEAD.

Requirement: The failure names the commit that the clone kept

The stage_clone_ahead message SHALL name the staged commit and the commit that the clone's HEAD holds.

Scenario: The message of an ahead clone

  • WHEN _move_clone fails on a clone whose HEAD holds a local commit
  • THEN the message holds the staged commit and the short hash and the subject of the clone's HEAD commit.

Requirement: The clone reaches the staged commit

_move_clone SHALL leave the clone's HEAD at the staged commit when the merge succeeds.

Scenario: A clone behind the staged commit

  • WHEN the clone's HEAD is an ancestor of the staged commit
  • THEN git rev-parse HEAD in the clone returns the staged commit, and _move_clone returns with no error.

Existing Tool Considered

No alternatives check has run. Git's own plumbing covers the need: git merge --ff-only moves the clone and git rev-parse HEAD reads its HEAD. Git lacks a mode that refuses a clone that is ahead, so _move_clone compares HEAD with the staged commit itself, at src/devops_cli/roadmap/stage.py:1626. The work is a few lines of src/ change and one regression test, so the build cost is one edit and no dependency.

Key questions

  • Does _move_clone compare HEAD with the staged commit after the merge?: Yes. _move_clone merges with --ff-only, compares git rev-parse HEAD with sha, and raises GitOperationError with the message stage_clone_ahead when they differ. [sources: src/devops_cli/roadmap/stage.py:1626, openspec/changes/archive/2026-11-05-3301-stage-reads-the-base-commit/tasks.md:60]
  • Does a test cover _move_clone?: No. The only reference to _move_clone is its call in plan_stage. The module tests/roadmap/test_roadmap_stage_tools.py tests checkout_problem and no move of the clone. [sources: src/devops_cli/roadmap/stage.py:1461, tests/roadmap/test_roadmap_stage_tools.py:562]
  • Which message holds the failure text of _move_clone?: The key stage_clone_ahead of MESSAGES.roadmap, in src/devops_cli/lang/en/messages.py. _move_clone formats it with the staged commit. [sources: src/devops_cli/roadmap/stage.py:1631, src/devops_cli/lang/en/messages.py]
  • Where does the regression test live?: Add it to tests/roadmap/test_roadmap_stage.py, the mirror module of src/devops_cli/roadmap/stage.py, and create that module when it does not exist. (best practice) [sources: openspec/specs/roadmap-stage/spec.md, tests/roadmap/test_roadmap_stage_tools.py:562]
    • Chosen: The mirror module tests/roadmap/test_roadmap_stage.py. The roadmap-stage spec puts a new test module in the mirror directory of its source, so the test sits with the tests of the stage job.
    • Rejected: The existing module tests/roadmap/test_roadmap_stage_tools.py. It tests the toolbox and its checkout_problem, not the move of the clone.
    • Rejected: A new module tests/roadmap/test_roadmap_stage_move_clone.py. A module for one function breaks the mirror rule and adds a file to keep.
  • How does the test make a clone that is ahead of the staged commit?: Build the repositories in tmp_path with real git commands: an upstream with one commit, a clone at that commit, and one local commit in the clone. Then call _move_clone with the upstream commit. (best practice) [sources: tests/roadmap/test_roadmap_stage_tools.py:562]
    • Chosen: Real repositories in tmp_path. The behaviour is git's own, so the real binary pins it, and the stage tests already read real checkouts.
    • Rejected: A mock of _git. A mock asserts the calls and not that git keeps the HEAD of an ahead clone.
  • What does the stage_clone_ahead failure name?: Name the staged commit and the commit that the clone's HEAD holds, with the short hash and the subject read by git log -1 --format=%h %s HEAD. (best practice) [sources: src/devops_cli/roadmap/stage.py:1631, src/devops_cli/roadmap/clone_git.py]
    • Chosen: The staged commit, and the hash and subject of the clone's HEAD. A person sees which local commit kept the HEAD, and a test asserts the two stable parts.
    • Rejected: The staged commit alone. The current message gives no reason, so a person cannot tell which local commit kept the HEAD.
    • Rejected: The raw output of git merge. The text depends on the locale and the git version, so the test is brittle.
  • Which tool moves the clone and checks its HEAD?: Git's own plumbing: git merge --ff-only and git rev-parse HEAD, through clone_git.git. (best practice) [sources: src/devops_cli/roadmap/stage.py:1626, src/devops_cli/roadmap/clone_git.py]
    • Chosen: Git's own plumbing. The module already runs git through clone_git.git with a fixed argument list, and the check needs one more call.
    • Rejected: GitPython. It adds a dependency for two commands that the repository already runs, and no check found a need.
    • Rejected: pygit2. It builds libgit2 and duplicates the git calls of the module.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-07: in-use.
The item already names this tool.
Tool: git/git (https://github.com/git/git), NOASSERTION, last activity 2026-11-07, maintained.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 5, 2026
  2. dan-petty commented on Nov 5, 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. A silent wrong-commit read can corrupt a plan, but the condition requires a clone ahead of origin, so it is not a constant failure.
    • Value: Medium. Prevents a plan from reading a commit it did not name, which is a correctness guarantee for the stage pipeline.
    • Effort: Low. The fix is a single HEAD-equality check after the existing merge call, with a clear failure message.
    • Related: fix(roadmap): a step whose agent moved HEAD is reset, not stopped #3575, which asks for a different change. Both address HEAD being in the wrong position in a git workflow, but #3575 resets HEAD after an agent moved it during a step, while the candidate checks and fails when the stage job cannot move HEAD to the staged commit.
  3. added
    priority/p2-medium
    on Nov 5, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 6, 2026
  5. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

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

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

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: The web searches returned no results (no provider answered), so I read the facts of git/git directly: Git is open and actively maintained. Git's own plumbing already does the work the issue needs — git merge --ff-only moves the clone and git rev-parse HEAD reads its HEAD so _move_clone can fail when the two differ — and the issue names Git as the tool the module already runs through clone_git.git.

    The item already names this tool.

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

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

    Covers:

    • git merge --ff-only moves a clone whose HEAD is an ancestor of the staged commit
    • git rev-parse HEAD reads the clone's HEAD so _move_clone can compare it with the staged commit and fail the run
    • git log -1 --format=%h %s HEAD names the short hash and subject of the commit the clone kept for the stage_clone_ahead message

    Lacks:

    • Git has no mode that refuses a clone that is ahead, so the HEAD comparison and the failure stay a few lines in _move_clone

    Tools considered:

    Searches run:

    • git-scm documentation git-merge fast-forward, results: 0
    • git merge --ff-only already up to date rev-parse HEAD verify clone at commit, results: 0
    • git merge --ff-only documentation, results: 0
    • git rev-parse HEAD, results: 0
    • GitPython library merge fast-forward, results: 0

    Sources:

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

  7. added
    status/in-progress
    and removed
    status/ready
    on Nov 14, 2026
  8. removed
    status/in-progress
    on Nov 14, 2026
  9. devops-cli-service commented on Nov 14, 2026

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

    @devops-cli-service
    Contributor

    Live since 2026-11-14 15:35 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