Skip to content

explain/_find_node cannot resolve node IDs containing punctuation or non-ASCII text (concept:*, merge-graphs ::, Hangul) #2467

Closed

Description

@sean-soomgo

Summary

_find_node (and therefore graphify explain) cannot resolve any node ID that contains punctuation. In our graph this silently disabled lookup for 2,327 of 2,327 concept/overlay nodes (concept:domain:*, concept:class:*, entity:*, commit:*), while IDs without punctuation resolved 400/400.

The docstring states the intent clearly, so this looks like an oversight rather than a design decision:

Return node IDs whose label or ID matches the search term (diacritic-insensitive).
[...] Node-ID exact matches are grouped with label exact matches.

find_node_ambiguity's user-facing hint also assumes ID lookup works:

Retry with the repo-relative path or the full node id.

Version: graphifyy 0.9.32

Reproduction

import networkx as nx
from graphify.serve import _find_node

G = nx.DiGraph()
G.add_node("concept:domain:gosu", label="Gosu")   # id contains ':'
G.add_node("plain_node_id", label="Plain")        # id has no punctuation

print("colon id  ->", _find_node(G, "concept:domain:gosu"))
print("plain id  ->", _find_node(G, "plain_node_id"))
print("by label  ->", _find_node(G, "Gosu"))

Actual:

colon id  -> []
plain id  -> ['plain_node_id']
by label  -> ['concept:domain:gosu']

Expected: the first line resolves to ['concept:domain:gosu'].

Same through the CLI:

$ graphify explain "concept:domain:gosu"
No node matching 'concept:domain:gosu' found.     # node exists in the graph

Root cause

In graphify/serve.py, _find_node_tiers builds two normalizations of the query:

term       = " ".join(_search_tokens(label))          # \w+ tokens -> punctuation becomes a space
norm_query = _strip_diacritics(str(label)).lower().strip()   # punctuation preserved

The exact-match tier compares the node ID against term only:

elif (
    term == norm_label or term == bare_label or term == label_tokens or term == nid_lower
    or norm_query == norm_label or norm_query == bare_label
):

For concept:domain:gosu:

value
term concept domain gosu
norm_query concept:domain:gosu
nid_lower concept:domain:gosu

term == nid_lower is always False once the ID contains punctuation. norm_query — which already holds the correct form and is even part of the trigram prefilter (_trigram_candidates(G, [term, norm_query])) — is never compared against nid_lower.

