Repository navigation
Conversation
`used_by` for a symbol was queried with `GraphEdge.target_node_id == sym.file_path` (the bare path). Symbol nodes are keyed `<path>::<name>` and call/reference edges point *at* that symbol node, so the query never matched them — it only ever caught file→file edges. For a C++ symbol that is the synthetic header/source `imports` pair (`imported_names = []`), so `used_by` named the paired header (which never references the symbol) and omitted the file that actually calls it. Now match either kind of evidence: - symbol→symbol `calls`/`references` edges targeting the symbol node, or - file→file `imports` edges whose `imported_names` actually names the symbol (gated, so an empty-imports header pair is not a fabricated user). Distinct sources afterwards, so a file that both imports and calls is one user. Python file-import used_by is preserved. Fixes repowise-dev#1655
|
✅ Health of changed files: 2.2 → 2.9 (+0.7) 📋 At a glance Files & modules (2)
✅ Health gate: passed 📌 Before you merge
🔎 More signals (2)🗺️ Change map flowchart LR
subgraph PR ["Changed in this PR (1 with dependents)"]
f_packages_server_src_repowise_server_mcp_server_tool_context_targets_py[".../tool_context/targets.py 🔥"]:::changed
end
f_packages_server_src_repowise_server_mcp_server_tool_answer_answer_py[".../tool_answer/answer.py"]
f_packages_server_src_repowise_server_mcp_server_tool_context_targets_py --> f_packages_server_src_repowise_server_mcp_server_tool_answer_answer_py
f_packages_server_src_repowise_server_mcp_server_tool_context_context_py[".../tool_context/context.py"]
f_packages_server_src_repowise_server_mcp_server_tool_context_targets_py --> f_packages_server_src_repowise_server_mcp_server_tool_context_context_py
t_tests_unit_server_mcp_test_context_file_preview_py(["✅ .../mcp/test_context_file_preview.py"]):::guard
t_tests_unit_server_mcp_test_context_file_preview_py -.-> f_packages_server_src_repowise_server_mcp_server_tool_context_targets_py
classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Solid arrows: code that imports the changed files (2 direct dependents, from the last indexed snapshot). Dashed: history/tests. 🔥 Hotspots touched (2)
📊 See the full report for this PR |
|
Thanks @sloemo01, and specifically for not stopping where the issue stopped. The report blamed the header/impl pairing, and the pairing is the symptom. The existing comment above that query is quiet corroboration, by the way. It says distinct sources are needed because "two files joined by both an import and a call are one user", then notes the corpus holds zero duplicate rows so the guard "costs nothing and prevents nothing today". Zero duplicates because the call half never matched anything. The code was already describing the bug. The The gapThe rewrite replaces the file-scoped condition with an unscoped one: or_(
GraphEdge.target_node_id == sym_node_id,
GraphEdge.imported_names_json.contains(sym.name),
)The old query was over-broad in one direction (any file importing this file, regardless of what it imported) but it was at least anchored to the symbol's own file. The new import branch drops that anchor completely. It now matches an import edge anywhere in the repository, pointing at any file, as long as the text of its Two independent widenings stacked: no file scope, and no word boundary. What it does on this repo's own indexDistinct source files returned, running the real
That last part is what makes it worse than a cosmetic precision loss. What I think it needsKeep the file anchor on the import branch only, and leave the call branch unscoped since a call edge already names the symbol node exactly: or_(
GraphEdge.target_node_id == sym_node_id,
and_(
GraphEdge.target_node_id == sym.file_path,
GraphEdge.imported_names_json.contains(sym.name),
),
)Same three columns, same index, and it still excludes the header pair you were targeting, because an empty Two things I checked so you do not have to: Only 37 of 12,941
The substring match still lets Push that and I will merge. This is a good fix one condition away from done. |
|
Thanks @sloemo01, the root-cause read is right and it is the one I had reached too: Gating the import half on GraphEdge.imported_names_json.contains(sym.name),
Matching the quoted JSON token closes most of it: GraphEdge.imported_names_json.contains(f'"{sym.name}"'),
The two tests are well built, particularly Everything else is ready to go. Push that and I will merge. |
|
Main already carries this fix, so I am closing rather than rebasing a four-hundred-commit-stale branch.
Main's Main's version also goes further than this one did: it matches both node depths, symbol-to-symbol call and reference edges plus file-to-file imports gated on The merge conflict was the useful signal, since it was the same lines changed on both sides. |
What
Fixes #1655.
get_context'sused_byfor a symbol was populated from the C++ header/impl pairing, not from resolved call/reference edges — it named the paired header (which never references the symbol) and omitted the file that actually calls it.Root cause
The
used_byquery matchedGraphEdge.target_node_id == sym.file_path(the bare path). Symbol nodes are keyed<path>::<name>, and call/reference edges point at that symbol node — so the query never matched a single call edge. It only ever caught file→file edges, which for a C++ symbol is the synthetic header/sourceimportspair (minted withimported_names = []).Fix
targets.pynow matches either kind of evidence:calls/referencesedges targeting the symbol node (<path>::<name>) — the real cross-file C++ callers.importsedges whoseimported_namesactually names the symbol — gated on the name so the empty-imports header pair is not served as a fabricated user.Distinct sources afterwards, so a file that both imports and calls a symbol is one user. The Python file-import path (
imported_names-based) is preserved — existing ranking tests pass unchanged.Tests
test_used_by_ranking.py— 6 passed (4 existing + 2 new):test_call_edge_to_symbol_node_is_a_user— a cross-file C++ call edge now surfaces the caller inused_by.test_empty_header_pair_edge_is_not_a_user— the synthetic header pair (emptyimported_names) is excluded.This is confined to the graph-surface consumers (
context/get_context/get_symbol);dead-codewas already correct per the issue.