Skip to content

Disclose a store known by two spellings differing only in case (#298) - #300

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/298-case-divergence-disclosure
Aug 3, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/298-case-divergence-disclosure

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Part of #298. Deliberately not Closes: the measurement that decides the rest of that issue — whether any real store's history carries both spellings — is still outstanding, and the issue should outlive this.

What this is not

The premise #298 was filed on does not survive @jqit-ricky's listing. It claimed a store created under the pre-#263 spelling (C--Users-…) is orphaned by the post-#263 resolver (c--Users-…). Test-Path on both spellings returns True for the same directory object, with 88 files reachable through either name. NTFS is case-insensitive, so two stores differing only in case is not a state that filesystem can be in. Nothing is stranded, the plugin reads that store, and the orphaning cannot happen on the platform #263 came from.

So there is no migration here, no merge, and no rename. test_nothing_here_repairs_anything is an allowlist — it fails if mv, cp, rm, mkdir, git mv, git add, git commit, git checkout, git clone, git fetch, git pull, git merge, git rebase, git reset or git push ever appear in the library — rather than a denylist, for the reason #253's restore hook gives: a denylist has to guess the name of the next dangerous verb.

What is actually detected

Git's index is case-sensitive where NTFS is not. On the reporter's machine:

on disk : C--Users-ricky-dev-jqit-project-b
in git  : c--Users-ricky-dev-jqit-project-b

Free while the store stays on NTFS, and the git backup exists precisely so the store can be restored elsewhere. Confirmed on a real case-sensitive APFS volume rather than reasoned about: one repository carrying both spellings, one plain git clone, out/C--proj/remember.md beside out/c--proj/remember.md.

Two probes, and why the git one alone was not enough

The issue frames this as "the path git tracked vs the path we resolved". Built as stated it would not fire on the one machine we can point at: there git tracks c--… and the post-#263 resolver computes c--…. Those agree. The divergence that is currently true on that box is between the directory's own name and the resolved one, which is what their listing shows. A git-only check would have been dead code on Windows — the reporter's exact objection to the sibling-scan shape, arriving a second time by a different route.

So there are two:

  • disk — the directory names in the store root that case-fold to the one we resolved. Not "does a sibling exist": on a case-insensitive filesystem there is exactly one entry, and the question is whether it is spelled the way we resolved it. Pure shopt -s nocasematch over a glob, no fork at all, and the only half that can fire on NTFS.

  • git — the top-level names in HEAD's tree of the store's own repository. HEAD's tree and not the history, which is a narrower claim than the issue makes and I think the correct one: a clone checks out HEAD, so a history carrying both spellings while HEAD carries one is inert. The split needs both spellings in the tree a checkout materialises. This is why the check does not run git log --all, and why it does not depend on the answer to the outstanding measurement.

Four answers, not two

ok (compared, they agree) / diverged / unavailable / not-applicable.

unavailable carries a reason: not-a-repository, git-not-installed, nothing-committed, store-not-tracked, store-root-unreadable. The last two matter most — "this store has never been backed up" and "the store root could not be read" are both absences produced by the check, and neither may read as agreement. unavailable never outranks a diverged another probe found; there is a test for that.

not-applicable is separate from all three: the legacy layout, and any store whose directory is not named by the slug. That is not "we looked and found nothing", it is "there is nothing here that could diverge" — and it is also the guard that stops this going anywhere near the user's own project repository, the same refusal 50-git-backup.sh makes at its top for #138.

The message

One hard requirement: a reader must not be able to conclude the opposite of the truth. On the reporter's machine the condition is TRUE and completely harmless. So the message says what is true now (nothing to fix, memory reading and writing normally), what would change that (a restore onto a case-sensitive filesystem), and that nothing will be done for them. test_the_notice_says_it_is_a_heads_up_and_not_a_fault asserts the words broken, lost, corrupt, stranded and not being read do not appear in it.

remember: this store's directory is spelled C--proj where this plugin resolves it as c--proj — spellings that differ only in case. On a case-insensitive filesystem those are one and the same, which is why memory is being read and written normally and there is nothing to fix today. It would matter on a restore: checked out onto a case-sensitive filesystem they become separate directories, and this plugin would use only c--proj. Nothing here will rename or merge anything for you — if you keep a backup of this store, check which spellings its HEAD holds before restoring it somewhere case-sensitive. Run /remember:doctor to see this again.

Delivered on systemMessage through user-prompt-hook.sh's notice loop — the one channel a human sees (#200, #253) — and only when the finding changes. The condition never clears itself and is harmless today, so a line every session start is wallpaper on the channel that can least afford it. The unavailable log line is gated the same way, because its commonest reason by far (not-a-repository, an external store nobody has pointed a backup at) is a standing condition rather than an event, and one identical daily line for five weeks is what #252 proved nobody reads.

/remember:doctor re-runs the check live and reports every time — that is the answer to the issue's last question. A user who suspects their memory went missing had no way to check. WARN, never FAIL, and the VERDICT line is deliberately untouched: capture is entirely unaffected by this.

Cost

Interleaved A/B against origin/main, macOS, n=25.

delta
library sourced + disk probe, isolated +2.3 ms, no fork
git ls-tree, isolated +35 ms
session-start hook, external {slug} store whose root is its own repo +34 ms median
session-start hook, legacy layout / no repository inside the hook's own noise

The one git invocation is the whole cost and there is a test capping it at one. Everything else was pushed to zero forks: not-applicable returns before either probe runs, .git's absence is a shell builtin away, the disk probe is shopt/glob, the previous record is read by the shell rather than grep | tr, and the record is rewritten only when its content changes — so the steady state costs no fork in any layout that has no git answer to fetch.

session_dir_slug and the per-tool-call path are untouched: scripts/post-tool-hook.sh, scripts/lib-slug.sh and scripts/lib-memory-dir.sh are byte-identical to origin/main, asserted here as well as by #299's test_the_per_tool_call_path_is_not_touched.

Tests

tests/test_case_divergence_298.py, 20 tests. Red 18/20 first — the two that passed against no code at all are the absence assertions (nothing is repaired, the hot path is untouched), which is what they are for.

No test needs a case-sensitive volume. One can be built on macOS with hdiutil create -fs "Case-sensitive APFS", and I did, to watch the clone actually produce two directories. A test that needed one could not run on a CI runner — so the divergence is instead built by writing a blob straight into git's index with update-index --cacheinfo, which is not a simulation: the condition being detected is a name in git's index, and that is exactly what the fixture writes. The disk half is exercised by pre-creating the store directory under the other spelling, and asserts on the finding rather than on the entry count, so it holds on a case-sensitive and a case-insensitive filesystem alike.

One bug the tests caught, worth naming because it is this file's own recurring shape: a [ -n … ] && printf as the last command of a redirected group makes a correct write look like a failed one, and the error branch then deleted a record that had been produced correctly.

Full suite: 1431 passed, 43 skipped, coverage 94.26%.

Still open on #298

Whether any real store's history carries both spellings. Nothing here assumes an answer, and this check would be worth having either way — it is what tells us how common the condition is before anyone considers writing a migration nobody currently has grounds for.

…n case (#298)

The issue as filed claimed a store created under the pre-#263 drive-letter
spelling is orphaned by the post-#263 resolver. @jqit-ricky measured it on the
only Windows box we can point at and disproved it: both spellings resolve to the
same directory object, 88 files through either name. NTFS is case-insensitive,
so two stores differing only in case is not a state it can be in. Nothing is
stranded; no migration is needed or wanted.

What survives is git. Its index is case-sensitive where NTFS is not, so a store
can be C--Users-you-proj on disk and c--Users-you-proj in the repository that
backs it up. On a case-sensitive restore — confirmed on a real case-sensitive
APFS volume, not predicted — a repository carrying both spellings clones to two
directories with two remember.md files, and the resolver reads one of them.

So: a session-start check that discloses, and only discloses. Two probes — the
store root's directory names (no fork, and the only half that can fire on
Windows) and HEAD's top-level tree (one `git ls-tree`, and HEAD rather than the
history because a clone checks out HEAD). Four answers: they agree / a second
spelling exists / could not check, with a reason / not applicable. An absence
produced by the check is never rendered as agreement.

Message on `systemMessage` only when the finding changes, and in
/remember:doctor every time. Nothing is renamed, merged or migrated; an
allowlist test fails if mv/git add/git checkout ever appear in the library.

Measured, interleaved against origin/main, macOS, n=25: +2.3ms for the library
and the disk probe with no fork, +35ms for the `git ls-tree`, +34ms median end
to end on a store whose root is its own repository. Layouts without one sit in
the hook's own noise. The per-tool-call path is byte-identical.

tests/test_case_divergence_298.py, 20 tests, red 18/20 first. Full suite 1431
passed, 43 skipped, coverage 94.26%.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 1e5065d into main Aug 3, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/298-case-divergence-disclosure branch August 3, 2026 13:40
fdaviddpt added a commit that referenced this pull request Aug 4, 2026
Manifest 0.14.0 -> 0.15.0. The updater compares manifest versions and
nothing else (#133), so this bump is what reaches anyone.

Ships #301 (prompt_stamp, external report), #302 (shell parse gate),
#293 (lock test measures overlap) and #300 (case-divergence disclosure).
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