Skip to content

merge3 reports conflicts as JSON and takes decisions on them - #25

Merged
MartenH merged 4 commits into
mainfrom
merge3-json-resolve
Oct 31, 2026
Merged

MartenH merged 4 commits into
mainfrom
merge3-json-resolve

Conversation

@MartenH

@MartenH MartenH commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

merge3 printed its conflicts as lines on standard error and kept ours, so a tool putting conflicts to a person had to parse text and could not say what was decided. This gives it a report to read and a way to answer.

Vendors flatxml at its squash of MartenH/flatxml#46.

What changes

  • merge3 --format json: writes the conflicts to standard output. It needs -o, since the result would otherwise go there too. Each conflict has an id, its kind and AUTOSAR path, and for each of the three versions its place, its value, and the element around it as the file has it. Described in docs/report.md, with a schema in docs/merge3.schema.json.
  • merge3 --resolve FILE: takes the decisions back, ours ID or theirs ID a line. The result holds the side named, and when every conflict is decided the exit code is 0.
  • The id: a hash of the conflict's kind, path, place among like items, what the base has there and what each side made of it: where a move goes and, for a removal or a move, all that a side changed in the node. No file name or line goes in, so a git merge driver's temporary files do not change it. If any of that changes, the id does too, so a decision kept for a later merge cannot land on a different conflict. A decision that meets no conflict is reported, and changes nothing.
  • Context size: the element around a node is its parent, or the node itself where the parent is over 64 KiB, or the start of the node with cut set where that is too.

The decisions file is plain lines rather than JSON, like the rule files and @FILE lists, so it needs no parser and can be read and edited by hand.

Without the new options, merge3 behaves as before.

Tests

v test . passes, as do scripts/merge3_cli_test.sh (new, run from scripts/check_reports.sh, so CI runs it with no change to a workflow), scripts/git_driver_test.sh and scripts/inputs_cli_test.sh. scripts/check_reports.sh now validates a merge3 report against its schema.

On a large real-world model:

  • The plain merge was byte-identical to the current main on every file.
  • The report gave the same conflicts as the text output, and the same ids on a second run.
  • Deciding every conflict for ours gave a result byte-identical to the plain merge, with exit 0.
  • Deciding every conflict for theirs gave a clean result, which a further merge with theirs had nothing to disagree with.

🤖 Generated with Claude Code

A tool putting conflicts to a person had to parse lines from standard error, and had no
way to say what was decided. `--format json` writes each conflict with an id and what the
three versions have there, the element around it as the file has it. `--resolve FILE`
takes the decisions back, `ours ID` or `theirs ID` a line, and when all are decided the
exit code is 0.

An id is a hash of the conflict's kind, its path and what each side has there. No file
name goes in, so a git driver's temporary files do not change it; a side changing gives a
new id, so a decision kept for a later merge cannot land on another conflict. One that
meets no conflict is reported.

Vendors flatxml fd6e96a, whose merge3 can take theirs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T13:23:39.631898Z 9d511f5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e7bb10474

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread arxmodel/compare.v Outdated
Comment on lines +430 to +433
for side in [c.ours, c.theirs] {
parts << '${side.kind}'
parts << side.after or { '' }
parts << if side.new.ok() { own_xml(side.new) } else { '' }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include move destinations in conflict IDs

When both sides move an unchanged element to different parents, the ID hashes the base path and each moved element's XML, but neither destination. If theirs subsequently moves that element to a different parent again, its XML and conflict ID remain identical. A saved theirs ID decision therefore silently accepts the new destination instead of being reported as stale, potentially placing model content somewhere the user never approved. Include each move's semantic destination (and relevant ordering information) in the fingerprint without incorporating temporary filenames.

Useful? React with 👍 / 👎.

@MartenH

MartenH commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

Review of 8e7bb10. Each case below was run through the CLI on a small synthetic model. The claim in docs/report.md that a decision kept "cannot land on another conflict" does not hold yet.

finding reaction result
Codex P2: a move's destination is not in the id 👍 Reproduced. Decided theirs for ours→Q / theirs→R, then theirs moved to S instead. Same id, exit 0, and the node landed in S with no warning.
A removed conflict hashes only the first change on the other side new Ours removes a node, theirs changes one child; decide ours. Theirs then also changes a second child. Same id, exit 0, and that change is dropped with no warning. The mirror case is the same: with theirs removing, theirs ID drops a later change of ours.
Two conflicts can share one id new Two unkeyed siblings with the same edits have the same path and the same sides, so both get one id. One decision settles both, they cannot be decided apart, and resolved says 1. The schema reads as if an id names one conflict.

Also, the base is not in the id, although a decision depends on it less than the sides do; worth settling along with the fix.

All three come from one cause: the id hashes one node's source per side, which is less than what the decision covers. Merge flatxml#46 only once the id is settled, in case the fix needs more from it.

A decision kept for a later merge could apply to a conflict that had
changed: the id hashed one node per side. A move's destination was not
in it, nor any change below a removed node but the first, and two items
of a list with the same edits shared one id. It now has the base, the
place among like items, where a move goes and, for a removal or a move,
all that each side changed in the node.

Vendors flatxml at its squash of #46.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MartenH

MartenH commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33bb302178

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread arxmodel/compare.v Outdated
Comment on lines +501 to +503
made := '${merged_path(anchors[0], base.ix)}\0${places_of(anchors[0], base.ix)}\0${c.name}\0${change_print(c,
v)}'
h := hash.sum64_string(made, 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include insertion order in subtree conflict fingerprints

When ours removes Head and theirs changes its WATTS and appends two ordered NOTE children, swapping those new children in a later version leaves the removal conflict's ID unchanged. The representative WATTS change remains identical, while each addition's scope fingerprint contains its base parent and XML but not its insertion index; summing those fingerprints also discards their order. Consequently, a saved theirs ID decision silently accepts a different ordered list instead of becoming stale. Include the semantic insertion position of ordered additions in the scope fingerprint.

Useful? React with 👍 / 👎.

Comment thread arxmodel/compare.v
Comment on lines +445 to +447
base: conflict_side(c.node, c.ours.before)
ours: conflict_side(c.ours.new, c.ours.after)
theirs: conflict_side(c.theirs.new, c.theirs.after)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report the surviving subtree for removal conflicts

When one side removes an ancestor and the other changes multiple descendants, flatxml.combine reports one removal conflict whose surviving-side change is only the first descendant change. Using that change's new node here therefore reports the wrong subtree: for example, removing Body while theirs edits WATTS in both Head and Tail reports only Head's context, omitting Tail's changes even though the decision accepts or discards both. Resolve the surviving counterpart of c.node for structural conflicts and generate its bounded context, rather than using the first changed descendant.

Useful? React with 👍 / 👎.

Comment thread docs/merge3.schema.json Outdated
"properties": {
"conflicts": {"type": "integer", "minimum": 0},
"resolved": {"type": "integer", "minimum": 0},
"unused": {"type": "array", "items": {"$ref": "#/definitions/id"}},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align unused-ID validation with accepted decisions

When a decisions file contains ours aa, parse_decisions accepts it (the new parser test explicitly covers such IDs), and a merge with no matching conflict emits "unused":["aa"]. This schema rejects that output because definitions/id requires exactly 16 hexadecimal digits. Thus a successfully completed merge can produce a report that schema-validating consumers cannot read, precisely when they need to display an unused-decision warning. Either allow arbitrary strings in summary.unused or reject nonconforming IDs before producing the merge result.

Useful? React with 👍 / 👎.

A removal or a move conflict names one change, but a decision takes or
drops all that a side changed in the node. Each side now lists them in
`changes`. The id counts where an addition goes, since a list in another
order is another decision, and the schema takes an unused decision as
the file spells it, which need not be an id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MartenH

MartenH commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

Fixed in the commit after 33bb302; codex round on that head:

finding reaction what happened
Insertion order missing from the scope fingerprint 👍 Fixed: a change's index is in the hash, and a test covers two added items swapped.
A removal conflict reports only the first descendant change 👍 Fixed differently: each side has changes, every change the decision covers, a line each. xml still shows one place, since flatxml gives no counterpart of a removed node.
summary.unused schema rejects an id that is not 16 hex digits 👍 Fixed: unused takes any string, as the file spells it.

@MartenH

MartenH commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98a12352ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread arxmodel/compare.v Outdated
Comment on lines +520 to +522
for cur.ok() && !(int(cur.i) < ix.at.len && ix.at[cur.i] != 0) {
out << place_of(cur).str()
cur = cur.parent()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include ancestor variant identities in conflict IDs

With the built-in identity rules, two LAMP elements can share SHORT-NAME Head but have different VARIATION-POINT/SHORT-LABEL values. If both variants have the same WATTS conflict (for example, 55 → 60 versus 65), they receive identical IDs: merged_path excludes variation points, this loop stops before including the referrable ancestor's identity, and the XML fingerprints contain only WATTS. Consequently, a decision intended for one variant silently resolves both, and opposite decisions cannot be expressed. Include the distinguishing merge keys of referrable ancestors in the fingerprint.

Useful? React with 👍 / 👎.

Comment thread arxmodel/compare.v
// change_print is what a change does: to what, and for a move, where to.
fn change_print(c flatxml.Change, v &Version) string {
mut parts := ['${c.kind}', c.after or { '' }]
parts << if c.new.ok() { own_xml(c.new) } else { '' }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fingerprint every contribution to an added subtree

When both sides add a conflicting element whose merged subtree spans multiple files, own_xml(c.new) fingerprints only fragment(0). Changing a descendant contributed solely by another fragment therefore leaves the addition conflict's ID unchanged: added subtrees produce one addition change, and .added conflicts receive no supplementary scope hash. A saved theirs ID decision then silently accepts the modified content, since Applier.add copies every fragment, not just the fingerprinted one. Hash the complete merged addition, or all its contributions, rather than only its first source fragment.

Useful? React with 👍 / 👎.

Two variants of one element share a path, so they shared an id too: the
merge keys of the node and all above it are in it now. A node spread
over several files was hashed from the first alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MartenH

MartenH commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

Fixed in 9d511f5; codex round on 98a1235:

finding reaction what happened
Variants of one path share an id 👍 Fixed: the merge keys of the node and everything above it are hashed. Test added; it fails with the fix taken out.
A multi-file addition is hashed from its first file 👍 Fixed: own_xml reads every fragment. Test added.

@MartenH

MartenH commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 9d511f5abd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@MartenH
MartenH merged commit 86cf733 into main Oct 31, 2026
2 checks passed
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.

1 participant