Skip to content

Resolve paths through case-variant sibling directories - #332

Merged
jbearak merged 13 commits into
mainfrom
case-variant-sibling-dirs
Oct 1, 2026
Merged

jbearak merged 13 commits into
mainfrom
case-variant-sibling-dirs

Conversation

@jbearak

@jbearak jbearak commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

On Linux, sight check reported "Cannot read file" for do "scripts/tables/export.do" when the file lived at Scripts/tables/export.do and a separate scripts/ 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

  • When the exact-cased directory's subtree misses, resolve_path_rich now searches its case-variant siblings. A unique hit resolves case_only. Sight reads the file, inherits its symbols, and emits path_case_mismatch ("Stata will not find it on case-sensitive filesystems") instead of cross_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.
  • The search is bounded to one read per component plus 256 for backtracking, so symlinks that alias a directory under several casings can't make it exponential. A search cut short reports ambiguous with truncated: true. That stops the candidate chain, and the cd diagnostic says the search hit too many case-variant directories. The search stops as soon as two hits prove a path ambiguous.
  • Case-mismatch messages now pair the path as written with the on-disk spelling of the same components, e.g. 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 miscased sight: cd, both sides stay relative to the caller.
  • The forward-closure memo now matches dependent URIs case-insensitively, so a file created under any casing of a probed path evicts the closures it could change. A closure is stored unservable, and walked live, when its cd target 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 concurrent sight check workers 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

  • I reproduced the original warnings by running sight check from 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.
  • Tests that need scripts/ beside Scripts/ 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.
  • Codex review ran 15 rounds. The last reported no findings.
  • 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, and bun run build:bundle passed independently.

Decisions and deferrals

  • The scope cache's reverse-dependency index still matches watcher events by exact URI, and creating a file doesn't revalidate callers. A file created at a path a caller probed and missed leaves that caller's cached scope stale until the caller is edited. The missed path can be a case variant or a higher-priority working-directory or workspace-root candidate. This is pre-existing on main for every probe kind. Fixing it means giving the scope cache the probe tracking the memo already has, which is separate work.
  • The memo does not observe directory-only changes. Creating a directory or a directory symlink that puts an existing file under a higher-priority candidate path fires no Stata-file event, so a closure that fell back to a lower tier stays cached. This is pre-existing on main for exact-cased paths too. The branch only makes a closure unservable when its winning resolution matched a directory case-insensitively.
  • Exact-cased directories beat their siblings. If scripts/ holds clean.do and Scripts/ holds an extensionless clean, do scripts/clean resolves to scripts/clean.do, which is the file Stata opens on that filesystem.
  • A directory the walk can't read, or a symlink it can't stat, counts as absent. The resolver did the same before this change, and the shared symlink-aware entry helpers do the same in the indexer, check discovery, and completion.

Summary by CodeRabbit

  • Bug Fixes
    • Paths can now resolve when directory names differ only by letter casing, including nested paths and fallback file matches.
    • When a path’s casing differs from the on-disk name, a diagnostic identifies both versions. Multiple possible matches are reported as ambiguous rather than resolved arbitrarily.
    • Searches that exceed the directory-search limit are reported as inconclusive, and the working directory is left unchanged.

jbearak added 13 commits October 1, 2026 07:57
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.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 5da7c93f-fcc7-4d44-be0b-871d4a10d32b

📥 Commits

Reviewing files that changed from the base of the PR and between aabb494 and e006433.

📒 Files selected for processing (7)
  • docs/cross-file.md
  • src/forward-scope-resolver/index.ts
  • src/utils/file-path-utils.ts
  • tests/integration/forward-closure-memo-store-serve.test.ts
  • tests/integration/sight-check-path-case.test.ts
  • tests/unit/cd-timeline.test.ts
  • tests/unit/path-resolve-rich.test.ts

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.


📝 Walkthrough

Walkthrough

The 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.

Changes

Case-variant path resolution and closure memoization

Layer / File(s) Summary
Bounded case-variant path lookup
src/utils/file-path-utils.ts, src/forward-scope-resolver/index.ts, tests/unit/path-resolve-rich.test.ts, tests/unit/cd-timeline.test.ts, tests/integration/sight-check-path-case.test.ts, docs/cross-file.md
The resolver checks exact paths before searching case-variant sibling directories. It reports ambiguous outcomes for multiple matches or an inconclusive bounded search. Tests and documentation cover path resolution, diagnostics, and cd behavior.
Casing-aware closure memoization
src/forward-scope-resolver/index.ts, tests/integration/forward-closure-memo-store-serve.test.ts
Closure builds track directory-casing dependence and do not serve closures that depend on case-insensitive directory matches. Memo invalidation matches dependent URIs without regard to ASCII letter casing. Integration tests cover invalidation, serving, and collector cleanup.

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
Loading

Merge Risk: ⚪ Minimal · up to e0064

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: resolving paths through directories whose names differ only by case.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 6 files. (1 skipped: 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@jbearak
jbearak merged commit 07c6d27 into main Oct 1, 2026
13 checks passed
@jbearak
jbearak deleted the case-variant-sibling-dirs branch October 1, 2026 22:06
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