Skip to content

fix(gate): read a merge of unrelated histories as a first-parent diff - #137

Merged
systemfsoftware-bot merged 2 commits into
mainfrom
docs/plan-ci-tooling-fixes
Nov 27, 2026
Merged

systemfsoftware-bot merged 2 commits into
mainfrom
docs/plan-ci-tooling-fixes

Conversation

@systemfsoftware-bot

@systemfsoftware-bot systemfsoftware-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Written adversarial review (before the diff)

Is the approach right?

The change asks git merge-base <first> <second> before a two-parent merge reaches git merge-tree. Exit 0 keeps today's mergeResidue (the merge-tree call) byte for byte; exit 1 takes the residue from git diff-tree between the first parent and the merge commit. Any other exit is a failure that names the command, its exit status and its stderr.

Alternatives weighed:

  1. git merge-tree --allow-unrelated-histories — rejected: a squashed subtree add's second parent holds the vendored repository's files at its own root, not under the prefix the subtree merge placed them. Merging it against an unrelated base relocates those files to the workspace root, so the residue would name root paths instead of the import — a wrong set of paths rather than a wider or narrower one.
  2. Treating merge-tree's exit 128 as the trigger and matching its stderr — rejected: it recovers from that one message only, leaves every other 128 on the same crash path, and makes the check depend on git's English text.
  3. Diffing every two-parent merge against its first parent — rejected: on a related merge that diff counts the target branch's own commits and hides an evil-merge resolution, which is what merge-tree exists to isolate.
  4. Testing separately that the second parent is a root commit — redundant: merge-base exit 1 already means the two parents share no commit, so a second test can only disagree with it by being wrong.

Cost: one git merge-base process per two-parent merge. The probe returns before any merge-tree work, and only two-parent merges pay it.

P0/P1

None found. Checked how the change could weaken what the check guards:

  • Could a publishable package's change now pass without an intent? No. The residue is only ever added to the feature-touched set (changedPathsOf), and a feature-touched path is never released, so residue can only move a path from release-owned to feature-owned — never the reverse. The required-intent set is monotone in the residue, so a wider residue can only make the check stricter. The end-to-end proof below shows the intent requirement still firing for a first squashed subtree add inside a published package.
  • Could the new probe hide a real failure? No. Only exit 0 and exit 1 are answers; every other status fails through EvidenceCommandFailed naming the command, its exit status and its stderr, the shape every other git call in this adapter uses.
  • Could a related merge change? No. Exit 0 selects the unchanged mergeResidue call, and no other line of the adapter changed. A related merge with an evil edit was re-run end to end and still reports both the merged feature change and the evil edit.
  • Could it pass a change it should refuse? The only way to weaken the guard would be a residue that omits a path the merge introduced. A diff against the first parent cannot omit one: it lists every path whose tree entry differs. For a vendored prefix outside every member, that path set is unowned, so the verdict is the pass the check exists to give.

Residual risk, stated plainly: a two-parent merge of unrelated histories now demands an intent for every path it introduces that a publishable member owns. That strictness is intended; it is what the check does for any other feature change.

What changed

  • packages/process-adapter/src/history-io.ts — the two-parent branch of commitOf asks git merge-base first: related → the merge-tree residue as before; unrelated → the first-parent diff; any other exit fails naming the command.
  • docs/change-intents.md — how the check reads a merge of unrelated histories.
  • docs/solutions/runtime-errors/merge-tree-refused-a-first-squashed-subtree-add.md — the learning record.
  • .changeset/merge-tree-reads-unrelated-histories.md — a patch intent for @systemfsoftware/process-adapter.

The plan this implements is in the branch: docs/plans/2026-11-27-1501-fix-change-intent-unrelated-history-merge-plan.md.

Verification

Run at low priority (nice -n 19 ionice -c3):

Command Exit
pnpm typecheck --filter @systemfsoftware/process-adapter 0
pnpm lint --filter @systemfsoftware/process-adapter 0
pnpm test --filter @systemfsoftware/process-adapter 0
./bin/dprint check on the four changed files 0

End to end, against the built changeset-management app and three synthetic consumer repositories (each a pnpm workspace with two publishable members):

Case git merge-base parents check verdict
First squashed subtree add under an unowned prefix exit 1 pass — no publishable package changed (2 member(s))
First squashed subtree add inside packages/a exit 1 fail — names @x/a
Related merge with an evil edit to packages/b exit 0 fail — names @x/a and @x/b

Before the change, the first two cases reached git merge-tree and exited 128 with fatal: refusing to merge unrelated histories, reproduced directly against git 2.55.0. The change intent job of the failing public consumer pull request has not been re-run against this branch yet; that run is the remaining proof.

Tests

No test was added. The adapter's real-git suites spawn git on the host, and this repository admits a new test only when that is asked for. The end-to-end proof above is the replacement evidence.

Plan note

One assumption in the plan does not hold. docs/plans/2026-11-27-1501-fix-change-intent-unrelated-history-merge-plan.md:78 says the squashed root commit's paths are read and can make a colliding root path feature-owned. In fact git diff-tree -r -z --root --no-renames --name-status <commit> prints the commit id as its first NUL field (git 2.55.0), so the adapter's pair walk misaligns and records no changes for a root commit. Nothing in this fix depends on it: the net diff from the merge base to HEAD carries every imported path. Recorded so the plan's reasoning is not read as fact.

A two-parent merge whose parents share no ancestor, as a first squashed
subtree add produces, made git merge-tree refuse the merge with exit 128 and
failed the whole changeset check. The two-parent branch now asks git
merge-base whether the parents are related: exit 1 takes the residue from the
diff between the first parent and the merge commit, the rule octopus merges
already use, and any other exit fails naming the command, its status and its
stderr. A merge whose parents are related keeps its merge-tree residue.
@systemfsoftware-bot

Copy link
Copy Markdown
Contributor Author

Tests at head 426e975. CI's checks job ran build and lint for the changed package but no test task, so I ran the tests locally:

  • pnpm test --filter @systemfsoftware/process-adapter...: exit 0, 4 of 4 tasks.
  • pnpm test --filter ...@systemfsoftware/process-adapter (the package and its workspace dependents changeset-management, git-hooks and github-release-management): exit 0, 18 of 18 tasks.

Independent adversarial review: approach kept, no P0/P1.

@systemfsoftware-bot
systemfsoftware-bot merged commit 2922882 into main Nov 27, 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