Skip to content

Fix: validate_extraction crashes on non-hashable node id / edge endpoint - #1447

Closed
dschwartzi wants to merge 1 commit into
Graphify-Labs:v8from
dschwartzi:fix/validate-non-hashable-id
Closed

dschwartzi wants to merge 1 commit into
Graphify-Labs:v8from
dschwartzi:fix/validate-non-hashable-id

Conversation

@dschwartzi

Copy link
Copy Markdown
Contributor

Problem

validate_extraction() is documented to return a list of error strings ("empty list means valid"), but it raises TypeError: unhashable type: 'list' when a node id — or an edge source/target — is a non-hashable value such as a list. This happens in practice when an LLM extraction subagent emits malformed JSON like {"id": ["foo", "bar"], ...}.

Two crash sites:

  • node_ids = {n["id"] for ...} — the set comprehension over node ids.
  • edge["source"] not in node_ids / edge["target"] not in node_ids — the set-membership tests.

Because build_from_json() calls validate_extraction() at its start, the whole build aborts before any graph is produced — a single malformed node from a semantic pass kills an otherwise-complete extraction of a large corpus. build_from_json() itself would also raise (G.add_node(<list>), and the not in node_set membership test) even if the validator were bypassed.

Fix

  • validate.py: collect node_ids during the node pass, adding only hashable ids; report a non-hashable id/endpoint as an error string instead of crashing. All existing error messages and the dangling-edge checks are preserved.
  • build.py: in build_from_json, skip dict nodes with a missing/non-hashable id and edges with non-hashable endpoints (with a stderr warning), so a malformed entry is dropped rather than aborting the build. Non-dict nodes are deliberately left to raise as before, so multigraph_diagnostics still observes shape errors.

Tests

  • 3 new tests/test_validate.py cases: non-hashable node id reported, non-hashable edge endpoint reported, and valid ids still collected (dangling edge still flagged) when a sibling id is bad.
  • 2 new tests/test_build.py cases: build skips non-hashable/missing node ids and non-hashable edge endpoints while keeping well-formed entries.

Full suite locally (pytest tests/): 2331 passed, with the only 2 failures (test_ollama::test_detect_backend_ollama, test_detect_backend_none_without_envvars) being pre-existing and environmental — they fail identically on a pristine checkout because backend auto-detect resolves to an installed paid-API package. This change adds 5 passing tests and introduces 0 new failures. ruff check is clean on the changed files.

validate_extraction() is documented to return a list of error strings ("empty
list means valid"), but raised TypeError: unhashable type: 'list' when a node
id -- or an edge source/target -- was a non-hashable value such as a list. This
occurs in practice when an LLM extraction subagent emits malformed JSON like
{"id": ["foo", "bar"], ...}. Crash sites: the node_ids set comprehension and
the `edge[...] not in node_ids` membership tests.

Because build_from_json() validates at its start, a single malformed node
aborted the entire build, losing an otherwise-complete extraction of a large
corpus. build_from_json() itself would also raise (G.add_node(<list>) and the
`not in node_set` test) if the validator were bypassed.

- validate.py: build node_ids during the node pass, adding only hashable ids;
  report a non-hashable id/endpoint as an error string instead of crashing.
  All existing messages and the dangling-edge checks are preserved.
- build.py: skip dict nodes with a missing/non-hashable id and edges with
  non-hashable endpoints (stderr warning). Non-dict nodes are deliberately
  left to raise so the multigraph diagnostic still observes shape errors.
- tests: 3 cases in test_validate.py and 2 in test_build.py.
@safishamsi

Copy link
Copy Markdown
Member

Merged into v8 via cherry-pick (commit 2c7cbb6, authorship preserved). Verified locally: full suite 2333 passed, 0 failures. Clean defensive fix — thanks for catching that a single malformed node would abort the whole build, and for leaving non-dict nodes to raise so the multigraph diagnostic still sees shape errors. 🙏

@safishamsi safishamsi closed this Jun 24, 2026
safishamsi added a commit that referenced this pull request Jun 24, 2026
The #1447 cherry-pick only touched build.py/validate.py + tests, so it
shipped without a CHANGELOG note. Add it under Unreleased.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
safishamsi added a commit that referenced this pull request Jun 24, 2026
Work-memory (#1441): save-result --outcome + graphify reflect, with recency-decayed
scoring, corroboration threshold, label-matched node-existence gate, contested
handling, and zero-config adoption (skill reads LESSONS.md + records outcomes; git
hooks auto-reflect). Fixes: Python ClassName.method() qualified-call edges (#1446);
validate_extraction/build crash on non-hashable id (#1447); graphify update now
prunes a symbol removed from a surviving file without --force.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
…nt crash fix)

The Graphify-Labs#1447 cherry-pick only touched build.py/validate.py + tests, so it
shipped without a CHANGELOG note. Add it under Unreleased.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
PerryLin-0420 pushed a commit to PerryLin-0420/graphify-decouple that referenced this pull request Aug 13, 2026
Work-memory (Graphify-Labs#1441): save-result --outcome + graphify reflect, with recency-decayed
scoring, corroboration threshold, label-matched node-existence gate, contested
handling, and zero-config adoption (skill reads LESSONS.md + records outcomes; git
hooks auto-reflect). Fixes: Python ClassName.method() qualified-call edges (Graphify-Labs#1446);
validate_extraction/build crash on non-hashable id (Graphify-Labs#1447); graphify update now
prunes a symbol removed from a surviving file without --force.

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.

2 participants