cd /news/ai-agents/merge-concurrent-agent-patches-by-ba… · home topics ai-agents article
[ARTICLE · art-60394] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Merge Concurrent Agent Patches by Base Commit and Hunk Ownership

A developer proposes a deterministic merge protocol for concurrent AI agent patches that uses base commit, diff digest, and hunk ownership instead of completion timing. The protocol rejects overlapping ownership, rebases in isolated worktrees, and runs union of required checks to avoid 'last finisher wins' semantics. Tests on a disposable repository with three branches and two arrival orders should produce identical results from the same repository state.

read2 min views1 publishedJul 15, 2026

Two coding agents start from commit A. One finishes quickly and merges as B. The second finishes later with a patch that was valid against A.

Applying the second patch because it arrived last makes completion timing part of repository correctness. The merge protocol needs explicit inputs.

{
  "patch_id": "p-204",
  "base_commit": "4f2c1d...",
  "paths": ["src/parser.ts", "test/parser.test.ts"],
  "owned_hunks": [
    {"path":"src/parser.ts","start":88,"end":112,"symbol":"parseHeader"}
  ],
  "required_checks": ["npm test -- parser"],
  "diff_sha256": "..."
}

The base commit and diff digest bind review to exact bytes. Path and hunk ownership are conflict hints, not proof that independent patches compose semantically.

receive patch
  -> verify digest and base exists
  -> compare with changes since base
  -> reject overlapping ownership
  -> attempt rebase in isolated worktree
  -> run union of required checks
  -> emit candidate commit or conflict record

Do not choose a winner by task start time, completion time, agent identity, or retry count. Those fields are operational metadata, not merge semantics.

Conflict Example Action
textual same lines changed reject to resolution queue
structural function moved while edited require semantic review
behavioral separate files alter one invariant tests or owner rule must detect

Git catches much of the first class. It cannot reliably infer the third. Repository-owned tests and critical-path ownership remain part of the protocol.

Create a disposable repository with commit A and three branches:

parseHeader

;Merge P1. Feed P2 and P3 to the coordinator in both arrival orders. Assert:

Record Git version, base and result commits, command output, and tree hashes. A deterministic protocol should let another machine reproduce the same decision from the same repository state.

Hunk ownership becomes stale when code moves. Symbol extraction differs by language. Passing tests cannot prove two patches preserve every product invariant. These are reasons to expose conflict evidence and keep a human resolution path—not reasons to let “last finisher wins” become the hidden policy.

── more in #ai-agents 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/merge-concurrent-age…] indexed:0 read:2min 2026-07-15 ·