Skip to content

fix(scripts): repair rows whose cited paths moved - #445

Merged
abogartz merged 6 commits into
mainfrom
fix/ref-fixer
Nov 19, 2026
Merged

abogartz merged 6 commits into
mainfrom
fix/ref-fixer

Conversation

@abogartz

@abogartz abogartz commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Problem

The write gate refuses a new settled claim that cites a path the repository does not have (ref_path_missing). That check runs on writes only, so a row that was correct when it was saved goes stale silently the moment a later refactor moves the file. Nothing notices, and recall keeps quoting a path the reader cannot open.

This is self-inflicted and measurable. The src/ moves — domain structure, the telemetry merge, command/ensure.ts → init/ — invalidated refs in rows already on disk.

Measured on the maintainer's store

bun scripts/ref-fixer.ts against this repository, 2026-11-19:

count
active rows for this repo 1253
active rows citing at least one dead path 33
repaired by --apply 9
refused by the gate, with reasons 5
dead paths left for a human 18

The refusals are the interesting output and the script does not paper over them: 4 rows cite a second dead path the rules will not touch, and 1 is a learning row where a content change brings the symptom-first rule into play.

Two rules, each narrow for a stated reason

  1. A scored rename. Git records a rename scored at least R90 whose chain ends at a file that exists today and whose basename is unchanged. The floor is measured, not guessed: this repository's renames cluster at R090–R100 (the domain restructure, where the only content change is the import lines inside the moved file) with outliers at R058, R072, R080, R086, R088 — files git scored as renames after much of their content was rewritten. Same basename is the safety property: src/lock.ts → src/store/lock.ts still says "lock", so the tokens a query matches on survive.
  2. A loose citation. The path never existed anywhere in git history and exactly one tracked file ends with it (gate/gate.ts → src/gate/gate.ts). Both halves are load-bearing: without the history check a path the gate once refused as hallucinated gets handed a verified ref, and without the single-candidate check the script picks a directory on the row's behalf.

Everything else is reported only. A row about a deliberately retired artifact — poc-409/, a retired bench runner — is accurate history: the file is gone on purpose and the row is the record that it existed.

One consequence worth knowing: the retirement convention used in docs/pre-release-ritual.md (recover it with git log -- bench/runners/<name>.ts) cannot be written into a memory row, because the gate reads the path inside it as a live reference. Filed as #447.

Review findings that changed this PR

An adversarial review found two blocking defects in the first version. Both are fixed and both are now pinned by test/ref-fixer.test.ts (11 tests).

The rewrite was a blind substring replace. content.split(from).join(to) also hit a ref nested inside a longer one: a row citing both gate/gate.ts and src/gate/gate.ts came out as src/src/gate/gate.ts. Worse, it rewrote absolute paths that checkablePathRefs deliberately skips — so the gate could never refuse the damage, because it never sees those. The fix is span-based: checkablePathRefSpans in src/gate/resolver.ts returns each checked ref with the offsets it occupies, checkablePathRefs now delegates to it, and the fixer edits only those spans. One source of truth, so the script cannot drift from what the gate validates.

The docs described a stricter rule than the code had. Rule 2 repointed paths with no rename in history, which the text claimed never happened. The docs now state both rules and why each is narrow.

Also from the review, all fixed: the rename map ignored git's similarity score (now R90+, printed per row); the chain resolver returned a wrong path on a cycle or an unresolved intermediate (now null); git exit codes were ignored, so a run outside a repository reported a clean scan (now exits 2); a zero-row scan looked like success (now says NOTHING SCANNED and names --repo); the "exactly one candidate" the header promised was unimplemented (now a tracked-surface suffix match); rule 2 could bless a retired path (now requires the path never existed in history); the dry run never showed the rewritten text, so a bad rewrite was invisible until --apply (it now prints will be REFUSED: still cites … for every row the gate will stop); a run with refusals exited 0 (now 1); --limit abc silently printed nothing (now rejected); and the PARTIAL message dropped symptom-fixer's warning that a re-run reports the duplicate (restored).

The PR body's earlier claim that comment-lint does not cover scripts/ was wrong — it diffs *.ts with no path filter. The 0 added comment line(s) I reported came from running with a base equal to HEAD. With COMMENT_LINT_BASE=origin/main it checks this script's comments.

A reused path produced a confident wrong write. Two review rounds, one shape each. A path renamed away, recreated with different content, then deleted leaves no second rename record, so counting renames reads it as a clean single move and a row about the second occupant was rewritten onto the first occupant's new path. Its mirror — delete the first occupant, add a different component at the same path, then move only that second file — has the rename as the path's newest touch, so a "was it touched after its rename" check passes and the row about the retired occupant was rewritten onto the second one's path.

Both are one path with two creations, so the rule is a creation count: an A, or a rename or copy landing on the path, more than once. That subsumes both rules it replaces — a path cannot be renamed, deleted or written again without being created again first — so they were deleted rather than stacked into a third check. indexRenames(renameLog, fullLog) is now a pure function over the two log texts: the check had lived inside main() behind two git calls, unreachable from a test, which is how the first version of the rule survived review at all. Tests pair the two shapes and add a path that arrived by rename and was later recreated at it, where no A exists for the first lifetime. The full-history log is now a checked call: an empty log reads as "no path was ever created twice" and would disable the rule silently.

A reused destination is not a safe target either. A third round found that the creation count was scoped to rename sources — reused was built from the keys of hopScore, and a destination is never one of those. Move src/lock.ts to legacy/lock.ts, delete the moved file, commit something unrelated at legacy/lock.ts: the chain ends on a path the original component never occupied, and a row about the original component was superseded onto it. The set is now every path with more than one creation, and the check applies to whatever the chain walks. ambiguousHop reports WHICH path in the chain has two lifetimes, because telling a human that src/lock.ts was reused when legacy/lock.ts is the ambiguous one sends them to the wrong file. chainEnd shares one hop walk with it rather than keeping its own copy — a duplicated walk is how the destination got omitted.

Across the three rounds the same mistake recurs: a rule scoped to the thing being looked at (the rename count, then the newest touch, then rename sources) instead of the property the row needs ("can this path be cited by rows written against two different files", which belongs to every path in the chain).

This history has 39 rename sources, 34 followed at R90+, and 0 created more than once, so the stricter rule changes nothing on the maintainer's store — both fixes came from the reviewer's fixtures.

Apply path

Identical to scripts/symptom-fixer.ts, deliberately: one row at a time under the store's batch lock, through the real write pipeline with supersedesTs set — the memory_update contract. The successor inherits the target's repository stamp, so the script forges no identity. The old row is superseded and never edited, markSuperseded snapshots the day file first, and memory_undo stays the recovery path. A row whose content changed between scan and apply is skipped rather than clobbered.

Refs resolve against the repository the row describes (repoPath), not the store: that is the only tree where the new path exists.

Scope, stated because silence reads as a clean report: rows are selected by repository key, defaulting to the current directory. Rows stamped for another repository, and rows with no stamp at all, are never scanned — the dry run prints how many it skipped.

Verification

  • bun run typecheck clean. bun x biome format clean. COMMENT_LINT_BASE=origin/main bun run lint:comments clean, 48 added comment lines checked.
  • bun test ./test/ — 1537 pass / 21 skip / 0 fail, including 11 new tests for the rewrite and the chain resolver.
  • bun run test:e2e — 35 pass / 0 fail. Run this time because src/gate/resolver.ts changed.
  • Dry run re-executed after the rework: 5 rows still repointable (the 5 refusals), and the dry run now predicts 4 of the 5 gate refusals before writing.
  • The 9 rows already written were audited: every diff is exactly one path swap, no doubled segments, and all three rule-2 repairs satisfy the new rule (never existed in history, one tracked match).

Not included

The 18 dead paths that need judgement are listed by the script and left alone. The 5 rows the gate refuses stay stale until a human rewords them; --apply is a no-op for each.

The gate checks path references on writes only, so a row that was correct when
it was saved goes stale when a later refactor moves the file. The src/ moves
invalidated refs in 33 active rows on the maintainer's store.

ref-fixer repoints a path only when git records a rename whose chain ends at a
file that exists today and whose basename is unchanged, so the tokens a query
matches on survive. Renames that also renamed the file, and paths with no rename
in history, are reported rather than rewritten: a row about a deliberately
retired artifact is accurate history.

Apply goes through the same gated update path as symptom-fixer: batch lock,
supersedesTs, snapshot first, memory_undo stays the recovery path.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran the fixer at da8c43a with two disposable Git/store fixtures. In both cases --apply reported one repair and superseded the original row, but the successor cited the wrong file.

  1. An edit also rewrites an already-valid citation. A row cited both capture/runtime.ts and docs/capture/runtime.ts. The plan listed only the first citation. The saved successor changed the second to docs/src/capture/runtime.ts as well. That file existed in the fixture, so the gate accepted it. Applying edits to the matched path spans in the original text would keep the plan and the write in sync. This fixture also had multiple prefix matches for capture/runtime.ts, yet the planner picked src/ without checking uniqueness.
  2. A reused source path picks the oldest rename. I moved src/lock.ts to legacy/lock.ts, added a different file at src/lock.ts, then moved that one to current/lock.ts. Both destinations still existed. A row describing the second file was rewritten to legacy/lock.ts. Git emits the newer rename first and the map overwrites it with the older one. Reporting reused paths as ambiguous would protect rows from either generation.

I’d address these before applying the fixer to more stored rows. Both fixtures would make useful regression tests against the persisted successor.

An adversarial review found two blocking defects in the first version.

The rewrite was content.split(from).join(to). It hit a ref nested inside a
longer one, so a row citing both gate/gate.ts and src/gate/gate.ts came out as
src/src/gate/gate.ts, and it rewrote absolute paths that checkablePathRefs
deliberately skips - damage the gate can never refuse, because it never sees
those. checkablePathRefSpans now returns each checked ref with the offsets it
occupies, checkablePathRefs delegates to it, and the fixer edits only those
spans: one source of truth, so the script cannot drift from what the gate
validates.

The docs also claimed a stricter rule than the code had. Rule 2 repoints paths
with no rename in history, so the text now states both rules and why each is
narrow: R90+ renames only (this repo's moves are R090-R100; the R058/R072
outliers are rewrites), and a loose citation requires that the path never
existed in history and has exactly one tracked match, or the gate's
hallucination refusal becomes a verified ref.

Also: git exit codes checked, a zero-row scan says so instead of reading clean,
cycles and unresolved chains return null, the dry run predicts every gate
refusal before writing, refusals exit 1, --limit is validated, and the PARTIAL
message keeps the duplicate warning. 11 new tests pin the rewrite and the
resolver.
A path renamed away, recreated at the same path and renamed away again has two
generations of rows citing one string, describing two different files. Picking
the newest rename is a guess with the confidence of a repair, so the chain walk
now stops on any hop whose source was renamed more than once and the path is
reported instead.

Two regression tests from the review fixtures: a row citing both a loose
capture/runtime.ts and a valid docs/capture/runtime.ts must have only the loose
one rewritten, and a reused source path must resolve to nothing.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked 72dea23. All 11 ref-fixer tests passed, and the CLI now leaves my ambiguous suffix fixture untouched. The span-based rewrite resolves the nested-citation finding.

One case still writes the wrong successor. In the same disposable Git history, the first src/lock.ts moved to legacy/lock.ts. A different file later occupied src/lock.ts and moved to current/lock.ts. Both moves are R100 and both destinations still exist. This time I applied the fixer to a row describing the first component. It reported one repair, persisted current/lock.ts and superseded the original row. Choosing the newest rename fixes the second component's citation but misattributes the first one's.

Could the planner retain both destinations and leave a reused source path for human review when the row's file generation cannot be established? A CLI regression with one row for each generation would cover both sides.

@abogartz

Copy link
Copy Markdown
Owner Author