norm_query appears to have been introduced for punctuated labels (the comment references #1704); it just wasn't extended to node IDs.

Suggested fix

One additional clause in the exact tier:

elif (
    term == norm_label or term == bare_label or term == label_tokens or term == nid_lower
    or norm_query == norm_label or norm_query == bare_label or norm_query == nid_lower
):

Why this is worse than a plain lookup failure

The natural workaround — calling explain with the node's label instead of its ID — resolves to the wrong node silently. Across our 35 concept nodes, only 4 resolved correctly; 31 landed on a same-named code node:

query resolves to intended
Repository data_repository_feedrepository_ts concept:class:Repository
API api_apitypehelper_ts concept:class:API
Gosu entity:Gosu concept:domain:gosu

So users get a plausible-looking wrong answer rather than an error, which is hard to notice in downstream reasoning.

Activity

  1. sean-soomgo commented on Aug 5, 2026

    @sean-soomgo
    ContributorAuthor

    Follow-up: the fix I suggested in the issue body is incomplete, and there is a second class of unresolvable IDs with the same root cause.

    Non-ASCII IDs are also affected, without any punctuation

    _strip_diacritics NFD-decomposes the query, but the node ID is compared in its raw form. For any ID containing Hangul (and presumably any NFD-decomposable script), the two sides can never be equal:

    nid = "artifact:story:공통"
    _strip_diacritics(nid).lower()   # '...공통' as NFD  -> ends U+1169 U+11BC
    nid.lower()                      # '...공통' as NFC  -> ends U+ACF5 U+D1B5

    They print identically but differ byte-wise.

    Measured on our graph (14.9k code nodes, Korean source filenames are common):

    ID class count resolves today
    contains : 2,327 0
    contains Hangul, no punctuation 353 0
    ASCII, no punctuation 300 (sample) 300

    So my original repro understated the scope — I first sampled only ASCII IDs and reported 400/400 passing.

    Revised suggestion

    Normalize both sides rather than adding norm_query == nid_lower:

    elif (
        term == norm_label or term == bare_label or term == label_tokens or term == nid_lower
        or norm_query == norm_label or norm_query == bare_label
        or norm_query == _strip_diacritics(nid).lower()      # <-- covers both classes
    ):

    Evaluated over the same graph, replicating the exact-tier predicate:

    ID class current norm_query == nid_lower norm_query == _strip_diacritics(nid).lower()
    contains : (2,327) 0 2,326 2,327
    Hangul, no punctuation (353) 0 0 353
    ASCII, no punctuation (300) 300 300 300

    No regression: 400 label-based queries returned identical results before and after.

    (The single colon ID the narrower fix misses is artifact:story:공통 — it is in both classes.)

    User-visible consequence

    find_node_ambiguity tells users to disambiguate with the full node ID:

    Retry with the repo-relative path or the full node id.

    For a repo with non-ASCII filenames that retry cannot succeed — explain "<label>" returns Ambiguous, and every ID it prints as the remedy fails to resolve.

  2. sean-soomgo commented on Aug 5, 2026

    @sean-soomgo
    ContributorAuthor

    Correction to my previous comment — the non-ASCII part of that table is wrong.

    I measured the strengthened clause by replicating the exact-tier predicate over every node. That skipped _trigram_candidates, which runs before the predicate. After actually applying the change to my local install and re-testing through _find_node:

    ID class before after norm_query == _strip_diacritics(nid).lower()
    contains : (300 sample) 0 299
    contains Hangul (300 sample) 0 0 ← my earlier comment claimed 353/353

    So the predicate change fixes the punctuation class, and does not fix the non-ASCII class. Sorry for the noise.

    Why non-ASCII IDs fail earlier in the pipeline

    _find_node_tiers prefilters with _trigram_candidates(G, [term, norm_query]). For a Hangul node ID the candidate set comes back empty, so the node is never scored by any predicate:

    nid  = "artifact:story:공통"          # present in the graph
    term = " ".join(_search_tokens(nid))
    nq   = _strip_diacritics(nid).lower().strip()
    
    _trigram_candidates(G, [term, nq])    # -> []  (0 candidates)

    The cause looks like a normalization mismatch between index build and query. The postings table holds both forms:

    idx = _get_trigram_index(G)["postings"]
    [g for g in idx if re.search(r"[가-힣]", g)][:3]   # ['_것이', '_없으', '시_선']   NFC
    [g for g in idx if re.search(r"[ᄀ-ᇿ]", g)][:3]   # ['ᅥ_ᄇ', 'ᅥᆹᄋ', 'ᅵ_ᄉ']      NFD jamo

    17 of the query's 19 trigrams exist in the index individually, but the per-trigram postings intersect to the empty set — consistent with the node's own text having been indexed under one normalization while the query is trigrammed under the other (_strip_diacritics NFD-decomposes, so norm_query is NFD; term goes through the same path).

    Suggested split

    These look like two independent defects with one shared theme (query and stored text normalized asymmetrically):

    1. Punctuation in node IDs — predicate only. The clause in my previous comment fixes it; measured 299/300 on a real graph, no regression across 400 label queries.
    2. Non-ASCII in node IDs — prefilter. Needs the trigram index and the needles to agree on a normalization form (e.g. normalize both to NFC before trigramming, or apply _strip_diacritics consistently on both sides at index build time).

    Happy to test a candidate patch for (2) against a graph with ~350 Hangul-named nodes if that helps.

  3. sean-soomgo commented on Aug 5, 2026

    @sean-soomgo
    ContributorAuthor

    Found the prefilter half. Both classes are now fixed locally; measurements below.

    Root cause of the non-ASCII class

    _node_search_text indexes the node ID raw, while every query path folds through _strip_diacritics (which NFD-decomposes):

    # serve.py
    return "\x00".join((norm_label, label_tokens, str(nid).lower(), source, source_tokens))
    #                                             ^^^^^^^^^^^^^^^^ NFC, but queries arrive NFD

    So for a Hangul node ID the query's trigrams never match the indexed ones and _trigram_candidates returns an empty candidate list — the node is dropped before any predicate runs.

    This is why the two classes need different fixes, and why the non-ASCII class needs both: the full-scan path is gated by the predicate, the index path by the prefilter.

    Suggested fix (prefilter)

    Index the folded form alongside the raw one:

    return "\x00".join((
        norm_label, label_tokens,
        str(nid).lower(), _strip_diacritics(str(nid)).lower(),
        source, source_tokens,
    ))

    Additive only — candidates stay a superset and the exact predicates still decide, so no new false positives. _trigrams builds a set over the whole concatenated text, so ASCII IDs (where both forms are equal) add no duplicate postings.

    Measurements

    Applied to a real graph (14.9k code nodes, Korean source filenames common), full population, not a sample:

    ID class total unpatched predicate only predicate + prefilter
    contains : 2,327 0 2,326 2,327
    contains Hangul 353 0 0 353
    ASCII, no punctuation 300 (sample) 300 300 300

    Regression check: 600 label-based queries compared before/after in the same process — all 600 identical. (My earlier comment compared hash() across two processes, which is salted per process and therefore meaningless; that was my error, not a real difference.)

    End-to-end through the CLI:

    $ graphify explain "artifact:story:공통"
    Node: 공통 story
      ID:        artifact:story:공통
    

    One gotcha for whoever writes the regression test

    A synthetic graph that is too small will pass even when the bug is present: _trigram_candidates's guard (min(present) > int(n * 0.10)) bails out to a full scan, which the predicate fix alone can satisfy. I first wrote a 2-node probe and it reported success while the real graph still returned 0/300. A test for the non-ASCII class needs enough nodes (~10+) to actually exercise the index path.

  4. xg-gh-25 commented on Aug 5, 2026

    @xg-gh-25

    The root cause is colon-splitting during node ID resolution — concept:domain:x gets parsed as ["concept", "domain", "x"] instead of being treated as an opaque identifier.

    Why this breaks:

    # Current (broken)
    node_id = "concept:domain:x"
    parts = node_id.split(":")  # → ["concept", "domain", "x"]
    lookup_key = parts[0]       # → "concept" (wrong namespace)
    
    # Expected
    lookup_key = node_id        # → "concept:domain:x" (full ID)

    The fix: Node IDs should be content-addressed, not parsed. Colons are valid in URIs (urn:isbn:, did:key:), and graphify's ID scheme shouldn't restrict that.

    Recommended approach:

    1. Short-term: Escape colons in node IDs during indexing: concept\:domain\:x
    2. Long-term: Use a different delimiter for internal partitioning (e.g., | or #), or store IDs as opaque strings with a separate namespace field

    Domain-Driven Design lens: This is a bounded context leak. The ID format (colons as structure) is bleeding into the ID semantics (should be opaque). The explain/ API shouldn't care how IDs are constructed — it should just look them up.

    Test case to add:

    assert explain._find_node("concept:domain:x") == expected_node
    assert explain._find_node("urn:isbn:978-3-16-148410-0") == expected_node

    SwarmAI contribution from Domain-Driven Design. Built with the SwarmAI framework.

  5. thomasrengot-hub commented on Aug 8, 2026

    @thomasrengot-hub

    Another affected class, in case it helps size the fix: every graph produced by
    merge-graphs is 100% unresolvable by ID
    , not just concept/overlay nodes.

    merge-graphs namespaces node IDs with a <source>:: prefix, so the separator is
    present on every node — plain code nodes included. On the merged graph of my two
    repos, 21596 / 21596 nodes contain :::

    $ graphify explain "android::app_src_main_kotlin_com_lisa_app_ui_lisanavgraph_lisanavgraph"
    No node matching 'android::...' found.
    
    $ graphify explain "LisaNavGraph"        # same node, by label
    Node: LisaNavGraph()
      ID:        android::app_src_main_kotlin_com_lisa_app_ui_lisanavgraph_lisanavgraph
      Degree:    79
    

    So on a merged graph the ID printed by explain itself cannot be fed back into
    explain, and find_node_ambiguity's hint ("Retry with [...] the full node id")
    is advice that cannot work — which is how I ran into it: I copied the ID out of
    one command's output into the next.

    Label lookup is the only route left, and that is exactly what namespacing exists
    to disambiguate — the same short label often exists in both merged repos
    (SynthesesScreen, CortexScreen, and so on appear in my Kotlin app and in the
    TypeScript PWA).

    Nothing to add on the root cause — your norm_query == nid_lower analysis covers
    this case as-is. Just noting that the blast radius is larger than concept/overlay
    nodes: for anyone using merge-graphs, ID lookup is not degraded, it is entirely
    unavailable.

    Version: graphifyy 0.9.36.

  6. sean-soomgo commented on Aug 10, 2026

    @sean-soomgo
    ContributorAuthor

    @xg-gh-25 I don't think this matches the code, flagging it so the diagnosis in this thread stays consistent.

    There is no colon splitting in the resolution path. In graphify/serve.py (v0.9.38, 2290 lines) split(":"), partition(":") and rsplit(":") each appear 0 times. The parts = node_id.split(":") / lookup_key = parts[0] snippet quoted as "Current (broken)" is not in the repository. The package does split on :: elsewhere — build.py:1880 records a local_id when merge-graphs prefixes ids, and the Rust/Ruby/C++ extractors parse :: namespaces — but none of that touches _find_node.

    The repro in the issue body already rules it out. _find_node(G, "Gosu") returns ['concept:domain:gosu'] — the full punctuated ID comes back intact. If the ID were being decomposed and looked up under a concept namespace, a label query could not return it whole.

    IDs are already opaque here. What differs between the two sides of the comparison is normalization, not structure: the query is folded (_search_tokens turns punctuation into spaces for term; _strip_diacritics NFD-decomposes for norm_query) while the node ID is compared raw. That is the two-part root cause in #2467 (comment) — the exact-tier predicate for the punctuation class, the trigram prefilter for the non-ASCII class.

    On the suggested remedies: escaping colons at index time adds a third normalization form that has to stay in sync with the query rather than removing the mismatch, and changing the internal delimiter would break every existing graph as well as merge-graphs' <source>:: prefix, while leaving the failing comparison untouched. Neither reaches the line that actually fails.

    One small thing on the test case: the function is graphify.serve._find_node(G, label), so explain._find_node("concept:domain:x") would not run as written.

    For what it is worth I have put the actual fix up as #2583, with regression tests for both classes and a full-population before/after sweep.

  7. changed the title [-]explain/_find_node cannot resolve node IDs containing punctuation (e.g. concept:domain:x)[/-] [+]explain/_find_node cannot resolve node IDs containing punctuation or non-ASCII text (concept:*, merge-graphs ::, Hangul)[/+] on Aug 10, 2026
  8. safishamsi commented on Aug 11, 2026

    @safishamsi
    Member

    Fixed in v0.9.40 (graphifyy==0.9.40 on PyPI). explain/_find_node (and the MCP serve equivalent) now resolve node ids containing punctuation or non-ASCII characters, without collapsing distinct ids. Thanks @sean-soomgo (PR #2583).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions