Repository navigation
Resolve paths through case-variant sibling directories - #332
Conversation
A case-sensitive checkout can hold directories whose names differ only in case (`Scripts/` beside `scripts/`). On the case-insensitive machine where the code was written they are one directory, so `do "scripts/tables/export.do"` finds `Scripts/tables/export.do` there. On Linux, resolve_path_rich took the exact-cased `scripts/` and never looked at `Scripts/`, so `sight check` reported "Cannot read file" for the callee and for every caller that reached it transitively. The walk now backtracks: when the exact-cased directory's subtree misses, each case-variant sibling is searched, and a unique hit resolves as case_only, so the callee is read and a path_case_mismatch warning replaces the missing-file one. Exact matches still win, and hits under two or more siblings are ambiguous. The case-mismatch messages for forward calls and cd now pair the path as written with the on-disk spelling of the same components, instead of re-basing both onto the caller's directory (which showed "../../scripts/..." for paths resolved against the workspace root).
Codex review, round 1: - When a call resolved through one case-variant sibling directory, the walk discarded the probes of the siblings that missed, so creating the file under an empty sibling (which makes the call ambiguous) evicted nothing and the memo kept serving the old closure. The walk now reports every as-written path it probed and found absent, under every directory it visited, through RichResolveOptions.missed_probes; resolve_forward_call_rich feeds those into its missed_candidates. - case_mismatch_display_paths paired the as-written suffix even when the miscasing was in the resolution base (a miscased working directory), printing the same spelling twice. It now pairs only when the base matches the disk exactly.
Codex review, round 2: a case-only resolution changes when a file appears under ANY casing of the probed path (`SCRIPTS/Clean.do`, or a new `SCripts/clean.do`, beside the winning `Scripts/clean.do` makes the call ambiguous). Recording particular spellings cannot cover that, so the round-1 walk-level probe recording is reverted in favor of keying the memo's dependent-URI index by the ASCII-case-folded URI: an invalidation for any casing of a dependent now evicts. Over-matching only over-invalidates.
Codex review, round 4: symlinks can alias one directory under several casings (`a -> .` beside `A -> .`), so backtracking into case-variant siblings doubled the directory reads at every component, about two million reads for a 20-component missing path. The walk now spends at most one read per component (all the exact-first descent needs, so nothing it reaches is cut off) plus MAX_CASE_VARIANT_BACKTRACK_READS for backtracking; past that, unexplored branches count as misses.
Codex review, round 5: when the backtracking budget ran out partway through a component's case-variant siblings, the branches it never read counted as misses, so one hit found earlier was returned as a unique case_only match even though an unread sibling might also hold the file. A single hit from a search cut short is now a miss; two or more remain ambiguous.
Codex review, round 6: reporting a truncated search as missing let resolve_forward_call_rich fall through to a lower-priority candidate (for example a script-relative exact match) although the higher-priority search had found a match and might hold more. A search cut short is inconclusive, so it now reports ambiguous, which stops the candidate chain the same way two or more case-insensitive matches do.
Codex review, round 7: a branch whose directory could not be read (EACCES, EIO, ...) counted as a proven miss, so a hit in another case-variant sibling was promoted to a unique case_only match even though the unreadable branch might hold another. A lone hit beside an unreadable branch at the same level or below now reports ambiguous. With no hit at all, a read failure stays a plain miss, as before backtracking existed.
Codex review, round 8: - Reusing `ambiguous` for a search the read budget cut short left the cd diagnostic claiming "multiple case-insensitive matches" it never saw. Such outcomes now carry `truncated: true`, and the cd message says the search had too many case-variant directories instead. - Round 7 made unreadable directories inconclusive, but symlinks that fail to stat are, like everywhere else in Sight, still treated as absent by the shared symlink-aware entry helpers. Rather than split the policy, revert round 7: anything the walk cannot read or stat counts as absent, as in the resolver before backtracking.
Codex review, round 9: a cd target that resolved case_only or ambiguous depends on which case-variant directories exist (creating SCRIPTS/tables beside Scripts/tables makes it ambiguous), but the watcher reports only Stata files, so no dependent URI could evict the memoized closure, and editing the outer caller kept serving symbols from the old working directory. build_cd_timeline now reports depends_on_directory_casing, and a standalone build that saw one is stored unservable, so that closure is always walked live. This also covers leaf-level case-only cd targets, which had the same gap on main.
…nsensitively Codex review, round 11: a case_only call such as "scripts/clean.do" resolving through Scripts/ depends on which case-variant directories exist, and creating a directory or a directory symlink (SCRIPTS -> Scripts) that makes it ambiguous fires no Stata-file event, so the case-folded dependent index could not evict the memoized closure. Calls whose case_only match crossed a directory component now mark the build as depending on directory casing, like case-insensitive cd targets, and are stored unservable. Leaf-only mismatches stay cacheable, since file events for any casing still evict them.
Codex review, round 12: the directory-casing flag was broadcast to every in-flight standalone build, like probe sets. Extra probes only over-invalidate, but this flag stores the entry unservable, so under concurrent resolutions (sight check workers share the resolver) one miscased directory disabled caching for unrelated files. The flag now reaches only the build whose walk made the match: each build's collector is looked up by its own visited map, which live recursion passes through and nested builds replace. Enclosing builds need no propagation, because an inner entry stored unservable is walked live in the enclosing context.
Codex review, round 13: two hits already prove a path ambiguous, but the sibling loop kept reading, spending up to the whole backtracking budget and then labelling a proven ambiguity as truncated (so cd reported "too many case-variant directories" instead of multiple matches). The loop now returns ambiguous as soon as it has two hits.
Codex review, round 14: a stored closure keeps its build's visited map as visited_delta, so the collector_by_visited entry keyed by it, and the build's probe set, lived as long as the memo entry. The mapping is now dropped in the build's finally block, once no walk of that build can look it up.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (7)
Included review availability: This review used your included allowance. 5 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour. 📝 WalkthroughWalkthroughThe path resolver now searches case-variant sibling directories after an exact-cased path fails, within a read bound. The forward-scope resolver tracks directory-casing dependence in closure builds and uses case-folded URI keys for memo invalidation. ChangesCase-variant path resolution and closure memoization
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant ForwardScopeResolver
participant PathResolver
participant FileSystem
participant ClosureMemo
ForwardScopeResolver->>PathResolver: Resolve call or cd path
PathResolver->>FileSystem: Read directory entries
FileSystem-->>PathResolver: Return directory entries
PathResolver-->>ForwardScopeResolver: Return path outcome
ForwardScopeResolver->>ClosureMemo: Store closure with casing-dependence state
ForwardScopeResolver->>ClosureMemo: Invalidate by case-folded dependent URI
Merge Risk: ⚪ Minimal · up to The change makes path resolution find files under case-variant sibling directories and report a case-mismatch warning instead of a missing-file warning. It is bounded and covered by new tests, and no merge-blocking risk was identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
On Linux,
sight checkreported "Cannot read file" fordo "scripts/tables/export.do"when the file lived atScripts/tables/export.doand a separatescripts/directory also existed. On macOS and Windows those are one directory, so the code works for its authors. A Linux checkout holds two directories, and the resolver only searched the exact-cased one. Every caller that reached the callee transitively got its own copy of the warning, so two such paths produced 22 warnings in the project where this came up.Behavior
resolve_path_richnow searches its case-variant siblings. A unique hit resolvescase_only. Sight reads the file, inherits its symbols, and emitspath_case_mismatch("Stata will not find it on case-sensitive filesystems") instead ofcross_file_missing_file. Exact matches still win, and hits under two or more siblings are ambiguous.do/run/include,cd, directives, go-to-definition, and the dependency graph all share this resolver.ambiguouswithtruncated: true. That stops the candidate chain, and thecddiagnostic says the search hit too many case-variant directories. The search stops as soon as two hits prove a path ambiguous.Path "scripts/tables/export.do" does not match the file on disk "Scripts/tables/export.do". Before, both sides were re-based on the caller's directory, which printed"export.do"against"../../Scripts/tables/export.do"for a path resolved against the workspace root. When the miscasing is in the resolution base, such as a miscasedsight: cd, both sides stay relative to the caller.cdtarget or a directory component of a call path matched case-insensitively, because no Stata-file event reports a new case-variant directory or directory symlink. Only the build whose own walk made the match is affected, so concurrentsight checkworkers keep caching unrelated files. Leaf-only mismatches stay cacheable. This also closes the same gap for case-only directory matches that already existed on main.Validation
sight checkfrom source on that project copied onto a case-sensitive APFS volume. With this branch, the 22 missing-file warnings become 3 case-mismatch warnings, one per call site. The warnings that remain are unrelated to casing.scripts/besideScripts/probe the temp filesystem and skip where it can't hold both, so Linux CI runs them. I also ran them locally on the case-sensitive volume. The other new tests use injected filesystems and run on every host. Each new test fails on main.bun test ./tests: 7,900 passed, 9 skipped (3 of them the new host-gated tests, on macOS), 0 failed.bun run check:line-endings,bun run typecheck,bun run lint, andbun run build:bundlepassed independently.Decisions and deferrals
scripts/holdsclean.doandScripts/holds an extensionlessclean,do scripts/cleanresolves toscripts/clean.do, which is the file Stata opens on that filesystem.Summary by CodeRabbit