Merging Concurrent Agent Patches by Base Commit, Not Arrival Time
A deterministic merge protocol for concurrent AI coding agent patches, using base commit hashes, diff digests, and hunk ownership instead of arrival time.
When multiple coding agents branch from the same base commit and produce independent patches, applying whichever finishes last quietly makes completion timing part of repository correctness. This entry describes a protocol that instead binds merge decisions to a patch envelope: base commit hash, diff SHA256, explicitly owned hunks, and required check commands.
The deterministic decision flow verifies the digest and base, checks for overlapping hunk ownership, attempts a rebase in an isolated worktree, and runs the union of required checks before emitting a candidate commit or conflict record. Critically, task start time, completion time, agent identity, and retry count are excluded from the decision — they're operational metadata, not merge semantics.
Conflicts are grouped into three classes: textual (same lines changed), structural (a function moved while being edited), and behavioral (separate files breaking one shared invariant). Git reliably catches only the first class; the third still depends on repository-owned tests and critical-path ownership rules.
A reproducible fixture — two patches touching the same hunk plus one independent patch, fed in both arrival orders — is used to assert identical conflict records, identical rebase results, and idempotent reprocessing of accepted patch IDs. Limitations include hunk ownership going stale as code moves and tests being unable to prove every invariant holds, which is why a human resolution path stays part of the protocol rather than an afterthought.
This synthesis was produced from its source by AI; there is no human editor or manual review step. How we work