Both reproduced, both fixed. Your review ran against da8c43a; the fixes are in 72dea23 and 8c63a26.

1. An edit also rewrote an already-valid citation. Fixed in 72dea23, and your fixture is now a named test. The rewrite was content.split(from).join(to); it is now span-based. src/gate/resolver.ts gained checkablePathRefSpans, which returns each checked ref with the half-open span it occupies, checkablePathRefs delegates to it, and the fixer edits only those spans. Your capture/runtime.ts / docs/capture/runtime.ts pair is the second test in test/ref-fixer.test.ts: only the loose citation is rewritten. The same change also stops gate/gate.ts becoming src/src/gate/gate.ts inside a longer ref, and stops absolute paths being rewritten at all — which was the worse half, because checkablePathRefs skips those, so the gate could never refuse the damage it was doing to them.

Uniqueness is checked now too. Rule 2 requires exactly one tracked file whose path ends with the citation (git ls-tree -r --name-only HEAD, not a filesystem walk, so build output cannot invent a second candidate), and additionally that the path never existed anywhere in history — otherwise a path the gate once refused as hallucinated gets handed a verified reference.

2. A reused source path picked the oldest rename. The oldest-wins part was real: git emits newest-first and the map overwrote the good entry with the old one. 72dea23 keeps the first record per path. Your deeper point is the right one, though, and newest-wins is still a guess — a path renamed away, recreated, and renamed away again has two generations of rows citing one string, and nothing in a row's text says which file it describes. So 8c63a26 drops the guess: the chain walk returns null on any hop whose source was renamed more than once, the path is reported, and the dry run prints a separate section naming it. Tests cover reuse at the head of the chain and mid-chain.

Also changed from a separate adversarial pass, since you asked for the plan and the write to stay in sync: the dry run now prints will be REFUSED: still cites … for every row whose rewrite leaves another dead ref, so the gate's answer is visible before --apply rather than after it. It predicts 4 of the 5 refusals on the live store; the fifth is the symptom rule, which is not a path question.

Status: bun test ./test/ 1541 pass / 0 fail, bun run test:e2e 35 pass, comment-lint clean over 105 added comment lines. The 9 rows already applied were audited row by row against their superseded originals — each diff is exactly one path swap, and all three loose-citation repairs satisfy the tightened rule (never existed in history, one tracked match).

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The two-rename fixture now passes at 8c63a26. I ran --apply with a row for each generation of src/lock.ts. It reported both and wrote zero successors. All 15 ref-fixer tests passed.

There is a related retirement case that still writes a wrong successor. In a disposable Git repo I moved the first component from src/lock.ts to legacy/lock.ts (R100), added a different component at src/lock.ts, then deleted that second component. For a row describing the second component, --apply reported one repair, superseded the original, and persisted “The second component uses legacy/lock.ts for its locking behavior.” That file belongs to the first component.

The history query filters to renames, so it sees the R100 and misses the later creation and deletion. Could the planner leave this path for human review when a later generation occupied it? The persisted row above would make a regression test for the documented retirement rule.

A rename source that history touches again after its newest rename held a
second generation: moved away, recreated, then deleted. No second rename
record appears, so counting rename records reports a clean single move and a
row describing the second occupant is repointed onto the first occupant's new
path. Reproduced in a disposable repo: src/lock.ts moved to legacy/lock.ts, a
different component added at src/lock.ts, then deleted. --apply rewrote the row
to "the second component uses legacy/lock.ts", which is the first component's
file.

Detection is one pass over the unfiltered name-status log: for every rename
source, is the newest commit touching it later than its newest rename? If so
the path is reported for a human, alongside the shapes already refused.

The check lived in main() and no test reached it, which is how the first
version of this rule survived review. indexRenames now takes the two log texts
and returns the index, so the rename floor, the multi-rename count and the
reuse pass are all unit-testable without a git binary.

Verified against the maintainer's store: 5 repointable rows and 18 dead paths,
byte-identical before and after, and no path in this history is reused.

bun test ./test/ 1525 pass / 21 skip / 0 fail, test:e2e 35 pass.
@abogartz

