Skip to content

fix(identity): probe volume case sensitivity instead of trusting the platform (#109) - #250

Merged
abogartz merged 5 commits into
mainfrom
fix/case-sensitive-volume-probe-109
Nov 2, 2026
Merged

abogartz merged 5 commits into
mainfrom
fix/case-sensitive-volume-probe-109

Conversation

@abogartz

@abogartz abogartz commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Problem

normalizeDirPath folded path case on every win32/darwin host:

if (process.platform === "win32" || process.platform === "darwin") r = r.toLowerCase();

A case-sensitive APFS volume is a legitimate macOS choice (and NTFS has per-directory case sensitivity). There, Foo and foo are two directories, but both hashed to one repo= key, and isVisibleTo matched on the key alone — silent cross-project visibility for path-derived keys (repos without a git origin).

Fix

Probe the filesystem instead of trusting the platform. isCaseInsensitivePath(dir) flips one cased character of the deepest existing component and stats both spellings: the volume folds names itself exactly when the flipped spelling still names the same dev+inode. A missing path is decided from the nearest existing component; answers cache per path (FIFO-capped, like the session map). Truly undecided — nothing of the path exists, or no component carries case — falls back to the old platform rule, which is also a no-op whenever the path has no cased characters.

Compat story (no re-stamp migration)

Rows written under the old fold carry repoPath (the true spelling) and isVisibleTo already matches on it, so:

Known, intended behavior change: on a case-sensitive volume, renaming a directory's case now yields a different key (as on Linux); rows stamped under the old spelling stay visible only while the raw path is unchanged.

Tests

  • isCaseInsensitivePath pinned against an independent filesystem oracle (write osi-case-oracle, look for OSI-CASE-ORACLE) — never against itself.
  • normalizeDirPath folds exactly when the volume folds (fixture with guaranteed cased characters).
  • Two dirs differing only by case share a key only where the volume folds them (existence of the second mkdir is the oracle).
  • Undecided fallback pinned for a wholly missing path.
  • Compat: a row forged with the old platform-fold key stays visible through repoPath.
  • The pre-existing spelling-stability test now branches on the oracle instead of process.platform.

Verified locally on both volume types: full suite (872 tests) and e2e (30) green on the insensitive boot volume and on a case-sensitive APFS disk image (hdiutil create -fs "Case-sensitive APFS"); the compat and two-dirs tests run their sensitive branches there. tsc and biome lint clean.

Smaller items from the ticket body: the tautological assertion in test/repokey-path.test.ts was already fixed on main; #101's "unmatchable-by-hash across machines" wording is corrected on the issue.

…platform (#109)

normalizeDirPath folded path case on every darwin/win32 host, so two
directories differing only in case on a case-SENSITIVE APFS volume (or an
NTFS dir with per-directory sensitivity) hashed to one repo= key and read
each other's rows. Replace the platform check with a probe: flip one cased
character of the deepest existing component; the volume folds names itself
only when the flipped spelling still names the same dev+inode. Undecided
paths (nothing exists, no cased characters) keep the old platform rule.

No re-stamp migration: rows written under the old fold carry repoPath (true
spelling) and isVisibleTo already matches on it, so they stay visible to
their own repo while the cross-case leak closes for them too.

Tests pin the probe against an independent filesystem oracle and cover both
volume types (verified on an insensitive boot volume and a case-sensitive
APFS disk image).
@abogartz
abogartz force-pushed the fix/case-sensitive-volume-probe-109 branch from 6ec489d to e079003 Compare November 2, 2026 05:30

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed head e079003c87b29c4c55156a389c7069ea933d922d (diff key 96abfafe…0e0c).

Verdict: APPROVE — posted as a comment review because GitHub refuses an approve event on a PR authored by the same account (422 "Can not approve your own pull request", GraphQL and REST alike). No behavior defect found; a human can merge on this review.

Commands run (measured)

  • bun run typecheck — clean
  • bun run lint — 498 warnings, identical to the main baseline
  • bun run test — 872 tests: 860 pass, 12 skip, 0 fail
  • bun run test:e2e — 30 pass, 0 fail (src/ changed)
  • CI: lint / test / test-windows / smoke all pass

Verification of the body's claims against the tree

  • The compat story holds: isVisibleTo (src/store/model/visibility.ts:73) already matches m.repoPath === reader.scope.path, and appendMemory stamps repoPath from target.scope.path (src/store/files/append.ts:135). Old rows written under the platform fold therefore stay visible through repoPath, and on a case-sensitive volume repoPath distinguishes /x/Foo from /x/foo, closing the leak for old rows too.
  • The compat test is non-trivial on every platform: the forged oldKey differs from the new key on macOS (realpath adds /private) and on Linux (the fold lowercased CompatProj), so the assertion genuinely exercises the repoPath path, not a key collision.
  • Probe fails in the safe direction: folding happens only on a positive same-dev+ino confirmation; any stat error yields "no fold" — a key split, never a cross-project leak.
  • Parent walk terminates on POSIX, Windows drive, and UNC forms; index 0 is protected so a C: drive letter never flips.
  • The oracle (osi-case-oracle write + uppercase existsSync) is independent of the probe under test.

Findings

No P0/P1.

  • nit — test/repokey-path.test.ts:214: the comment says oldKey is "exactly what the pre-fix normalizer stamped for this path on ANY platform", but the pre-fix normalizer applied realpath first, so on macOS the real pre-fix stamp carried the /private prefix. The test's purpose (visibility via repoPath when keys differ) is unaffected; the comment overstates.
  • nit — src/identity/repokey.ts:86: flipLastCased scans the whole path, so when the deepest existing component carries no case the probe answers for an ancestor's volume. If that case-free component were itself a mount point of a volume with different case semantics, the answer would be wrong. Contrived; the fallback direction stays safe.

Approving: the fix probes the filesystem instead of trusting the platform, the compat story is verified in the tree, and every check is green here and in CI.

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

Review findings at e079003c87b29c4c55156a389c7069ea933d922d, against main 8dd43e6edaf80381b3a06789142ac5f1645900d1. Recommendation: request changes for two reproduced repository-isolation gaps. Posting as a comment review; merge and scope decisions remain yours.

F1 — new regression: a case-variant symlink is mistaken for filesystem case folding

Location: src/identity/repokey.ts:115–117 (alternate spelling + statSync inode comparison), followed by whole-path lowercasing in normalizeDirPath.

On a real case-sensitive filesystem, create distinct directories Foo and foo, then a symlink FoO -> Foo. The last-character flip of Foo is FoO. Because statSync follows the link, it sees the same inode and returns true, even though Foo and foo are distinct repositories. Under an all-lowercase ancestor path, both resolve to the same key. A memory written for Foo is then retrieved by relevantKnowledge() from foo.

Differential: the same actual-write/retrieval probe passes on main (separate keys, no foreign content) and fails on this head (same keys, foreign content returned). No filesystem mocks. This also contradicts the existing review's statement that the probe can only fail toward a safe key split: same-inode lookup through a symlink is a false positive.

Suggested acceptance: the alternate spelling must not establish case-insensitivity merely by following an alias. Pin two distinct real directories plus a case-variant symlink, and verify the foreign row is excluded. More broadly, one component's result should not justify folding case-sensitive ancestor components. I have not independently exercised mixed-volume or per-directory NTFS configurations here.

F2 — pre-existing gap left open: legacy folded keys still authorize the lowercase sibling

Location: new compatibility test in test/repokey-path.test.ts and unchanged isVisibleTo / evidenceVisibleTo in src/store/model/visibility.ts.

For /tmp/<all-lowercase-parent>/Foo, an old win32/darwin-style stamp is sha1(lowercase(realpath(Foo))), with repoPath retaining Foo. That old key equals the new path key of the distinct lowercase sibling foo. The predicate is:

m.repo === reader.scope.key || (!!m.repoPath && m.repoPath === reader.scope.path)

So the matching key grants access before the conflicting repoPath can distinguish the repositories. I seeded that exact legacy stamp, verified that the owner still retrieved it, then switched to foo: actual relevantKnowledge() returned the private row there too. evidenceVisibleTo accepts the equivalent evidence stamp as well.

This is pre-existing, not a new regression: the negative isolation assertion fails on both base and head. But it means the PR body's claim that the cross-case leak closes for old rows is not yet true. The new compat test proves continued owner access only; it needs the negative sibling check too. A safe compatibility policy must distinguish legacy path-derived identities without breaking intentional shared-origin identity; simply rejecting all differing repoPath values would be too broad.

Reproducer and validation

The essential filesystem setup is below. The all-lowercase ancestor matters: use a lowercase UUID, not an unconstrained mkdtemp suffix whose uppercase letters can mask these collisions.

// Run on a case-sensitive filesystem, from the repository root with Bun.
import { mkdirSync, symlinkSync } from "node:fs";
import { createHash } from "node:crypto";
import { resolveRepo } from "./src/identity/repokey.ts";
import { isVisibleTo } from "./src/store/model/visibility.ts";

const root = `/tmp/osi250-${crypto.randomUUID()}`;
mkdirSync(root);
mkdirSync(`${root}/Foo`);
mkdirSync(`${root}/foo`);
const lower = resolveRepo(`${root}/foo`);
const oldKey = createHash("sha1")
  .update(`${root}/Foo`.toLowerCase()).digest("hex").slice(0, 12);
console.log("F2: foreign legacy row visible", isVisibleTo(
  { repo: oldKey, repoPath: `${root}/Foo` },
  { kind: "repo", scope: lower },
)); // true, should be false

// Resolve Foo only AFTER creating the alias: otherwise the probe cache masks F1.
symlinkSync(`${root}/Foo`, `${root}/FoO`);
const upper = resolveRepo(`${root}/Foo`);
console.log("F1: distinct repositories collide", upper.key === lower.key);
// true on this head, false on base

Validation: Bun 1.4.4; existing repokey-path.test.ts passes all nine tests on both Windows and WSL Linux. The stronger external probes use appendMemory() plus relevantKnowledge() against throwaway stores: both isolation assertions fail at the PR head; only the legacy assertion fails on base. Those probes and logs are preserved locally. Hosted checks remain green. I did not rerun the full suite/E2E or test a live macOS APFS volume; the old-platform stamp was synthesized on real case-sensitive WSL Linux. No production changes made.

@WhollyMindless

Copy link
Copy Markdown
Contributor

Offered an F1-only companion PR: #251, based directly on this branch at e079003 and targeting fix/case-sensitive-volume-probe-109 (not main).

It checks the exact case-flipped component with lstat, rejecting a symlink there, including when an uncased numeric child follows it. Genuine input aliases still canonicalize to their targets. Both new regressions fail on your current head and pass with the fix on case-sensitive WSL Linux; the full Windows merge gate also passes, including all 30 E2E tests. Validation details and platform limits are in #251.

F2 is unchanged and remains a separate compatibility-policy finding. Please feel free to merge, cherry-pick, adapt, defer, or reject the companion PR — it is an optional contribution, not a request to surrender ownership of this work.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Head reviewed: e079003c87b29c4c55156a389c7069ea933d922d

Contract: closingIssuesReferences is empty — this PR does not formally close #109 (title references it; body never says Closes). Per reviewer policy that means a merits review posted as a comment; no approval from me. #109 is human-authored (abogartz), so the blocker is the missing Closes #109 footer, not bot provenance.

Contract as stated by #109 (quoted): "A case-sensitive APFS volume is a legitimate macOS choice. There, Foo and foo really are two directories, but they now hash to one repo= key … Silent cross-project visibility."

Verdict: the fix works, measured on a real case-sensitive volume

I built the differential rather than trusting the PR body:

  1. hdiutil create -fs "Case-sensitive APFS" -volname OSI109CS — confirmed sensitive (probe created, PROBE → No such file or directory).
  2. Fixed side (this head), TMPDIR=/Volumes/OSI109CS bun test test/repokey-path.test.ts → 9 pass / 0 fail.
  3. Broken side (same head, one line reverted to the pre-fix platform rule const fold = process.platform === "win32" || process.platform === "darwin") → 2 fail for exactly the stated reason:
    • normalizeDirPath lowercased on a case-sensitive volume: Expected to contain: "MixedCase" / Received: "/volumes/osi109cs/…/mixedcase" (test/repokey-path.test.ts:174)
    • two real dirs differing only by case shared one key: Expected: not "9a5f0c64acad" (test/repokey-path.test.ts:195) — the leak #109 describes, reproduced and closed.

Commands run (measured)

command result
bun run typecheck clean
bun run lint 498 warnings = baseline, no new
bun run test 872 tests, 860 pass, 12 skip, 0 fail
bun run test:e2e 30 pass, 0 fail (src/ changed)
gh pr checks 250 lint / test / test-windows / smoke all pass
case-sensitive volume, this head 9/9 pass
case-sensitive volume, fold reverted 2 fail (above)

Test-quality audit

No deleted assertions, no .skip, no widened tolerance. The oracle (volumeFoldsCase, test/repokey-path.test.ts:39) is independent of the probe: it writes osi-case-oracle and checks OSI-CASE-ORACLE via existsSync, never calling isCaseInsensitivePath. The pre-fix tautological assertion from #109's smaller items is already fixed on main (visible as unchanged context: expect(n.endsWith("/")).toBe(false)). Compat claim verified end-to-end: the forged-old-key row stays visible through repoPath on both volume types (compat test passed under TMPDIR=/Volumes/OSI109CS).

Probe logic review (src/identity/repokey.ts)

  • dev+inode comparison (not string compare) is the right ground truth; a flipped spelling that exists as a different dir correctly yields false via differing ino.
  • flipLastCased skipping index 0 protects the Windows drive letter (C:); a component with no case walks up to the nearest ancestor that has one, so mixed-volume paths (/Volumes/X/123) probe the volume that actually holds the deepest component.
  • statOrNull swallowing errors is correct for a probe: realpathSync already resolved the true spelling, and on a folding volume the flipped path resolves to the same inode, so a transient stat failure cannot flip the answer.
  • FIFO cache capped at 64, keyed on the normalized path; probe cost is 1–2 statSync per uncached path, called from resolveRepo, not a hot loop.

Findings

  • P0: none.
  • P1: none.
  • nit (src/identity/repokey.ts:71): the probe answer for a not-yet-existing path is cached from the nearest existing ancestor. If that exact path is later created as a mount point of a different-sensitivity volume, the cached answer is stale until process restart. Vanishingly rare; not worth code.

To get an approve: add Closes #109 to the PR body so the contract is machine-visible. The code itself is clean on every axis I could measure.

fix(identity): reject case-variant symlink probes (#250 F1)
@abogartz abogartz added the review:requested Human-admitted for autonomous review by ocsi-reviewer label Nov 2, 2026

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed at head 5613d5e58c834d7e7cb9509522af8e7dc4a4086a (diff key f6ca866f5a9a5531a7afb705ea860104369744d2084725fffacdf38eed798c6d).

What moved since the last reviewed head e079003

The branch merged main (4caef0f) and absorbed stacked PR #251 (4a4a9c5, merged 2026-11-02T17:48:51Z). The PR diff against main is now the union of the two previously-reviewed changesets:

  • src/identity/repokey.ts and test/repokey-path.test.ts at this head are byte-identical to df90d5f (head of #251, git diff df90d5f..5613d5e shows only README.md +12 from main).
  • The merge introduced no content of its own beyond main's README.

Contract

closingIssuesReferences is still empty. The title and body reference #109 but the body carries no Closes #109 keyword, so GitHub registers no closing issue. Per policy I cannot approve with no machine-readable contract to verify against. Action for author: add Closes #109 to the PR body. Everything else on this list was already green at the component heads.

Verification at this head

Check Result
gh pr checks 250 lint / test / test-windows / smoke — 4/4 pass
bun run typecheck 0 errors (223 files)
bun run lint 498 warnings = baseline
bun run test 860 pass / 14 skip / 0 fail, 11980 expects
bun run test:e2e 30 pass / 0 fail

Skip audit: the two skips beyond the prior 12 are describe.skipIf(aliasVolumeFolds) around the #250 F1 symlink fixtures — creating Foo and foo as distinct directories is impossible on a case-folding volume, so the fixture cannot exist there. Both suites ran green on a real case-sensitive APFS volume (hdiutil create -fs "Case-sensitive APFS") at df90d5f in the #251 review (11/11), with the differential failing at base e079003 for the stated alias-following reason. No assertions deleted, no unconditional .skip, no tolerance widened in the test diff.

Findings

  • P0: none.
  • P1: none.
  • Nit (carried from the e079003 review, non-blocking): isCaseInsensitivePath caches per path; if a cached path later becomes a mount point with different case sensitivity, the cached answer goes stale. Acceptable as-is; noting for the record.

Verdict: COMMENTED — not because of any defect, solely because the contract is empty. Add Closes #109 and the next run can approve against #109's criteria.

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

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.7 🎉

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

released review:requested Human-admitted for autonomous review by ocsi-reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants