Skip to content

fix: harden graph JSON loading against corruption#1537

Closed
guyoron1 wants to merge 1 commit into
Graphify-Labs:v8from
guyoron1:fix/harden-json-loading
Closed

fix: harden graph JSON loading against corruption#1537
guyoron1 wants to merge 1 commit into
Graphify-Labs:v8from
guyoron1:fix/harden-json-loading

Conversation

@guyoron1

Copy link
Copy Markdown
Contributor

Summary

Closes #1536

Three core graph-loading paths call json.loads() without catching JSONDecodeError or OSError. Corrupted graph.json files (from incomplete writes, power loss, or manual edits) crash with unhelpful tracebacks.

This PR wraps each site with try/except that raises a clear RuntimeError with recovery guidance.

Changes

  • graphify/build.py:652build_merge(): guards the --update incremental merge path
  • graphify/affected.py:212load_graph(): guards graphify prs graph loading
  • graphify/diagnostics.py:277_read_json_file(): guards graphify diagnose

Test plan

  • Corrupt a graph.json manually (e.g., truncate mid-file), run graphify extract --update — should get actionable error instead of traceback
  • Run graphify prs with corrupt graph — should get clear error
  • Run graphify diagnose with corrupt graph — should get clear error
  • Happy path unchanged: normal graph.json files load as before

🤖 Generated with Claude Code

Wrap unguarded json.loads() in build_merge(), load_graph(), and
_read_json_file() so corrupted graph.json files produce an actionable
RuntimeError instead of an unhelpful JSONDecodeError traceback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
safishamsi added a commit that referenced this pull request Jul 1, 2026
#1537 shipped with a manual test checklist only. Add automated tests that
corrupt a graph.json and assert the actionable RuntimeError at all three load
paths (build_merge, affected.load_graph, diagnostics._read_json_file) plus a
happy-path guard. Also record the six merged small fixes in the changelog.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@safishamsi

Copy link
Copy Markdown
Collaborator

Merged into v8 as 4a8d6ba (your authorship). One addition on my end: the PR had a manual test checklist only, so I added automated regression tests (tests/test_corrupt_graph_json.py) that corrupt a graph.json and assert the actionable RuntimeError at all three paths plus a happy-path guard. Composes cleanly with the recent build_merge hyperedge/prune work. Full suite 2767 passed. Ships next release.

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.

fix: harden graph JSON loading against corruption in build, affected, diagnostics

2 participants