Skip to content

Conflict forecast: warn when parallel worktrees are heading for a merge conflict (#249) - #369

Merged
currentbits merged 3 commits into
mainfrom
coder/conflict-forecast-predict-merge-conflict-5c2056
Aug 17, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/conflict-forecast-predict-merge-conflict-5c2056

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #249.

With several agents editing the same repo in parallel worktrees, you only find out two threads collided when the second one merges. This adds a proactive signal: thread cards now warn while both threads are still running.

How it works

git merge-tree --write-tree --name-only already performs a real dry-run 3-way merge between two branches without touching a working tree — so there is no heuristic function/class parsing here, git itself answers the question.

For each project, conflictForecast() in electron/worktrees.js:

  1. Collects active threads (not archived, has a branch, worktree exists on disk).
  2. Builds each thread's changed-file set: git diff --name-only <base>...<branch> unioned with its uncommitted git status --porcelain.
  3. Emits a pair only where two sets intersect — that intersection is overlap.
  4. Runs merge-tree on those pairs only; the files it reports on exit 1 become conflicts.

So conflicts non-empty means "these two will collide", while overlap-only means "same files, still auto-mergeable". Results are memoized 15s per project, and the function never throws — a project without a repo simply returns no pairs.

What you see

A chip on thread cards in the Sidebar and the Kanban board (Kanban reuses ThreadCard, so there is one badge implementation):

  • red conflict when any pair involving that thread has a real collision
  • amber overlap when the threads only share files
  • · N when the thread is in more than one pair

The native tooltip names the other thread and lists up to four hotspot paths.

Not on the Planboard — those cards are GitHub issues, not threads.

Wiring

New git:conflictForecast IPC channel through the usual five seams (src/shared/ipc.ts, electron/preload.js, electron/ipc.js, src/useCoder.ts) plus the two transports that must stay in sync (src/wireClient.ts, src/devCoder.ts — the dev mock fabricates a pair so npm run dev:browser renders the badge). The renderer refetches when the thread list changes; no new polling loop was added, since the main-process side is cached.

Deliberately left out

  • Function/class-level granularity — file-level first; worth adding only if it proves noisy in practice.
  • Cache invalidation on thread change (a 15s TTL covers it).
  • A background refresher.
  • merge-tree over uncommitted work: uncommitted edits contribute to overlap, but git cannot dry-run merge what is not committed. In practice checkpoints auto-commit each turn, so this rarely matters.

Tests

  • electron/test/conflict-forecast.test.js — real temp repo and real worktrees: disjoint files produce no pair, same file in far-apart regions produces overlap with no conflict, same line produces a conflict, and an uncommitted-only change still contributes to overlap.
  • test/conflictForecast.test.ts — the pure pairsForThread helper.
  • test/conflictForecastBadge.test.tsx — loud badge, quiet badge, and no badge.

Verified on this branch: npm run typecheck clean, and the electron plus renderer suites for these files pass (6/6 and 13/13). The full electron suite is baseline-clean — the pre-existing web-integration reconnect failure also fails on unmodified main.

  • PR created by the Claude Code agent

Willem and others added 3 commits August 17, 2026 20:54
Wires git:conflictForecast end to end with a stub implementation so the
backend and UI can be built in parallel against a fixed shape.

Co-Authored-By: Claude Opus 5 <[email protected]>
Scan active worktree threads for overlapping file edits vs the
base branch, then run git merge-tree to distinguish auto-mergeable
overlap from real collisions. Cache per project for 15s; never throw.
Surface the shared forecast on Sidebar and Kanban thread cards: red
"conflict" when git would collide, amber "overlap" for shared files,
with a tooltip of the other thread and the hotspot paths.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 2fd0e8c into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/conflict-forecast-predict-merge-conflict-5c2056 branch October 3, 2026 16:07
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.

Conflict forecast: predict merge conflicts between parallel worktrees before they happen

1 participant