Repository navigation
fix(ids): casefold before the non-word filter so normalize_id is idempotent - #2616
rajarshidattapy wants to merge 2 commits into
Conversation
…djusting casefolding order
…s and update related test cases
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. 1 change(s) tested, no difference found (not proven).
Graphify review — findings
This pull request reverts the changelog entries for version 0.9.39, moving 0.9.38 back to "unreleased" status. It removes the fuzzy dedup content-word/stopword comparison helpers (_content_token_swap, _same_word_variant, _STOPWORDS) and their call sites in deduplicate_entities and _llm_tiebreak, along with the file-source-based dedupe logic in the JS dynamic import rescue path. The changes appear to roll back several features/fixes that had been slated for the 0.9.39 release, touching dedup, extract, and watch modules plus their corresponding tests.
No blocking issues surfaced.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3268 functions depend on the 1518 functions this change touches.
Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):
extract()— 400 callers, 39 callees (high)_rebuild_code()— 93 callers, 51 callees (high)build_from_json()— 151 callers, 17 callees (high)deduplicate_entities()— 53 callers, 19 callees (high)build_merge()— 41 callers, 14 callees (high)save_semantic_cache()— 50 callers, 9 callees (high)_extract_generic()— 18 callers, 22 callees (high)extract_bash()— 34 callers, 10 callees (high)- …and 2 more
Verification — 3268 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 2952 function(s) in the blast radius were not formally verified this run
Formal verification
Could not verify: Could not verify \_llm\_tiebreak.
The verifier did not have enough to check \_llm\_tiebreak, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: not verifiable: all 105 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify deduplicate\_entities.
The verifier did not have enough to check deduplicate\_entities, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: not verifiable: all 7 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_rescue\_js\_dynamic\_imports.
The verifier did not have enough to check \_rescue\_js\_dynamic\_imports, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
Could not verify: Could not verify \_resolve\_objc\_member\_calls.
The verifier did not have enough to check \_resolve\_objc\_member\_calls, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous
Could not verify: Could not verify \_extract\_generic.
The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
Could not verify: Could not verify extract\_objc.
The verifier did not have enough to check extract\_objc, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
Could not verify: Could not verify \_merge\_decl\_def\_classes.
The verifier did not have enough to check \_merge\_decl\_def\_classes, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: not verifiable: the input domain has 49 values but only 7 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)
No difference found (not proven): No behavior difference found in normalize\_id (not a proof).
The verifier ran both versions of normalize\_id on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
Could not verify: Could not verify watch.
The verifier did not have enough to check watch, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `watch_path` is annotated `Path` — outside the synthesizable primitive/collection set
|
Shipped in v0.9.40 ( |
Fixes #2614.
Problem
normalize_id()casefolded after the[^\w]+filter:Casefolding can expand a character into a base letter plus a combining mark:
"İ".casefold()is"i" + U+0307. With the filter already spent, that marksurvived into the id — so
normalize_idbroke both of its contracts:İstanbul→i̇stanbul→i_stanbul.\wcharacters, thoughcache.pydocuments that "normalize_id drops everynon-word character".
Turkish identifiers (
İslemYap,İçerik) hit this on every run, and U+0307 is invisible inmost terminals, so the resulting ids look correct.
The concrete damage is the ghost-node class
ids.pywas created to prevent.build.pyre-normalizes ids that
make_id()already produced, and atbuild.py:1057compares_normalize_id(nid).startswith(new_stem)wherenew_stemcomes frommake_id()and is notre-normalized. For a Turkish symbol the two sides disagreed (
i_slemyapvsi̇slemyap), so_semantic_id_remap's re-key silently no-opped.Fix
Move casefold ahead of the filter, and NFKC again to recompose what it expanded:
Blast radius (measured, not assumed)
Scanned all 1.1M codepoints, and diffed ids across the 369-file graphify tree:
\wThe 29 affected codepoints are U+0130, Greek ypogegrammeni, and precomposed
Latin/Greek letters whose casefold expands. For those, the new output is the composed
NFKC form — which is what the module docstring already specified.
No migration needed — and I verified rather than assumed
The issue expected this to need #1504/#1917-style legacy-form handling. It does not, because
the new output is exactly the old recipe's fixed point:
normalize_id(old_id) == new_id.build.py:1008keys its reconciliation map on_normalize_id(nid), so old-form and new-formids already collapse to the same key.
Tested end to end rather than argued: built a Turkish corpus with the unfixed code
(
islem_i̇slemyap), applied the fix, added a symbol, rangraphify update:So no legacy-form code was added.
Tests
A property test for exactly this already existed and did not catch it.
test_property_normalize_id_idempotentwith@given(st.text())has been in the suite sincethe contract file was written — a uniform draw essentially never produces U+0130 out of ~1.1M
codepoints. Fixing only the implementation would leave that gap open, so this PR also
strengthens the guard:
CONTRACT_CASESCASE_EXPANDING_CHARSset covering each distinct failure shape (expansion,recomposition, combining marks,
ẞ→ss)\w-only postcondition, asserted directlyclass is covered by construction rather than by luck
New tests produce 18 failures on the unfixed code, 0 with the fix.
One assertion hypothesis rejected, worth knowing
I first asserted
normalize_id(s.upper()) == normalize_id(s.lower()). Hypothesisimmediately found
ı(U+0131 dotless i):'ı'.upper()is'I', which casefolds to'i'.str.upper()is locale-independent and lossy, so that property is false regardless of thisfix. Replaced with caseless equivalence via
casefold, which is the invariant the graphactually relies on. Noted in the test docstring so nobody "fixes" it back.
Verification
tests/test_id_normalization_contract.py: 71 passednew, +37 tests