Skip to content

fix(diff): pair colliding facts positionally instead of last-write-wins - #81

Merged
dejo1307 merged 1 commit into
mainfrom
fix/diff-collision-safe-fact-keys
Jul 9, 2026
Merged

fix(diff): pair colliding facts positionally instead of last-write-wins#81
dejo1307 merged 1 commit into
mainfrom
fix/diff-collision-safe-fact-keys

Conversation

@dejo1307

@dejo1307 dejo1307 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

factKey is not unique and no prop can make it so: Swift declares the same class twice under mutually exclusive #if/#else branches, overloaded methods share a name and symbol_kind, and a dependency fact's name already embeds its import target, so two imports of one target in one file are identical in name, props and relations. Such facts differ only by line, and line may not enter identity (diff.go:388, TestCompute_LineShiftIsNotAChange).

Keying them into a map[string]Fact silently dropped all but one. Two symptoms:

  • Deleting a dropped fact produced no diff entry at all. 172 facts across three corpus repos were absent from the diff's map entirely.
  • The on-disk baseline and the in-memory current iterate facts in different orders, so the surviving representative differed between the two sides and diff_snapshot reported a changed fact between byte-identical fact sets.

groupByKey now buckets facts into map[string][]Fact, sorts each bucket by intraGroupOrder (line, propsJSON, relationsJSON), and pairs the two sides positionally. Line is used only as an ordinal within a group that already shares an identity; it never enters factKey, so a lone fact that merely moves is still unchanged.

sortAll orders by factSortKey rather than factKey. Once colliding facts both survive, factKey no longer totally orders them, and the collections are built by ranging over a map -- sort.Slice would have left their order to Go's randomized map iteration, breaking the package's byte-identical-output promise.

The KindRoute/KindStorage discriminators are kept. They are no longer load-bearing for correctness but still pair a route's GET and DELETE facts by method rather than by position.

No cacheVersion bump: internal/diff emits no facts. Verified -- facts.jsonl hashed identically before and after.

factKey is not unique and no prop can make it so: Swift declares the same
class twice under mutually exclusive #if/#else branches, overloaded methods
share a name and symbol_kind, and a dependency fact's name already embeds
its import target, so two imports of one target in one file are identical in
name, props and relations. Such facts differ only by line, and line may not
enter identity (diff.go:388, TestCompute_LineShiftIsNotAChange).

Keying them into a map[string]Fact silently dropped all but one. Two symptoms:

  - Deleting a dropped fact produced no diff entry at all. 172 facts across
    three corpus repos were absent from the diff's map entirely.
  - The on-disk baseline and the in-memory current iterate facts in different
    orders, so the surviving representative differed between the two sides and
    diff_snapshot reported a changed fact between byte-identical fact sets.

groupByKey now buckets facts into map[string][]Fact, sorts each bucket by
intraGroupOrder (line, propsJSON, relationsJSON), and pairs the two sides
positionally. Line is used only as an ordinal within a group that already
shares an identity; it never enters factKey, so a lone fact that merely moves
is still unchanged.

sortAll orders by factSortKey rather than factKey. Once colliding facts both
survive, factKey no longer totally orders them, and the collections are built
by ranging over a map -- sort.Slice would have left their order to Go's
randomized map iteration, breaking the package's byte-identical-output promise.

The KindRoute/KindStorage discriminators are kept. They are no longer
load-bearing for correctness but still pair a route's GET and DELETE facts by
method rather than by position.

No cacheVersion bump: internal/diff emits no facts. Verified -- facts.jsonl
hashed identically before and after.
@dejo1307
dejo1307 merged commit f0381aa into main Jul 9, 2026
4 checks passed
@dejo1307
dejo1307 deleted the fix/diff-collision-safe-fact-keys branch July 18, 2026 06:54
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