Skip to content

fix(prompt): describe the node-ID class ids.py actually produces (#4432) - #4799

Closed
dupeisen wants to merge 1 commit into
Graphify-Labs:v8from
dupeisen:fix/4432-node-id-rule-non-ascii
Closed

dupeisen wants to merge 1 commit into
Graphify-Labs:v8from
dupeisen:fix/4432-node-id-rule-non-ascii

Conversation

@dupeisen

Copy link
Copy Markdown
Contributor

What this fixes

The extraction prompt tells the model:

Node ID format: lowercase, only [a-z0-9_], no dots or slashes.

But ids.normalize_id keeps every word character after casefolding, so a non-ASCII path keeps its letters:

docs/tz/ЛЗ4_обоснование.md  ->  docs_tz_лз4_обоснование
文档/中文名.md               ->  文档_中文名

Nothing satisfies both halves of that instruction. For a non-ASCII path the model improvises a stem — and per the issue, differently per chunk and per run — while _semantic_id_remap has no canonical id to remap onto. The AST node and the semantic nodes for one file then land under different ids, which is the ghost-duplicate failure mode this module exists to prevent (its own docstring lists #811, #550, #1033, #1104).

#3103 reported this and was closed without a fix. The wording is unchanged on v8, and it is in three places, not one:

  • graphify/llm.py _EXTRACTION_SYSTEM
  • tools/skillgen/fragments/references/shared/extraction-spec.md (rendered into 14 host skills)
  • tools/skillgen/fragments/references/shared/extraction-spec-compact.md

The change

All three now state the rule the code implements:

Node ID format: lowercase, word characters only (`[^\W]` after casefolding —
`[a-z0-9_]` for ASCII input, but non-ASCII letters and digits are kept as-is),
no dots or slashes.

The ASCII half is unchanged. src/auth/session.py + ValidateToken still yields src_auth_session_validatetoken, so no ASCII corpus produces different ids and no rebuild is needed. Only the false "ASCII-only" claim is gone, plus the concrete examples a model needs for the non-ASCII case.

I edited the two fragments rather than the committed skill files, per the contributing guide, then ran:

$ uv run python -m tools.skillgen --bless    # refresh tools/skillgen/expected/
$ uv run python -m tools.skillgen            # write graphify/skills/** and graphify/skill-*.md
$ uv run python -m tools.skillgen --check
check OK: 134 artifact(s) match committed output and expected/.

That is why the diff touches 32 files: 2 fragments, llm.py, 1 test, and 28 regenerated artifacts. Every regenerated file differs by that one line only — I checked the diff on graphify/skills/codex/references/extraction-spec.md and --check passing is the proof the tree is self-consistent.

Verification

New tests/test_prompt_id_rule_matches_ids.py (5 tests) pins the invariant rather than the exact wording:

  • no prompt surface claims ASCII-only ids (parametrised over llm.py and both fragments);
  • make_id keeps Cyrillic and CJK as documented;
  • normalize_id output is all word characters for those inputs;
  • ASCII input is still lowercased ASCII, and punctuation still folds to _ — the guard that this was a wording fix, not a relaxation.
$ uv run pytest tests/test_prompt_id_rule_matches_ids.py -q
5 passed

$ uv run pytest tests/test_skillgen.py tests/test_skillgen_input_path_injection.py -q
11 failed, 92 passed, 3 skipped

Those 11 failures are pre-existing on this Windows checkout: unmodified v8 gives the same 11 failed with 87 passed, so this change adds 5 passes and no failures. I did not touch them.

Limitations

Fixes #4432


Disclosure: I used an AI coding assistant for this change, as the contributing guide asks. I verified the ids.py behaviour directly, regenerated the artifacts with the project's own generator, and confirmed the new assertions fail without the fix.

The extraction prompt told the model "Node ID format: lowercase, only
`[a-z0-9_]`", but `ids.normalize_id` keeps every word character after
casefolding, so a non-ASCII path keeps its letters:

    docs/tz/ЛЗ4_обоснование.md  ->  docs_tz_лз4_обоснование
    文档/中文名.md               ->  文档_中文名

Nothing can satisfy both halves of that instruction. For a non-ASCII path the
model improvised a stem — differently per chunk and per run — and
`_semantic_id_remap` had no canonical id to remap onto, so the AST node and the
semantic nodes for one file landed under different ids. Graphify-Labs#3103 reported this and
was closed without a fix; the wording is unchanged on v8 and lives in three
places, not one.

All three now state the rule the code implements: word characters only, which
is `[a-z0-9_]` for ASCII input while non-ASCII letters and digits are kept.
The ASCII half is unchanged, so no ASCII corpus produces different ids.

The rule text is in two skillgen fragments, so the committed skill artifacts are
regenerated with `python -m tools.skillgen` rather than edited by hand, per the
contributing guide. `tools/skillgen/expected/` is refreshed with `--bless`.
`--check` reports all 134 artifacts in sync.

Tests: tests/test_prompt_id_rule_matches_ids.py (5 tests) asserts that no prompt
surface claims ASCII-only ids, that `make_id` keeps Cyrillic and CJK, and that
ASCII input is still lowercased ASCII (the rule was not relaxed). The three
"no ASCII-only claim" assertions fail on unmodified v8; the two behaviour
assertions pass both ways, since `ids.py` was already correct — only the prompt
lied about it.

Fixes Graphify-Labs#4432

Co-Authored-By: Claude <[email protected]>
@dupeisen
dupeisen requested a review from safishamsi as a code owner October 26, 2026 19:50
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @dupeisen. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

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

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Updates the node ID format instruction in the LLM extraction prompt and the shared extraction spec so it no longer claims IDs are ASCII-only. The rule now says IDs use word characters after casefolding: [a-z0-9_] for ASCII input, with non-ASCII letters and digits kept as-is. The same wording is regenerated across every per-platform skill copy (agents, amp, claude, claw, kilo, pi, trae, windows), so the in-code prompt and the skill docs stay in sync. A test now checks that the prompt's ID rule matches the IDs and no longer claims ASCII-only.

Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1139 functions depend on the 269 functions this change touches.

Health — grade B; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • deduplicate_entities() — 110 callers, 31 callees (high)
  • build_merge() — 101 callers, 16 callees (high)
  • dispatch_command() — 5 callers, 135 callees (high)
  • build() — 83 callers, 6 callees (high)
  • _call_openai_compat() — 34 callers, 12 callees (high)
  • extract_files_direct() — 19 callers, 21 callees (high)
  • _call_llm() — 18 callers, 22 callees (high)
  • extract_corpus_parallel() — 28 callers, 12 callees (high)
  • …and 2 more

Verification — 1139 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: 671 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

466 of 466 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/pi.test.ts — full-run-safety
  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_affected_overrides.py — full-run-safety
  • tests/test_affected_path_file_node.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_alias_folding.py — full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — impact, full-run-safety
  • tests/test_backend_extras.py — impact, full-run-safety
  • tests/test_backend_opt_in.py — impact, full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_benchmark_real_query.py — full-run-safety
  • tests/test_binary_media_words.py — full-run-safety
  • tests/test_blade_extractor.py — full-run-safety
  • tests/test_build.py — impact, full-run-safety
  • tests/test_build_located_semantic_identity.py — impact, full-run-safety
  • tests/test_build_merge_dedup_scope.py — impact, full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — impact, full-run-safety
  • tests/test_build_merge_shrink_guard.py — impact, full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_c_include_resolution.py — impact, full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_cache_long_paths.py — full-run-safety
  • tests/test_cache_stale_import_target.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — impact, full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — impact, full-run-safety
  • tests/test_chunking.py — impact, full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — impact, full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cloud_cta.py — full-run-safety
  • … and 416 more

non-code file(s) changed (graphify/skills/agents/references/extraction-spec.md, graphify/skills/amp/references/extraction-spec.md, graphify/skills/claude/references/extraction-spec.md, graphify/skills/claw/references/extraction-spec.md, graphify/skills/codex/references/extraction-spec.md …) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (graphify/skills/agents/references/extraction-spec.md, graphify/skills/amp/references/extraction-spec.md, graphify/skills/claude/references/extraction-spec.md, graphify/skills/claw/references/extraction-spec.md, graphify/skills/codex/references/extraction-spec.md …) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

safishamsi added a commit that referenced this pull request Nov 1, 2026
#4799's new wording put `[^\W]` in the non-raw _EXTRACTION_SYSTEM
string, which raises SyntaxWarning: invalid escape sequence '\W' (a
SyntaxError in a future Python). Escape it to `[^\\W]`; the rendered
runtime prompt is byte-identical (`[^\W]`) and the markdown fragments are
unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.100, now on PyPI (pip install graphifyy==0.9.100). The extraction prompt's node-id description matches what ids.py actually produces. Thanks for the fix, @dupeisen.

@safishamsi safishamsi closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants