Skip to content

fix: prefer HEAD-reachable atoms in Lore-id lookups, add doctor --all (fixes #57) - #74

Merged
Ian-stetsenko merged 1 commit into
mainfrom
fix/lore-id-head-first
Nov 3, 2026
Merged

Ian-stetsenko merged 1 commit into
mainfrom
fix/lore-id-head-first

Conversation

@TommyC81

Copy link
Copy Markdown
Collaborator

lore trace resolved Lore-ids with a single git log --all grep, so the newest commit by date across every ref won. A side branch (or a future-dated "poison" commit) sharing a Lore-id could shadow the legitimate current-branch decision, while lore doctor, which scans only the current branch, stayed silent about the duplicate.

This implements the accepted proposal: findByLoreId now greps the HEAD-reachable history first and consults --all only on a miss, and the Lore-id index is built the same way (HEAD pass seeds, --all pass fills misses) so trace BFS and reference validation stay consistent. lore doctor --all opts the Lore-id uniqueness check into scanning every ref and reports duplicates found across refs; the default stays current-branch only to avoid backup-branch noise, and no collision guard was added to lore commit per the plan. An integration test mirrors the reproduction from #57 (future-dated poison commit on a side branch plus a HEAD-reachable commit sharing the Lore-id) and covers trace resolution, silent default doctor, doctor --all reporting, and the side-branch-only fallback. Full suite is 484 green.

README and PROJECT_ARCHITECTURE updated in-PR; CHANGELOG left for release notes per repo convention.

Implements the maintainer's accepted proposal for issue #57. Previously findByLoreId ran a single git log --all grep, so the newest commit by date across every ref won: a future-dated commit on a side branch sharing a Lore-id shadowed the legitimate current-branch atom in lore trace, while lore doctor (current-branch scan only) stayed silent.

(a) findByLoreId now greps the HEAD-reachable history first and consults --all only on a miss, so a side branch can never shadow the current branch. The #67 Lore-id index follows the same rule: one HEAD pass seeds every id, then an --all pass fills only missing ids, keeping trace BFS, follow-link resolution, and reference validation consistent with the grep path. A failing HEAD pass (unborn branch on a fresh repo) is treated as a miss so fresh-repo behavior is unchanged.

(b) lore doctor --all opts the Lore-id uniqueness check into scanning every ref (findAll allRefs: --all) and reports duplicates found across refs as 'Lore-id uniqueness (all refs)'. Default output is unchanged; off by default because backup branches make cross-ref duplicates noisy.

(c) not implemented: no collision guard in lore commit, per the proposal.

Review hardening: the duplicated maxCommits bound in doctor is extracted to the DOCTOR_SCAN_LIMIT constant. Docs follow the contributor convention verified from merge history (#55, #56, #59, #66, #67): README doctor row and PROJECT_ARCHITECTURE lookup-semantics notes added in-PR; CHANGELOG.md left untouched because the changelog is maintainer-owned, written at release time with contributor credits.

Lore-id: d181468e
Constraint: findByLoreId stays a targeted git log --grep per id; no full-index build for single lookups
Constraint: getLoreIdIndex keeps its single ReadonlyMap API so trace BFS, validator, and follow-link consumers stay unchanged
Constraint: doctor default output must stay byte-equivalent to before; --all only widens the uniqueness scan
Constraint: fresh-repo (unborn HEAD) behavior preserved: lookups return null/empty, not a git error
Constraint: CHANGELOG.md is maintainer-owned release notes; contributors update README and PROJECT_ARCHITECTURE in-PR (verified from merge history of #55/#56/#59/#66/#67)
Rejected: Keeping the single --all pass with newest-first ordering: that is the reported bug (side-branch shadowing)
Rejected: Collision guard in lore commit: maintainer explicitly deferred it as (c)
Rejected: Replacing the index API with a two-tier lazy lookup method: ripples through trace and validator consumers for no behavioral gain
Rejected: Swallowing --all pass failures: real git errors must stay loud; only the HEAD pass falls through
Directive: If a commit-time collision guard is ever added, keep it a warning; the maintainer deliberately deferred it
Directive: Keep lookup HEAD-first when extending to new consumers; do not reintroduce bare --all-first resolution
Tested: npm run build
Tested: npm run typecheck
Tested: npm test: 484 passing (467 baseline + 17 new)
Tested: integration repro of issue #57: trace resolves the HEAD-reachable atom over a 2030-dated poison commit, doctor default silent, doctor --all reports the duplicate
Tested: unit: HEAD-hit skips --all, miss falls back to --all, unborn-HEAD HEAD-pass failure falls back, index HEAD-preference and off-branch fill
Tested: integration: fresh repo (no commits) returns null and empty index
Tested: review-fix re-run: full suite 484 green after DOCTOR_SCAN_LIMIT extraction
Not-tested: performance on very large corpora with many refs (two log passes per index build)
Not-tested: repositories with a detached HEAD
Confidence: high
Scope-risk: moderate
Reversibility: clean
@Ian-stetsenko
Ian-stetsenko merged commit 42a5646 into main Nov 3, 2026
2 checks passed
@Ian-stetsenko

Copy link
Copy Markdown
Owner

Merged to main in 42a5646 and shipping in 0.7.0. Thanks, this matches the proposal on #57 exactly and the integration test mirroring the reproduction is what made it easy to accept. Verified on Windows locally (the PR itself ran before the Windows CI leg from #70 landed): build, typecheck and the full suite are green, and doctor --all on this repository correctly surfaces a Lore-id that an old rebased branch still carries while the default stays quiet.

One non-blocking follow-up if you feel like it: getLoreIdIndex now walks HEAD history twice (once in the HEAD pass, again inside --all) and parses those commits twice before first-wins dedupes them. --all --not HEAD for the second pass would give only the delta, with a plain --all fallback when HEAD is unborn. On this repo it is unmeasurable; on the 1.4M-commit corpus from #55 it might be worth checking.

@TommyC81
TommyC81 deleted the fix/lore-id-head-first branch November 3, 2026 08:13
@TommyC81

TommyC81 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Taking up the non-blocking follow-up from your review: #75 makes the second pass walk only the delta. One design note beyond the suggestion: instead of --all --not HEAD on the ref, it resolves HEAD once and walks exactly that pinned commit, then runs --all --not <pin>. Resolving before the walk is what makes the pin sound under concurrency (a landing commit or branch switch between the passes can neither exclude walked history nor hide new history). Plain --all stays the fallback on unborn HEAD and on a failed pinned walk.

thoroc pushed a commit to pantheon-org/lore-protocol that referenced this pull request Nov 9, 2026
Follow-up on PR Ian-stetsenko#74 (d181468e), from the maintainer's review note: getLoreIdIndex walked HEAD history twice. The HEAD pass seeds every reachable id, then the --all pass re-walked and re-parsed those same commits before first-wins deduplication discarded the duplicate work. On small repositories the cost is unmeasurable; on a 1.4M-commit corpus (issue Ian-stetsenko#55) every index build pays the double walk. The index now resolves HEAD once, walks exactly that pinned commit, then runs git log --all --not <pin> for the delta. Resolving before walking is what makes the pin sound under concurrency: the first pass always walks exactly the commit the second pass excludes, so the exclusion boundary stays self-consistent under concurrent branch movement or landing commits - walked history is never dropped from the delta pass and new history is never hidden from it (which duplicate of a mid-build-landing shared Lore-id wins first-wins remains timing-dependent, as it was before). Plain --all remains the fallback whenever HEAD cannot be resolved (unborn HEAD on a fresh repository, a single --all walk) or the pinned walk fails (the exclusion is given up so --all covers HEAD). Semantics are unchanged: pinned-pass atoms are inserted first and the delta pass only fills missing ids, so a side branch can never shadow the current branch (issue Ian-stetsenko#57), and newest-first first-wins within each pass keeps the same atom a grep-based findByLoreId returns. Coverage: unit tests pin the exact args of both passes in all three paths (pinned walk then delta; unresolved HEAD, single --all; walk failure then plain --all), and a real-git integration test asserts the index itself holds the side-branch-only id and lets the HEAD-reachable atom win the shared id, alongside the existing shadowing and unborn-HEAD integration tests.

Lore-id: de1d01a2
Constraint: Resolve HEAD before walking and walk the pinned commit: the pin must always equal what the first pass walked, or the delta exclusion can misclassify history under concurrent branch movement.
Constraint: Unresolved HEAD and failed pinned walk both keep the plain --all fallback, so the union of the passes never shrinks below git log --all.
Constraint: Index semantics stay identical to PR Ian-stetsenko#74: HEAD-reachable atoms win, delta pass fills only missing ids, first-wins within each pass.
Tested: npm run typecheck: clean
Tested: Full suite on Windows: 508 tests in 34 files, all passing
Tested: Unit: pass-1 args are [pin], pass-2 args ['--all', '--not', pin] after a successful walk; unresolved HEAD runs a single ['--all'] walk; a failed pinned walk falls back to ['--all'] with head atoms retained
Tested: Real-git integration: the index holds the side-branch-only id (cafe1234) and the HEAD-reachable atom wins the shared id (deadbeef); existing unborn-HEAD and shadowing integration tests pass
Related: d181468e
Confidence: high
Scope-risk: narrow
Reversibility: clean
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.

2 participants