Skip to content

fix(query): fallback BFS/DFS traversal omits relationships between visited nodes #4314

Description

@vibhanshu-mishra

Summary

Cubic identified a correctness bug in Graphify's generated query instructions.

The inline NetworkX fallback for /graphify query records graph edges only when traversal discovers a previously unvisited node.

This can omit valid relationships between already visited nodes, producing incomplete answers even when the underlying graph contains the missing edges.

Affected file

graphify/skills/codex/references/query.md

Original downstream finding: .codex/skills/graphify/references/query.md, approximately line 133.

Priority: P2

Root cause

Both BFS and DFS couple edge recording to node discovery.

In BFS, an edge is appended only when the neighboring node is absent from subgraph_nodes.

DFS similarly appends an edge only when the neighbor has not yet been visited.

However, a graph can contain multiple relationships connecting nodes already discovered during traversal.

Node visitation should control whether traversal expands a node again, not whether an existing relationship is included in the result.

Minimal example

Consider a graph with three nodes:

  • A
  • B
  • C

And three relationships:

  • A → B
  • B → C
  • A → C

If A, B, and C are already selected as starting nodes, the BFS fallback records no edges between them because each target is already discovered.

The graph contains three valid relationships, but the traversal result can contain zero.

Expected behavior

The fallback traversal should preserve all relevant relationships between included nodes, within the configured traversal depth and output budget.

Actual behavior

Relationships to previously discovered nodes may be omitted, resulting in incomplete graph context.

Suggested fix

  1. Separate edge collection from node-discovery logic.
  2. Use the visited set only to control traversal expansion.
  3. Record all relevant traversed relationships.
  4. Preserve edge direction and relationship metadata.
  5. Avoid duplicate edges.
  6. Add regression coverage for BFS, DFS, seeded nodes, cycles, and cross-links.
  7. Update the authoritative skill-generation source and regenerate the affected artifacts.

Verification

This issue was identified through static review of the generated workflow. The example above demonstrates the suspected failure mechanism; an automated regression test should confirm the behavior before implementing the fix.

I would be happy to contribute a PR addressing this issue.

Activity

  1. github-actions commented on Oct 11, 2026

    @github-actions

    Thanks for opening this issue, @vibhanshu-mishra. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. nothariharan commented on Oct 11, 2026

    @nothariharan
    Contributor

    Confirmed on the current default branch (v8). The inline fallback records an edge only when BFS/DFS discovers an unvisited neighbour, so the seeded example yields 0 edges for BFS and 2 for DFS. The CLI has had the fix since #2323 (graphify.serve._complete_induced_edges); the generated skill fallback never inherited it.

    Opened a PR that applies the same induced-edge completion to the shared reference fragment and the aider/devin monoliths, regenerates all 14 references/query.md artifacts plus the expected/ snapshots, and adds regression tests that extract and run the shipped fallback. Coverage: seeded nodes, BFS/DFS cross-links, cycles, edge direction, and parallel-edge de-duplication.

    #4316

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