Repository navigation
fix(detect): prune a linked worktree whose main checkout is in the scan root (#4683) - #4833
barlowa124 wants to merge 1 commit into
Conversation
…an root (Graphify-Labs#4683) A workspace folder holding a repo and a linked worktree of it as siblings was indexed twice: every file in the worktree counted as a second copy, roughly doubling the graph and leaking the copy's paths into reports. The name-based rules (.worktrees/, <dot>/worktrees/) and .git/info/exclude cannot cover this layout — the worktree's directory name is arbitrary, and a workspace root that is not itself a repo has no info/exclude to read. A linked worktree is unambiguous on disk: its .git is a file pointing at <main>/.git/worktrees/<name>, whose commondir points back to <main>/.git, so the main checkout's root is the common dir's parent. When that main root resolves inside the scan root, the worktree is pruned and recorded in pruned_noise_dirs. Deliberately unchanged: scanning the worktree itself still indexes it; a worktree whose main is outside the root stays (it is the only copy); submodule gitdirs (no commondir) and bare-repo worktrees (shared git dir not named .git) are untouched. No git subprocess is used. Co-Authored-By: Devin <[email protected]>
|
Thanks for the pull request, @barlowa124. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).
Not verified on this run: detect (unsupported).
Graphify review — findings
Adds pruning of linked git worktrees in detect when their main checkout also sits under the scan root, so one repo is no longer indexed twice. The pruned directory is reported in pruned_noise_dirs. _linked_worktree_main_root identifies a worktree from its .git file and commondir back-pointer without spawning git, and returns None for submodules and dangling pointers, so those stay indexed. The prune decision depends only on the common dir being named .git and the main root resolving under the scan root, not on whether that main checkout is itself scanned.
Worth a look
- Worktrees of a bare repo stored as
.gitare pruned even though no main working tree exists —graphify/detect.py:1528· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
- Linked worktree pruned even when its main checkout is itself excluded from the scan —
graphify/detect.py:2261· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3943 functions depend on the 668 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
detect()— 147 callers, 19 callees
Verification — 3943 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1350 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
65 of 465 test file(s) selected (14%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_atomic_writes.py— impacttests/test_backend_opt_in.py— impacttests/test_binary_media_words.py— impacttests/test_build.py— impacttests/test_cargo_introspect.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_cjs_module_extension.py— impacttests/test_claude_cli_backend.py— impacttests/test_detect.py— impact, changed-testtests/test_docx_to_markdown.py— impacttests/test_dotnet.py— impacttests/test_ejs_extractor.py— impacttests/test_evidence_binding.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_extract_cli.py— impacttests/test_file_slice.py— impacttests/test_file_truncation_warning.py— impacttests/test_ignore_file_encoding.py— impacttests/test_image_vision.py— impacttests/test_import_extension_resolution.py— impacttests/test_incremental_mtime_collision.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_js_member_collisions.py— impacttests/test_language_override_imports.py— impacttests/test_language_override_lifecycle.py— impacttests/test_language_overrides.py— impacttests/test_languages.py— impacttests/test_llm_backends.py— impacttests/test_long_path_hashing.py— impacttests/test_manifest_ingest.py— impacttests/test_markdown_code_spans.py— impacttests/test_mcp_ingest.py— impacttests/test_msbuild_dir_evidence.py— impacttests/test_multilang.py— impacttests/test_non_regular_files.py— impacttests/test_office_incremental.py— impacttests/test_office_limits.py— impacttests/test_ollama.py— impacttests/test_out_dir_evidence.py— impacttests/test_oversized_document_slicing.py— impacttests/test_package_json_subpath_imports.py— impacttests/test_pdf_extra_warning.py— impacttests/test_pdf_slicing.py— impacttests/test_pdf_token_estimate.py— impacttests/test_phantom_external_import.py— impacttests/test_pipeline.py— impact- … and 15 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify detect.
The verifier did not have enough to check detect, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function
· 1 more finding(s) on lines outside this diff (see the check run).
|
Landed in v0.9.97, now on PyPI (pip install graphifyy==0.9.97). A linked worktree whose main checkout is in the scan root is pruned, so it is not double-indexed. Thanks for the fix, @barlowa124. |
What does this PR do?
Fixes #4683. A workspace folder holding a repo and a linked worktree of it as siblings (
ws/app/+ws/app-feature/) was indexed twice, so every file in the worktree counted as a second copy. On the reporter's ~78k-node graph this added ~13.8k duplicate nodes, and the copy's paths surfaced inGRAPH_REPORT.mdcommunity hubs.Neither existing guard reaches this layout. The name-based rules require a
.worktrees/or<dot>/worktrees/directory name, and.git/info/excludeonly exists when the scan root is itself a repo. A linked worktree is still unambiguous on disk. Its.gitis a file pointing at<main>/.git/worktrees/<name>, and that gitdir'scommondirpoints back to<main>/.git, so the main checkout's root is the common dir's parent. When that root resolves inside the scan root, the directory is pruned and recorded inpruned_noise_dirslike other noise prunes.Type of change
Verification & Invariants
Invariant: a corpus file is indexed once, and a directory is pruned only when it is provably a second checkout of a repo already under the scan root, never for carrying a
.gitfile alone.The prune fires only when the worktree's
commondirresolves to a<name>/.gitdirectory whose parent (the main worktree root) lies inside the resolved scan root. A submodule's.gitfile points at<super>/.git/modules/<name>with nocommondir, so it is untouched. A bare repo's shared git dir is not named.gitand has no main worktree, so its worktrees stay indexed. A moved or deleted main checkout leavescommondirdangling, and the worktree stays indexed as the only copy. Scanning the worktree itself still indexes it, and no git subprocess is spawned since the marker files are read directly. No persisted state changes, the pruned dir never entersfiles, sodetect_incrementaland the manifest see the same corpus a hand-built ignore rule would produce.How was this tested?
test_detect_prunes_sibling_linked_worktreefails onupstream/v8(AssertionError: linked worktree indexed as a second copy) and passes with the change. Three boundary tests cover the cases that must not change, the worktree as scan root, a worktree whose main checkout is outside the root, and a submodule gitdir withoutcommondir.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (No source fragments changed.)Known limitation: a repo cloned with
--separate-git-dirhas its common git dir outside the worktree and not named.git, so its linked worktrees are not deduplicated, they fail open and stay indexed.