Skip to content

feat(kernel): resolve merge conflicts on open Patchmill pull requests in the run loop - #416

Open
rochecompaan wants to merge 9 commits into
mainfrom
agent/issue-405-resolve-merge-conflicts-on-open-patchmill-pull-r
Open

rochecompaan wants to merge 9 commits into
mainfrom
agent/issue-405-resolve-merge-conflicts-on-open-patchmill-pull-r

Conversation

@rochecompaan

@rochecompaan rochecompaan commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #405

Before new work, an unattended run-once / patchmill run pass now finds a Done issue whose open Patchmill implementation pull request conflicts with the base branch. It resolves that conflict first, with an agent session that merges the base (never a rebase or force push). Patchmill then verifies the pushed branch.

Spec: docs/specs/2026-11-23-issue-405-resolve-merge-conflicts-on-open-patchmill-pull-r-design.md · Plan: docs/plans/2026-11-23-issue-405-resolve-merge-conflicts-on-open-patchmill-pull-r-plan.md

What changed

  • Detection: KernelGit.mergeConflict runs git merge-tree --write-tree on the fetched refs, so it behaves the same on every host and has no "unknown" state. KernelGit.isAncestor is new too. Facts.mergeConflict is set for an open implementation pull request into the base.
  • New module src/kernel/merge-conflicts.ts:
    • findConflictingPullRequests searches a candidate list that the caller supplies: open Done issues now, and the runner's own assignments in Add assignments and the patchmill run runner loop #360.
    • The attempt record (<runsDir>/issue-N/merge-conflict-attempt.json) and run.conflictRetryMinutes (default 30) set the backoff.
    • conflictResolutionGaps checks three things after the session: the branch still conflicts, its history was rewritten, or the base is missing. The result goes to verifyOutcome, and a failure stops with Needs Info.
  • runOneIssue: the search runs for unattended runs without --issue only. The run takes the first issue lock that is free, so a held lock falls back to normal selection. A conflict that is already gone stops with Done and no session.
    • A Conflict resolution is a run that the search selected, or that resumes from its attempt record. Its envelope says to resolve only the conflict.
    • Other implementation sessions on a conflicting pull request are told to merge the base first and then continue their normal work.
  • ownsPullRequest is now exported from pull-request.ts, so that ownership has one rule.
  • Git 2.38 or later is required. patchmill doctor has a new git check. The Nix wrapper puts nixpkgs Git first on PATH (--prefix), and the install check verifies this.
  • The implementation skill has a new ## Merge conflicts section, and the installed copy was refreshed with skills update. README and site docs are updated, and GLOSSARY.md has a new Conflict resolution entry.

Rulings (cost if wrong)

  • The Task 6 run-once tests were written after the implementation. I proved them by mutation: with the search disabled, 7 of 8 fail; with the gaps disabled, the push-without-merge test fails. Cost if wrong: a test that does not guard its behavior.
  • The needs-input test and the second-pass test are one test, because the second pass needs the first pass's record. Cost: none.
  • Final review, Minor 2 regraded to Important: a pull request that is closed or retargeted between the search and the claim reported "nothing to resolve" and published Done. Fixed: the shortcut now needs an open pull request into the base, with a RED→GREEN test. Cost if wrong: a false Done.
  • Two cases go through the normal path, because the spec matches an attempt only by the exact head and base: a paused resolution that a person resolves before the resume, and a resume after the base moved. Cost: one extra normal session.

Deferred minor findings

  • In label mode, an unattended pass calls listOpenIssues twice: once for the search and once for selection.
  • No tests cover the dry-run wording, or a stop request that arrives before any candidate lock is taken.
  • merged-cleanup.ts keeps its own copy of the base-branch rule. It could call resolveBaseBranch.

Validation

  • npm run lint: pass (0 errors)
  • npm test: 1780 pass, 0 fail
  • nix build -L (includes npm test and the install check): pass
  • PR checks on 80cc34a: Node test and lint, Nix package build, and Site audit and build all pass

Frontend review

Not applicable: kernel, Git, packaging, skill text, and docs only. There is no browser-visible change.

Human Reviewer Callouts (Non-Blocking)

  • Dependency/runtime change: Git 2.38 or later is now a hard requirement. npm users with older Git will see implementation runs on open PRs fail, and patchmill doctor reports why.
  • Packaging change: the Nix wrapper now puts nixpkgs Git first on PATH for Patchmill and all its child processes (Pi, gh, tea). A system credential helper named by a short name (for example libsecret) will no longer be found. The README documents this.
  • New config key: run.conflictRetryMinutes (default 30). The change is additive; unknown-key rejection is unchanged.
  • New local state file: <runsDir>/issue-N/merge-conflict-attempt.json. It is a backoff hint only, so no migration is needed.
  • Behavior change: unattended runs now move done issues back to inProgress and push merge commits to open PR branches without asking. No force push is used.

Patchmill run cost

Phase Model Prompt tokens Output tokens Estimated cost (USD)
Planning claude-opus-5-5 8,812,864 80,633 $0.0000
Planning Unknown model 5,861,721 64,277 $0.0000
Implementation claude-opus-5-5 15,683,908 60,961 $0.0000
Implementation Unknown model 2,503,027 26,851 $0.0000
Total 32,861,520 232,722 $0.0000

Includes all retained local runs for this issue, including specification and planning PRs. Prompt tokens include uncached input, cache reads, and cache writes. Estimated cost uses Pi's recorded model pricing and includes parent and subagent sessions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve merge conflicts on open Patchmill pull requests in the run loop

1 participant