Copy link
Copy Markdown
Owner Author

Reproduced, fixed at c76a431. Your fixture is a real wrong write, and the reason it survived my first version is worse than the bug.

Reproduction. Disposable repo, four commits: src/lock.ts added, moved to legacy/lock.ts (R100), a different component added at src/lock.ts, that one deleted. Row citing src/lock.ts for the second component. Dry run before the fix:

repointable rows: 1   dead paths left for a human: 0
2026-01-01T00:00:00.000Z [settled] learning/gate  src/lock.ts -> legacy/lock.ts (R100)

So yes — it claimed a clean repair and would have persisted a row attributing the second component to the first component's file.

The rule. Your suggestion is the right one and it is what shipped: refuse and report when a later generation occupied the path. Detection is not a rename count — the recreate-then-delete shape leaves no second rename record, which is exactly why --diff-filter=R missed it. It is one pass over the unfiltered name-status log asking, for each rename source, whether the newest commit touching that path is later than its newest rename. If it is, the path goes to the human list:

Occupied by more than one generation — moved away and recreated at the same
path, whether it moved again or was later deleted. Rows written against each
generation cite the same string and describe different files, so this script
will not pick:
  src/lock.ts

Why the first version survived you. The reuse check lived inside main(), behind two git calls, and no test reached it — the 15 tests covered chainEnd and applyRefFixes, both pure. A rule that cannot be tested without a git binary is a rule that only works on the history its author happened to try. So the extraction is part of the fix: indexRenames(renameLog, fullLog) now takes the two log texts and returns { renamed, hopScore, reused }, and five tests feed it hand-written logs in git's format. They pin a clean single rename as not reused, renamed-twice as reused, your recreate-then-delete as reused, the sub-R90 floor, and newest-rename-wins. chainEnd keeps its existing tests unchanged.

Your point about the persisted row becoming the regression test — taken, though as a unit fixture rather than a live row: the store is yours and --apply is not something I run from a review. The log text from your scenario is in the test verbatim.

Not a behavior change on your store. Same script, before and after, against the real history: repointable rows: 5, dead paths left for a human: 18, identical, and no path in this repository's history is reused — which is worth saying plainly, since it means this fix was bought entirely from your fixture and not from anything my own data could have surfaced.

bun test ./test/ 1525 pass / 21 skip / 0 fail, test:e2e 35 pass, comment-lint clean over 140 added lines, merge gate green on push. docs/write-gates.md now describes both reuse shapes, including that the second one is invisible to a rename count.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reran the original rename → recreate → delete fixture at c76a431. With --apply the row stayed byte-identical and there was no successor. All 20 focused tests passed.

Reversing which generation was deleted exposes a remaining wrong write. In a disposable repo I deleted the first src/lock.ts, committed a different component at the same path, then moved only that second file to current/lock.ts (R100). I applied the fixer to a row about the retired first component. It reported one repair, superseded that row, and persisted “The retired first component uses current/lock.ts for its locking behavior.”

Here the rename really is the newest touch, so the new check passes even though the row could describe either generation. Could the reuse check also consider whether the source path had multiple lifetimes before its final rename? A paired regression with the deletion on either side of the rename would exercise this without a live store.

The mirror of the previous fixture still wrote a wrong row. Delete the first
src/lock.ts, commit a different component at the same path, move only that
second file: the rename is now the newest touch of the path, so "was it touched
after its rename" answers no, and a row about the retired first occupant was
superseded and rewritten onto the second occupant's path.

Both shapes are one path with two creations, so the rule is now a creation
count: an add, or a rename or copy landing on the path, more than once. That
subsumes both rules it replaces -- a path cannot be renamed, deleted or written
again without being created again first -- so the rename count and the
newest-touch pass are gone rather than stacked into a third check.

The full-history log is now a checked call. An empty log reads as "no path was
ever created twice", which would disable the rule silently and repoint anyway.

Tests pair the two shapes, deletion on either side of the rename, plus a path
that arrived by rename and was recreated at it -- no `A` for its first
lifetime, so a rule counting adds alone would read one creation. Fixtures are
written the way git prints the unfiltered log, a move as a delete plus an add.

Verified: both disposable repos now refuse and leave the row byte-identical
under --apply, and the maintainer's store is unchanged at 5 repointable rows
and 18 dead paths, with no path in this history created twice.

bun test ./test/ 1527 pass / 21 skip / 0 fail, test:e2e 35 pass.
@abogartz

Copy link
Copy Markdown
Owner Author

Reproduced at c76a431, fixed at 4d95fc8. Your reversed fixture writes the wrong row, and it exposed that my fix was the wrong shape of fix, not just an incomplete one.

Reproduction. Disposable repo, four commits: src/lock.ts added, deleted, a different component added at the same path, that one moved to current/lock.ts (R100). Row about the retired first component. At c76a431:

repointable rows: 1   dead paths left for a human: 0
2026-01-01T00:00:00.000Z [settled] learning/gate  src/lock.ts -> current/lock.ts (R100)

Why your suggestion was not enough on its own. "Also consider whether the source path had multiple lifetimes before its final rename" is correct, and it is the case I missed — but implementing it as a second question next to the first gives two rules that each cover half the shapes. Laid out, the shapes are one property:

A ......... R away     one creation: a clean move, safe to follow
A ......... R away, A  moved away, occupied again, later deleted   <- your first fixture
A, D, A ... R away     first occupant retired, second one moved    <- your second fixture

So the rule is now a single creation count: an A, or a rename or copy landing on the path, more than once. It subsumes both rules it replaces, and the argument for that is mechanical — a path cannot be renamed, deleted or written again without being created again first. The rename count and the newest-touch pass are deleted rather than stacked into a third check.

Your fixture as a paired regression. Both shapes are in test/ref-fixer.test.ts, deletion on either side of the rename, plus a third you did not ask for but the same count has to answer: a path that arrived by rename and was later recreated at it, where no A exists for the first lifetime — a rule counting adds alone would read one creation there. The fixtures are written the way git prints the unfiltered log, a move as a delete plus an add, because the rule is a count over exactly that text.

One more hole, found while rewriting. The full-history log was an unchecked git(...) call. If it fails, the text is empty, empty reads as "no path was ever created twice", and the reuse rule is disabled silently while the script repoints anyway — the same failure mode as the bug, reached through a missing exit code. It is now a checked call that returns 2.

Verified on both fixtures. Each now refuses, and under --apply the row is byte-identical, with no successor written:

applied (gated update, snapshot-backed, old row superseded): 0

Not a behavior change on your store. repointable rows: 5, dead paths left for a human: 18, unchanged. This history has 39 rename sources, 34 followed at R90 or above, and 0 created more than once — so the stricter rule costs nothing here. Worth stating plainly: two findings in a row now came from your fixtures and nothing my own history could surface, which is the argument for a second repository's data being the real prerequisite on this whole thread, not more analysis of mine.

bun test ./test/ 1527 pass / 21 skip / 0 fail, test:e2e 35 pass, comment-lint clean over 161 added lines, merge gate green on push. docs/write-gates.md now states the creation count and says which question gets each shape wrong.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both source-reuse fixtures now leave the stored row byte-identical under --apply, including the delete-before-rename case. All 22 focused tests passed at 4d95fc8.

The terminal destination can also have multiple lifetimes. I moved src/lock.ts to legacy/lock.ts (R100), deleted the moved file, then committed an unrelated component at legacy/lock.ts. A row describing the original component still cited src/lock.ts. The fixer reported one repair, superseded the row, and persisted “The original component uses legacy/lock.ts for its locking behavior.” The current file at that path has never contained the original component.

The full history already records both creations of the destination. The reuse set only considers keys from hopScore, so a terminal path that was never itself renamed cannot enter it. Could the ambiguity check cover the destination as well? The existing chain walk visits that path before accepting it.

The creation count only covered rename SOURCES, because `reused` was built from
the keys of `hopScore`. A destination is never one of those, so the third shape
review found wrote a wrong row: move src/lock.ts to legacy/lock.ts (R100),
delete the moved file, commit an unrelated component at legacy/lock.ts. The
chain ends on a path the original component never occupied, and the row was
superseded onto it.

The set is now every path with more than one creation, and the check applies to
whatever the chain walks -- source, intermediate, or destination -- which the
walk already visited before accepting. `ambiguousHop` reports WHICH path in the
chain has two lifetimes: telling a human that src/lock.ts was reused, when
legacy/lock.ts is the path with two creations, sends them to the wrong file.
chainEnd now shares one hop walk with it rather than keeping its own copy, so
the two cannot disagree about what the chain contains.

Verified on a third disposable repo: refuses, names legacy/lock.ts, and the row
stays byte-identical under --apply. The two earlier fixtures still refuse and
still name src/lock.ts. The maintainer's store is unchanged at 5 repointable
rows and 21 dead paths, with no reuse section either way.

bun test ./test/ 1531 pass / 21 skip / 0 fail, test:e2e 35 pass.
@abogartz

Copy link
Copy Markdown
Owner Author

Reproduced and fixed at 882618c. You found the third shape, and it shows the previous rule was scoped wrong rather than merely incomplete.

Reproduction. Four commits: src/lock.ts added, moved to legacy/lock.ts (R100), the moved file deleted, an unrelated component committed at legacy/lock.ts. Row about the original component citing src/lock.ts. Before the fix the script reported one repair and superseded the row onto legacy/lock.ts — a file the original component never occupied.

Why your diagnosis was exact. reused was built from the keys of hopScore, and a destination is never a key of hopScore. So the set could not contain the destination no matter how the count was computed. The fix is to stop restricting it: reused is now every path with more than one creation, and the check applies to whatever the chain walks — source, intermediate, or destination. chainEnd already visited that path before accepting it, as you said; it just never asked about it.

The report names the right file. Telling a human "src/lock.ts was reused" when legacy/lock.ts is the path with two lifetimes sends them to the wrong file, so ambiguousHop(ref, renamed, reused) returns whichever path in the chain has two creations, and that is what the report prints. Your fixture now says:

Occupied by more than one generation — history created this path more than once, in either order
around the move. It may be the cited path or the one the chain ends on. ...
  legacy/lock.ts

chainEnd and ambiguousHop share one hop walk (chainHops) rather than each keeping their own, so the two cannot disagree about what the chain contains — a duplicated walk is exactly how the destination got omitted the first time.

Tests. Four added: indexRenames puts a reused destination in reused while leaving the source out; ambiguousHop names the destination, names the source when the source is the reused one, and reports nothing for an empty set (with chainEnd still resolving normally in that last case). All 26 pass.

All three fixtures, and your store. Each refuses and names the path it should — the two earlier ones still name src/lock.ts, the new one names legacy/lock.ts — and each leaves the row byte-identical under --apply. Your store is unchanged at 5 repointable rows and 21 dead paths with no reuse section either way, which I checked by running both versions of the script back to back rather than reasoning about it.

Worth naming the pattern across the three rounds. Each finding was a rule scoped to the thing I was looking at instead of the thing the row touches: first the rename count, then the newest touch, then rename sources only. The property that actually matters is "can this path be cited by rows written against two different files", and it belongs to every path in the chain. A fourth round would have to break that, and I do not see how — but the last three rounds also said that.

bun test ./test/ 1531 pass / 21 skip / 0 fail, test:e2e 35 pass, comment-lint clean over 186 added lines, merge gate green on push.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reran --apply at 882618c against four disposable Git/store fixtures. In both source-reuse histories and the destination-reuse history, the original row stayed byte-identical and the script wrote zero successors. The report named legacy/lock.ts when the destination was the ambiguous path. As a positive control, the same R100 move without reuse produced one successor citing legacy/lock.ts. All 26 focused tests passed. This resolves my wrong-write findings.

@abogartz
abogartz merged commit 9595285 into main Nov 19, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.33.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants