Skip to content

fix(detect): NFC-normalize manifest keys for macOS --update - #2224

Closed
SyedFahad7 wants to merge 2 commits into
Graphify-Labs:v8from
SyedFahad7:fix/2221-manifest-nfc-keys
Closed

SyedFahad7 wants to merge 2 commits into
Graphify-Labs:v8from
SyedFahad7:fix/2221-manifest-nfc-keys

Conversation

@SyedFahad7

@SyedFahad7 SyedFahad7 commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2221.

On macOS, os.walk / getcwd hand back NFD paths, but a lot of callers pass NFC path literals (skill --update, etc). Manifest lookup was a raw string compare, so every file looked deleted + new and --update rebuilt the whole corpus.

Same idea as the office sidecar hash fix in #1226 — just NFC the keys at the manifest boundary (load / save / incremental compare).

Test plan

  • On macOS with a non-ASCII corpus path: run extract once, then --update with no real changes — should report 0 new / 0 deleted
  • Sanity: normal ASCII path still increments correctly after a real edit
  • uv run pytest tests/test_detect.py -q (or full suite if you prefer)

…ath forms

macOS yields NFD paths from os.walk/getcwd while skill path literals are
often NFC. Raw string compare treated every file as deleted+new and forced
a full re-extract. Canonicalize at the manifest boundary (same idea as Graphify-Labs#1226).

Fixes Graphify-Labs#2221
Copilot AI review requested due to automatic review settings July 26, 2026 21:57

Copilot AI 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.

Pull request overview

This PR fixes macOS incremental update behavior by NFC-normalizing manifest keys at the manifest boundary, so scans that yield NFD paths (e.g., via os.walk() / getcwd()) still match prior manifests written with NFC path literals (Issue #2221).

Changes:

  • Added _nfc() helper and applied NFC normalization when loading and saving manifest keys.
  • Updated incremental comparison (detect_incremental) to normalize scanned file paths before manifest lookups and deletion checks.
  • Hardened save_manifest() pruning/clear-semantic membership checks to tolerate NFC/NFD mismatches in the provided path sets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread graphify/detect.py
Comment on lines +1708 to +1712
# NFC after relativize so on-disk keys match what load_manifest
# re-anchors and compares against (#2221).
manifest = {_nfc(_to_relative_for_storage(k, root)): v for k, v in manifest.items()}
else:
manifest = {_nfc(k): v for k, v in manifest.items()}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch — pushed a follow-up. _to_relative_for_storage now NFC's both the key and Path(root).resolve() before relpath, and the absolute re-anchor join NFC's the result too. should keep the #777 relative keys intact on macOS non-ASCII roots.

Comment thread graphify/detect.py
Comment on lines +1463 to +1467
def _nfc(s: str) -> str:
"""NFC-normalize a path string used as a manifest key.

On macOS, ``os.walk`` / ``getcwd`` yield NFD paths while path literals
and many skill-substituted roots are NFC. Raw string compare then treats

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fair point. kept this PR to the detect.py fix only for now — happy to add a regression test in a follow-up if maintainers want it in-tree.

Stamped keys can already be NFC while Path(root).resolve() is NFD, so
os.path.relpath treated in-root files as ../ and kept them absolute.
Normalize both operands inside _to_relative_for_storage (and the join in
_to_absolute_from_storage).
safishamsi added a commit that referenced this pull request Jul 27, 2026
Adds the regression test PR #2224 shipped without: an NFD-keyed manifest
(portable and legacy-absolute) must match an NFC scan so --update is a
no-op instead of re-extracting everything.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Thanks @SyedFahad7. Shipped in v0.9.28 (cherry-picked to v8), with the NFC regression test added as a follow-up. Closed-unmerged here, but it's in the release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.28

@safishamsi safishamsi closed this Jul 27, 2026
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…phify-Labs#2221)

Adds the regression test PR Graphify-Labs#2224 shipped without: an NFD-keyed manifest
(portable and legacy-absolute) must match an NFC scan so --update is a
no-op instead of re-extracting everything.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

macOS: --update re-extracts everything when corpus path has non-ASCII chars (NFC/NFD manifest mismatch)

3 participants