Skip to content

fix(query): five defects that returned wrong answers without erroring - #1577

Merged
Shashankss1205 merged 1 commit into
mainfrom
fix/query-correctness-batch
Aug 5, 2026
Merged

Shashankss1205 merged 1 commit into
mainfrom
fix/query-correctness-batch

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #1529, #1530, #1531, #1558, and items 1–2 of #1533.

Full suite: 1101 passed, 19 skipped, no failures.

These are grouped because they share a failure mode: each returned a plausible-looking wrong answer instead of an error, which is the class an agent cannot detect and will act on.

# Defect Effect
#1529 per-repo counters counted CONTAINS paths, not nodes 2202 functions reported where 1551 exist — and the same tool's global branch said 1551
#1530 find_callers hoisted row 0's target_file_path and stripped the rest every caller attributed to whichever definition sorted first
#1531 graph_name not forwarded to find_dead_code / find_most_complex_functions results returned from the wrong repository on FalkorDB
#1533 ①② count(*) after OPTIONAL MATCH; collect() of a map literal injection_count never 0; a phantom all-null key_patterns entry
#1558 add_code_to_graph advertised graph_name and ignored it agent told indexing succeeded into a graph that stayed empty

Notes on two of them

#1530 keeps the payload-slimming that motivated the original code. The path is still hoisted when every row agrees — the common case, when context pinned one definition. It only stays per-row when the rows genuinely disagree, and then the envelope carries a note:

"'save' is defined in 2 files; each result carries its own target_file_path.
 Pass `context` to disambiguate."

#1558 is not fully fixed and the issue stays open. Honouring graph_name for indexing needs a per-job GraphWriter threaded through the pipeline — GraphBuilder binds its writer to the default driver at construction (graph_builder.py:57). That is a real change with real risk to the core path, so this PR makes the tool refuse explicitly rather than write to the default graph and report success. Failing loudly beats misleading silently; the proper fix remains tracked.

Tests

tests/unit/tools/test_query_correctness_batch.py — 8 tests. Verified they catch the bugs by reverting the source changes: 7 of 8 fail, the 8th being the hoist-when-rows-agree case, which is correct both before and after.

One thing the tests caught while I wrote them: my first assertion for #1529 was too broad and flagged the global branch (MATCH (f:File) RETURN count(f)), which has no CONTAINS traversal and is correct as-is. The assertion now targets the traversal shape specifically.

🤖 Generated with Claude Code

Each of these produced a plausible-looking result rather than a failure,
which is the class an agent cannot detect and will act on.

get_repository_stats inflated every per-repo count (#1529)

The per-repository branch counted CONTAINS *paths*, not nodes. The writer
creates File->CONTAINS->Function, Class->CONTAINS->Function and
Function->CONTAINS->Function, so every method is reached 2+ times. On a
live single-repo database this reported 2202 functions against 1551 real
Function nodes, while the tool's own global branch reported 1551 — two
branches of one tool disagreeing by 42%. The module counter already used
count(DISTINCT m); the file, function and class counters now do too.

find_callers misattributed callers across same-named functions (#1530)

target_file_path was hoisted to the envelope from the first row and
stripped from the rest, on the assumption it is constant. Without
`context`, who_calls_function matches Function {name} across every file,
so rows legitimately carry different targets and every caller was
reported as calling whichever definition sorted first. Now hoisted only
when the rows agree; otherwise the field stays per-row and the envelope
carries a note naming the ambiguity.

graph_name silently discarded for dead_code and find_complexity (#1531)

Both inner methods default graph_name to None and re-assign the shared
_active_graph, so omitting it at the dispatch site redirected the query
to the default graph. On FalkorDB — the default, multi-graph backend —
that returns results for the wrong repository with no error.

count(*) after OPTIONAL MATCH, and a phantom collect() entry (#1533)

An unmatched OPTIONAL MATCH still emits one null row, so count(*) meant
injection_count was never 0 and every Spring bean reported at least one
injector; now counts the bound relationship. Separately, a map literal is
non-null even when every field inside is null, so collect() kept an
all-null entry for a datasource with no key patterns; now collects the
node and projects afterwards.

add_code_to_graph advertised an argument it ignored (#1558)

graph_name is in the tool schema but the handler never read it, so an
agent could index into "service-a", be told it succeeded, and find
nothing there. Honouring it needs a per-job writer threaded through the
pipeline (GraphBuilder binds its GraphWriter to the default driver at
construction), so this refuses explicitly instead. Full support stays
open on #1558.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
code-graph-context-pack Ready Ready Preview Aug 5, 2026 4:54pm

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Code Graph Analysis

fix(query): five defects that returned wrong answers without erroring (#1577)

📊 Interactive Visualization

View the blast radius graph: PR Reviewer Dashboard

📦 Artifacts

The graph JSON has been uploaded as a build artifact: pr-code-graph-1577


Generated by CodeGraphContext using FalkorDB Lite

@Shashankss1205
Shashankss1205 merged commit 7997a17 into main Aug 5, 2026
19 checks passed
@Shashankss1205
Shashankss1205 deleted the fix/query-correctness-batch branch August 5, 2026 17:14
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Aug 5, 2026
Shashankss1205 added a commit that referenced this pull request Aug 8, 2026
Ten PRs since 0.5.6 — mostly parser correctness, all with regression tests.

Parsers
- Ruby nested classes no longer delete their parent; method parameters
  extracted at all (#1523, #1527, #1581)
- C/C++ functions returning a pointer or reference are extracted, and
  registered in pre_scan so they resolve as call targets (#1524, #1582)
- C# fields and locals parsed, restoring receiver-type inference for
  `var x = new T(); x.M();` (#1525, #1584)
- JavaScript destructured, array and rest parameters extracted, recording
  the binding names rather than a placeholder (#1527, #1591)

Queries and analysis
- Five defects that returned wrong answers without erroring: inflated
  repository stats, misattributed callers, discarded graph_name,
  count(*) after OPTIONAL MATCH, an ignored tool argument (#1577)
- Dead-code detection made correct and self-consistent, including the
  JS module-level false positive (#600, #1559, #1578)

Indexing
- add_package_to_graph on a flat module no longer indexes the whole
  virtualenv (#1528, #1586)
- SCIP job progress no longer exceeds 100% (#1535, #1583)

Docs and tests
- Database Options table columns realigned (#1590)
- MCP tool definition contract validation (#1580)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(cli/mcp): get_repository_stats counts CONTAINS paths instead of distinct nodes — reports 2202 functions where 1551 exist (42% inflation)

1 participant