Skip to content

feat(roadmap): detect merge conflicts on open ready pull requests #4027

Closed

Description

@dan-petty

Problem or Motivation

The roadmap Service marks an implemented pull request ready when all CI checks pass.
Subsequent merges into the default branch can create merge conflicts with the open pull request.
For example, pull request #3961 was marked ready, but subsequent merges into main produced conflicts in capability specs and roadmap source files.
GitHub does not notify developers of conflicts unless they open the pull request page.
The Service does not monitor open ready delivery pull requests for merge conflicts against the default branch.
Consequently, conflicted pull requests stay blocked without notification until a person manually runs devops pr check-readiness.

Proposed Solution & Architectural Design

Add merge conflict detection and reporting for open ready delivery pull requests.

  1. In src/devops_cli/roadmap/run.py, add a check to the status lane or stage_ready row to evaluate open ready pull requests.
  2. For each open pull request whose base is the default branch:
    • Check the GitHub mergeable state via the GitHub API.
    • When the state is conflicting or dirty, add a label such as pr/conflicted or comment on the pull request.
    • When the branch is clean and behind main, trigger devops pr update to keep the branch synchronized.
  3. Integrate with devops pr check-readiness so that conflict state is tracked and exposed in the roadmap dashboard.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

GitHub's native mergeability check exposes whether a pull request has conflicts, but GitHub triggers no event or alert when background branch merges create new conflicts. Building this automated check in the Service row requires approximately 18,000 tokens to build and 4,000 tokens per year to maintain. Elapsed time is approximately 2 hours.

Proposed design

Problem statement

The roadmap Service marks a delivery pull request ready when its checks pass. A later merge into the default branch can create conflicts with that open pull request, and GitHub sends no alert for the new conflict. The pull request then stays blocked until a person runs devops pr check-readiness. The Service monitors no open ready delivery pull request for merge conflicts.

Acceptance criteria

Requirement: Status-lane conflict row

The status lane SHALL run a pr_conflicts row that evaluates the open ready delivery pull requests of the repository.

Scenario: Status lane table

  • WHEN the status lane table is built
  • THEN it contains a row named pr_conflicts last, after cloudflare_status.

Requirement: Delivery pull requests only

The row SHALL evaluate only open, non-draft pull requests whose base is the default branch and whose body closes exactly one open issue that holds a priority/* label.

Scenario: Plan pull request

  • WHEN an open non-draft pull request whose base is the default branch closes no issue
  • THEN the row skips it and posts no comment.

Requirement: Conflict comment

When the row reads a delivery pull request whose mergeable state is a conflict, it SHALL post one comment that names the default branch and asks to resolve the conflicts.

Scenario: Dirty mergeable state

  • WHEN the read returns mergeable false with mergeable_state dirty
  • THEN the row posts the conflict comment on that pull request.

Requirement: One comment per conflict

The row SHALL post no second conflict comment while the ledger records the pull request as conflicted at the same head SHA.

Scenario: Conflict persists

  • WHEN the row runs again with the same head SHA and the ledger records the pull request as conflicted
  • THEN it posts no second comment.

Requirement: Comment after a clean round

The row SHALL post the conflict comment again when a pull request becomes conflicted after a round that recorded it clean.

Scenario: Conflict returns

  • WHEN the ledger records the pull request as clean and the read reports a conflict again at the same head SHA
  • THEN it posts the conflict comment once.

Requirement: Unknown mergeable state

When GitHub reports the mergeable state as UNKNOWN, the row SHALL leave the pull request unchanged and check it in the next round.

Scenario: Unknown mergeable state

  • WHEN the read returns mergeable null with mergeable_state unknown
  • THEN the row posts no comment and keeps the ledger state.

Requirement: Clean behind update

When a delivery pull request is clean and behind the default branch, the row SHALL send one PUT /repos/{owner}/{repo}/pulls/{number}/update-branch that carries the head SHA it judged.

Scenario: Clean behind pull request

  • WHEN the read returns mergeable true with mergeable_state behind
  • THEN the row sends the update-branch request once with expected_head_sha equal to the head SHA.

Requirement: One conflict judgment

The row and devops pr check-readiness SHALL judge a conflict from the same mergeable states, so a pull request the command reports as conflicted is the one the row comments on.

Scenario: Check readiness and the row on one pull request

  • WHEN the pull request payload holds mergeable false with mergeable_state dirty
  • THEN the verdict and the row both report a conflict.

Requirement: Conflict gauge

The row SHALL emit a gauge with the number of conflicted ready delivery pull requests, labelled with the repository.

Scenario: Two conflicted pull requests

  • WHEN the row finishes a round with two conflicted pull requests
  • THEN it emits the gauge with value 2 and the repository attribute.

Requirement: Failed read fails its row

When the GitHub read fails, the pr_conflicts row SHALL fail and no other status row SHALL fail.

Scenario: Failed GitHub read

  • WHEN the GitHub API returns an error for one pull request
  • THEN the pr_conflicts row raises and the other status rows run.

Existing Tool Considered

GitHub's native mergeability state is the only tool considered. The REST read of one pull request returns mergeable and mergeable_state (https://docs.github.com/rest/pulls/pulls, fetched 2026-11-08), and devops pr check-readiness already reports a conflict from it. It lacks a scheduled check and a notification: no event or alert names a conflict that a background merge into the default branch creates, it emits no roadmap gauge, and it writes nothing to the item that the pull request delivers. No open, maintained tool or library was found that comments on an open delivery pull request, records the head SHA it commented on, and emits the Service's gauge. The plan builds the row in the Service: about 18,000 tokens to build, 4,000 tokens per year to maintain, and about 2 hours of elapsed time, as the body estimates.

Key questions

  • Should the row signal a conflict with a pr/conflicted label or with a comment?: Use a comment. It notifies the pull request watchers, needs no new label family in every managed repository, and GitHubClient.comment_on_pull already posts it. The label families hold the item fields, and a new pr/conflicted family would collide with them. (best practice) [sources: docs/adr/0016-labels-hold-the-roadmap-items-fields.md:9, src/devops_cli/github/client.py:402, src/devops_cli/roadmap/stage/stage_ready.py:105]
    • Rejected: pr/conflicted label. It needs a label in every managed repository, sends no notification, and conflicts with the label families that hold item fields.
    • Chosen: comment. It notifies the pull request watchers and needs no repository setting; comment_on_pull already posts a pull request comment through the session.
    • Rejected: both. It keeps two states that can drift.
  • Should the check run in the existing stage_ready row or in a new status-lane row?: Run it in a new pr_conflicts row at the end of STATUS_LANE_ROWS. The lane runs one row at a time, and the recorded decision puts the network-heavy status rows last so a slow read delays no other row. A separate row also makes a failed conflict read fail only its own row. (best practice) [sources: src/devops_cli/roadmap/run.py:739, CONTEXT.md:150, openspec/changes/archive/2026-11-08-4052-a-status-read-that-fails-fails/design.md:7]
    • Rejected: extend stage_ready. It mixes draft readiness with conflict monitoring, and a failed conflict read would fail the stage-ready row.
    • Chosen: new status-lane row last. It follows the recorded rule that a failed read fails its own row and that a network-heavy status row goes last.
    • Rejected: new row after stage_ready. It would put per-pull-request GitHub reads ahead of release_comments and the status pages, delaying them.
  • Which GitHub API path should read the mergeable state?: Read each candidate pull request through the GitHub session, GET /repos/{owner}/{repo}/pulls/{number}, as release/merge_candidate.py does: list the open pull requests into the default branch once, then read each candidate's payload. That payload holds mergeable and mergeable_state, the fields the readiness verdict judges. Do not call assess_merge_readiness for this: it also reads checks, review threads and changed files for every pull request. (best practice) [sources: src/devops_cli/release/merge_candidate.py:233, src/devops_cli/release/merge_candidate.py:275, src/devops_cli/github/merge_readiness.py:195, src/devops_cli/github/client.py:391, docs/adr/0006-github-session-requests-go-through-gidgethub.md:3]
    • Chosen: session REST read of each pull request. It is the recorded transport for the Service's GitHub reads, the payload holds mergeable/mergeable_state, and release/merge_candidate.py already lists open pull requests and reads each one.
    • Rejected: fetch_pr_details (gh subprocess). It runs the gh CLI for each read, which the session ADR rejects for the Service's own requests.
    • Rejected: full assess_merge_readiness. It reads the checks, the review threads and the changed files of every pull request for a judgment that needs two fields.
    • Rejected: one GraphQL list query. It needs a second definition of a conflict (GraphQL's enum names) and departs from the REST payload that check-readiness judges.
  • How should the row treat GitHub's UNKNOWN mergeable state?: Leave the pull request unchanged and check it again in the next round. The verdict already treats mergeable null or mergeable_state unknown as unresolved mergeability, not as a conflict, and GitHub computes mergeability on demand in the background, so a later read returns the settled state. The row polls, so the next round is the retry. (best practice) [sources: src/devops_cli/github/merge_readiness.py:204, tests/github/test_merge_readiness.py:382, docs/adr/0003-polling-is-how-the-roadmap-sees-changes.md:7, https://stackoverflow.com/questions/30619549/why-does-github-api-return-an-unknown-mergeable-state-in-a-pull-request]
    • Rejected: treat as clean. It would skip a real conflict.
    • Rejected: treat as conflicted. It would post false comments while GitHub still computes the state.
    • Chosen: wait for the next round. The state is unresolved, not a conflict, and the next poll can read the settled value.
  • Should the row auto-update a clean delivery pull request that is behind the default branch?: Yes. Send one PUT /repos/{owner}/{repo}/pulls/{number}/update-branch built by build_update_branch_cmd, with expected_head_sha equal to the head the row judged, so GitHub refuses the update when the branch moved. Do not run the devops pr update command: it is a Typer command that prints and requires the gh CLI. (best practice) [sources: src/devops_cli/github/branch_update.py:19, src/devops_cli/commands/pr.py:1976, src/devops_cli/commands/pr.py:1811]
    • Rejected: only report behind. It leaves the branch stale, and the issue asks to keep it synchronized.
    • Chosen: update-branch request with the judged head SHA. It reuses build_update_branch_cmd and its expected_head_sha guard, and needs no CLI process.
    • Rejected: run the devops pr update command. The command prints its own lines and requires the gh CLI; the row runs in the Service.
    • Rejected: rebase in the row. It duplicates the update-branch request and can rewrite commits.
  • How should the row avoid posting the same conflict comment every round?: Keep a ledger pr_conflicts.json beside schedule.json. For each pull request it records the head SHA and whether the last round found it conflicted or clean; a missing ledger reads as empty, and a ledger that exists and cannot be read fails the row and names the file. A lost ledger costs one duplicate comment, not a lost alert. (best practice) [sources: src/devops_cli/roadmap/run.py:644, src/devops_cli/roadmap/release_comments.py:53, k8s/README.md:673]
    • Rejected: comment every round. It spams the pull request.
    • Rejected: search for a hidden marker in comments. It needs a comment listing for each pull request and cannot tell a conflict that returned after a clean round at the same head SHA.
    • Chosen: ledger file. It follows the release_comments.json ledger that lies beside schedule.json, and it holds the previous round's state, which the two comment rules need.
  • What does the roadmap dashboard exposure mean for this change?: Emit one gauge with the number of conflicted ready delivery pull requests, labelled with the repository, as record_coverage emits its gauges. Do not build a new dashboard page. (best practice) [sources: src/devops_cli/roadmap/alternatives.py:1146, src/devops_cli/roadmap/run.py:691]
    • Rejected: new dashboard page. It duplicates the existing metrics pipeline and lies outside this repository.
    • Chosen: gauge only. The Service's metrics pipeline already emits gauges with a repository attribute.
  • How should the row read mergeable for many pull requests?: List the open pull requests whose base is the default branch once, then read each candidate pull request individually: the listing carries no mergeable fields, and release/merge_candidate.py lists the open pull requests and reads each one for its payload. [sources: src/devops_cli/release/merge_candidate.py:233, src/devops_cli/release/merge_candidate.py:275, openspec/changes/archive/2026-11-01-2915-roadmap-inbox/proposal.md:67]
  • Which pull requests count as delivery pull requests?: Open, non-draft pull requests whose base is the default branch and whose body closes exactly one open issue that holds a priority/* label. A plan pull request closes nothing, so the row skips it. [sources: .github/pull_request_template.md:3, docs/adr/0016-labels-hold-the-roadmap-items-fields.md:10, src/devops_cli/github/merge_readiness.py:485, src/devops_cli/roadmap/grounding.py:129]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-10: partly.
Tool: eps1lon/actions-label-merge-conflict (https://github.com/eps1lon/actions-label-merge-conflict), not stated, last activity 2026-05-27, maintained.

Activity

  1. added
    source/agent
    type/feature
    scope/roadmap
    status/new
    value/medium
    effort/low
    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 a manual step that blocks delivery but does not cause data loss or a security gap.
    • Value: Medium. It prevents ready PRs from sitting blocked without notification, saving developer time.
    • Effort: Low. The body states approximately 2 hours and 18,000 tokens to build.
    • Related: feat(roadmap): detect drift against default branch on open plan PRs #3968, which asks for a different change. Both monitor open PRs against the default branch, but #3968 detects plan drift on draft plan PRs while the candidate detects merge conflicts on ready delivery PRs and labels them.
  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 447f024 (see proposed design in issue body).

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

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: eps1lon/actions-label-merge-conflict is a maintained GitHub Action. It detects pull requests that conflict with the base branch and labels them or comments on them. The design needs more than that. It needs a ledger keyed on head SHA, a Service status-lane row, a gauge, an update-branch call for clean-but-behind pull requests, and the same conflict judgment as check-readiness. The Action provides none of these. I read only the repository facts, not the README, so the label and comment behaviour comes from my prior knowledge of the Action.

    Tool: eps1lon/actions-label-merge-conflict (https://github.com/eps1lon/actions-label-merge-conflict)

    • License: not stated
    • Last activity: 2026-05-27
    • Maintained: yes

    Covers:

    • Detects pull requests that conflict with the base branch after pushes to it
    • Labels or comments on conflicted pull requests

    Lacks:

    • Ledger of head SHA and conflict state to avoid repeat comments
    • Filter for delivery pull requests that close one priority-labelled issue
    • update-branch call with expected_head_sha for clean, behind pull requests
    • Roadmap gauge of conflicted pull requests
    • Shared conflict judgment with devops pr check-readiness
    • Runs as a status-lane row of the Service, not a GitHub Actions workflow

    Tools considered:

    Searches run:

    • GitHub action label or comment on pull requests with merge conflicts after push to main, results: 5
    • eps1lon/actions-label-merge-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.

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 11, 2026
  8. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope change for this item: pull request #4766 does not build the requirement "Clean behind update".

    docs/SDLC.md (Phase 1, step 5) tells us that an open pull request needs no rebase to catch up with main. An update-branch request on a clean pull request that is only behind main is such a catch-up update. It also starts a new CI run with no change in content.

    Thus the pr_conflicts row makes no update-branch request. A clean pull request that is behind the default branch gets no action. A conflicted delivery pull request gets one comment for each head SHA. The test test_a_clean_pull_request_behind_the_default_branch_gets_no_action in tests/roadmap/test_pr_conflicts.py shows the first rule. The archived proposal records the reason.

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

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

    @devops-cli-service
    Contributor

    Live since 2026-11-11 19:36 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/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions