[Bug]: graphify query prints a different answer on each run (BFS walks a set in hash order)

Open Beginner friendly
#5,109 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@rohit-jsfreaky is already working on this.

Since Nov 9, 2026.

  • #5112 by @rohit-jsfreaky — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
search

Research direction

Read _bfs in graphify/serve.py and trace how its traversal order affects graphify query output and the token budget. Reproduce with the issue’s PYTHONHASHSEED loop, then check the same query across seeds; done when the output and retained edges are stable across runs. No test file is named in the issue.

Written by the indexing model from the issue text.

Description

Pre-flight checks
  • I have checked the Troubleshooting section in the README
What happened?

graphify query prints a different answer on every run, on the same graph. _bfs in graphify/serve.py walks each level as a set of node ids (frontier = set(start_nodes), for n in frontier:), so the EDGE lines come out in string-hash order, which Python randomizes per process. query is not in _HASHSEED_PINNED_COMMANDS, and the MCP server runs the same traversal in a long-running process, so nothing pins it. The order also decides which edges survive the token budget.

Distinct outputs over 10 runs (PYTHONHASHSEED 1 to 10):

repo query budget distinct outputs
flask how does url_for work 50k 10
click how does echo work 50k 10
django how does slugify work default 10
django how does the queryset build sql 50k 10

On a FastAPI template repo, graphify query 'how does cn() work' run 6 times gave 5 different outputs.

Steps to reproduce
cd flask && graphify update .
for s in 1 2 3; do PYTHONHASHSEED=$s graphify query "how does url_for work" --budget 50000 | md5sum; done

Three different hashes.

Error output or graph output

Example, first 3 contains EDGE lines on a tiny graph (one seed, 60 neighbours), seeds 1 / 2 / 3:

helper_7, helper_17, helper_6 | helper_1, helper_13, helper_17 | helper_18, helper_17, helper_8
Graphify version

0.9.105 (v8 at 5eedffa8)

Operating System

Windows (also seen on Linux)

Python Version

3.12

Installation Method

uv tool install (recommended)

Additional context

_dfs uses a list stack and is already stable. Related but different: #2817 and #1667 (cluster order), #3743 (hash seed pinned for other commands).

Dominant language
Python
Stars
124k
Forks
11.9k
Avg merge
2h 35m
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Graphify-Labs/graphify

All issues in Graphify-Labs/graphify

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.