Skip to content

feat(benchmark): --questions reports whether query_graph shows the right file - #4342

Open
rohit-jsfreaky wants to merge 2 commits into
Graphify-Labs:v8from
rohit-jsfreaky:feat/benchmark-answer-quality
Open

rohit-jsfreaky wants to merge 2 commits into
Graphify-Labs:v8from
rohit-jsfreaky:feat/benchmark-answer-quality

Conversation

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #4341.

graphify benchmark measured token reduction only. graphify benchmark [graph.json] --questions FILE now measures answer quality:

  • load_benchmark_questions reads a JSON list or JSON Lines of {"question": "...", "files": ["pkg/module.py"]} (paths normalized; an item without a question or files is an error naming it).
  • run_answer_benchmark loads the graph with serve._load_graph and asks _query_graph_text each question with the MCP tool's defaults (BFS, depth 3, ~2000 tokens; --depth / --budget override). It reads the files of the NODE lines in the order the answer shows them, and records the position of the first expected file, the answer size (~3 chars/token, the budget's own rule) and whether query_graph printed its "Complete answer over budget" notice.
  • The report: expected file shown first / in the first 3 / first 5 / anywhere, median answer size, answers kept past the budget, and the questions with no expected file. --json prints the per-question results.
  • Without --questions, graphify benchmark is unchanged (token reduction). Unknown options now error instead of being taken as the graph path.
  • docs/how-it-works.md gets an "Answer-quality benchmark" section; graphify --help lists the flags.

Type of change

  • New feature

Verification & Invariants

Invariant: the report describes what query_graph shows an agent for each question, nothing re-implemented.

Checked against an independent harness over the same 177 SWE-bench Lite questions (title as question, files of the real fix as answer): identical counts, e.g. django 31 / 39 / 40 / 60 of 114 (first / first 3 / first 5 / anywhere), pytest 5 / 7 / 7 / 15 of 17.

$ graphify benchmark src/django/graphify-out/graph.json --questions django.jsonl
graphify answer benchmark
──────────────────────────────────────────────────
  Graph:           45,984 nodes, 107,138 edges
  Questions:       114 (query_graph, BFS depth 3, ~2000-token budget)
  Expected file shown first:      31/114 (27%)
  Expected file in first 3 files: 39/114 (34%)
  Expected file in first 5 files: 40/114 (35%)
  Expected file anywhere:         60/114 (53%)
  Answer size:     median ~2,175 tokens; 1 kept past the budget (query_graph's "complete answer over budget")
  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test: tests/test_benchmark_answers.py, 11 tests (question loading and validation, files read in shown order, rank and hit counts on a small graph, the CLI's --json, bad input and the unchanged token mode).
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Limitations: scores BFS query_graph only (not explain, get_neighbors or DFS); a file counts when any node from it is shown; questions files are brought by the user (no dataset is shipped).

How was this tested?

python -m pytest tests/test_benchmark_answers.py tests/test_benchmark.py tests/test_benchmark_raw_graph.py -q   # 31 passed
python -m pytest tests -q                                # 3 failed, 7154 passed, 33 skipped; clean 0.9.85 on this machine: the same 3 failed, 7143 passed (test_3357_minimal_reproduction_no_config_emits_calls_edge and the two test_absolute_path_lookup_skips_getcwd), 0 new
python -m ruff check graphify tests/test_benchmark_answers.py   # All checks passed
pyright graphify/benchmark.py graphify/cli.py graphify/__main__.py tests/test_benchmark_answers.py   # 3 errors, same 3 as 0.9.85, 0 new

Graphify-specific checklist

  • I updated generated skill artifacts — not needed, no skill fragments touched.
  • I confirmed that AST/structural extraction remains deterministic.
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed that no API keys or local-only graph data are included.
  • I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 11, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @rohit-jsfreaky. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (1 sampled, not proven, 1 not verified).

Formal verification. PR-changed functions: 1/2 verified (0 proven, 1 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).

Not verified on this run: dispatch\_command (vacuous: never exercised).


Graphify review — findings

Adds an answer-quality mode to graphify benchmark: with --questions FILE (a JSON list or JSON Lines of {"question", "files"}), it runs query_graph on each question the way the MCP tool does (BFS, depth 3, ~2000-token budget) and reports how often an expected file appears among the first 1, 3 and 5 files shown, or anywhere. It also reports median answer size and how many answers query_graph kept past its budget. --depth, --budget and --json tune the query and emit raw per-question results; without --questions the command still runs the token-reduction benchmark, but now exits with an error on unknown options or non-integer depth/budget values.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 444 functions depend on the 132 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: dispatch_command() — 2 callers, 133 callees
  • new: run_answer_benchmark() — 4 callers, 5 callees

Verification — 444 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 444 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

368 of 368 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — impact, full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_benchmark.py — impact, full-run-safety
  • tests/test_benchmark_answers.py — impact, changed-test, full-run-safety
  • tests/test_benchmark_raw_graph.py — impact, full-run-safety
  • tests/test_blade_extractor.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_located_semantic_identity.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_cache_stale_import_target.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — full-run-safety
  • tests/test_chunking.py — full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cloud_cta.py — impact, full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_cluster_ambiguous_scale.py — full-run-safety
  • tests/test_cluster_exclude_hubs.py — full-run-safety
  • tests/test_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — impact, full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • … and 318 more

non-code file(s) changed (docs/how-it-works.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (docs/how-it-works.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

…and 10 more.

Formal verification

No difference found (not proven): No behavior difference found in \_run\_cli (not a proof).

The verifier ran both versions of \_run\_cli on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/benchmark.py
return files


def run_answer_benchmark(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — run_answer_benchmark()

high coupling complexity (Ca·Ce = 20).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@rohit-jsfreaky

Copy link
Copy Markdown
Contributor Author

Health regression: run_answer_benchmark() high coupling complexity

Addressed in 48fc3fd: per-question scoring moved to _score_answer(question, expected, text), so run_answer_benchmark only loads the graph, asks each question and sums the rows. No behavior change: the 31 benchmark tests pass and the 177-question set gives the same counts (django 31 / 39 / 40 / 60 of 114, pytest 5 / 7 / 7 / 15 of 17).

@Graphify-Labs please re-review.

@rohit-jsfreaky
rohit-jsfreaky force-pushed the feat/benchmark-answer-quality branch from 48fc3fd to 954df3f Compare October 15, 2026 16:53

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: graphify benchmark measures answer size but never whether the answer is right

1 participant