Skip to content

fix(graph): stop leaking edges to excluded neighbors#463

Open
davion-knight wants to merge 1 commit into
vouchdev:testfrom
davion-knight:fix/graph-neighbor-edge-leak
Open

fix(graph): stop leaking edges to excluded neighbors#463
davion-knight wants to merge 1 commit into
vouchdev:testfrom
davion-knight:fix/graph-neighbor-edge-leak

Conversation

@davion-knight

Copy link
Copy Markdown
Contributor

summary

find_neighbors() appended an edge to the response before checking whether its other endpoint passed the same retrievability/existence checks that gate node inclusion (_neighbor_ok / _node_kind). superseded, archived, and redacted claims — and missing nodes — were correctly excluded from nodes, but the edge pointing at them still went out. a response could contain an edge whose target referenced a claim id the response itself said didn't exist.

kb.neighbors shares this code path across all three surfaces (mcp, jsonl, cli), so the leak was identical everywhere.

what changed

reordered the loop in src/vouch/graph.py::find_neighbors so an edge is only recorded once its other endpoint has been accepted into visited — either just now, having passed the gate, or already accepted in an earlier iteration.

test plan

extended test_find_neighbors_excludes_superseded_claims in tests/test_graph.py to also assert result["edges"] == [] — fails on the old code (returns the dangling edge to the superseded claim), passes with the fix.

.venv/bin/python -m ruff check src tests
.venv/bin/python -m mypy src
.venv/bin/python -m pytest tests/test_graph.py -q
.venv/bin/python -m pytest tests/ -q --ignore=tests/embeddings

all clean. note: the full suite has 3 pre-existing order-dependent failures (test_fsck_clean_kb_prints_clean_and_exits_zero, test_search_fts5_backend_label, test_deindex_removes_fts_and_prov) that reproduce identically on a clean test checkout with no changes — unrelated to this PR, confirmed by stashing this diff and re-running.

find_neighbors() appended an edge to the response before checking
whether its other endpoint passed the same retrievability/existence
checks gating node inclusion (_neighbor_ok / _node_kind). superseded,
archived, and redacted claims -- and missing nodes -- were correctly
excluded from `nodes`, but the edge pointing at them still went out,
so a response could contain an edge whose target referenced a claim
id the response itself said didn't exist.

kb.neighbors shares this code path across all three surfaces (mcp,
jsonl, cli), so the leak was identical everywhere. reordered the loop
so an edge is only recorded once its other endpoint has been accepted
into `visited` (either just now, having passed the gate, or already
accepted in an earlier iteration).
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 13d361dc-032d-48ce-be6d-3d61a3d6453a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added docs documentation, specs, examples, and repo guidance retrieval context, search, synthesis, and evaluation tests tests and fixtures size: XS less than 50 changed non-doc lines labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs documentation, specs, examples, and repo guidance retrieval context, search, synthesis, and evaluation size: XS less than 50 changed non-doc lines tests tests and fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant