fix: match lowercase relationship types returned by API#19
Conversation
The API returns lowercase types (imports, calls, defines_function) but handlers compared against uppercase. This silently broke dead-code, blast-radius, and focus commands.
WalkthroughA systematic normalization of relationship type identifiers across the codebase, changing string comparisons from uppercase to lowercase formats (e.g., Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
internal/focus/handler.go (3)
133-137:⚠️ Potential issue | 🔴 CriticalInconsistent: External callers check still uses UPPERCASE.
Hey, looks like this spot got missed! Lines 134 still check for
"CALLS"and"CONTAINS_CALL"in uppercase, but the API returns lowercase. This means the "Called by" section infocusoutput will always be empty.Think of it this way: you fixed
buildCalleesOf(line 228) to use lowercase"calls", but this loop does the same kind of check and still uses uppercase"CALLS". Same relationship type, different casing = one works, one doesn't.🐛 Proposed fix
for _, rel := range rels { - if rel.Type != "CALLS" && rel.Type != "CONTAINS_CALL" { + if rel.Type != "calls" && rel.Type != "contains_call" { continue }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/focus/handler.go` around lines 133 - 137, The loop iterating over rels in the focus handler is still comparing rel.Type to uppercase "CALLS" and "CONTAINS_CALL", but the API returns lowercase; update those comparisons to the lowercase strings "calls" and "contains_call" (mirror the fix you made in buildCalleesOf) so the external callers ("Called by") logic that checks fnIDSet[rel.EndNode] actually matches returned relation types.
181-185:⚠️ Potential issue | 🔴 CriticalInconsistent: Import traversal still uses UPPERCASE.
Same deal here -
reachableImportschecks for"IMPORTS"and"WILDCARD_IMPORTS"in uppercase, but the API returns lowercase. This means the imports BFS won't find any edges, sosl.Importswill always be empty.Compare this to
blastradius/handler.goline 65, which you correctly updated to lowercase"imports"/"wildcard_imports".🐛 Proposed fix
for _, cur := range queue { for _, rel := range rels { - if rel.Type != "IMPORTS" && rel.Type != "WILDCARD_IMPORTS" { + if rel.Type != "imports" && rel.Type != "wildcard_imports" { continue }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/focus/handler.go` around lines 181 - 185, The loop in reachableImports is checking rel.Type against uppercase strings ("IMPORTS", "WILDCARD_IMPORTS") but the API returns lowercase; update the comparisons inside reachableImports (where rels is iterated and rel.Type is tested) to use "imports" and "wildcard_imports" (match the change made in blastradius/handler.go) so the BFS will actually follow import edges (ref: reachableImports, rels, rel.Type, visited, cur).
237-241:⚠️ Potential issue | 🟠 MajorFix uppercase relationship type checks in
extractTypes.The
extractTypesfunction checks for uppercase"DECLARES_CLASS"and"DEFINES", but the API returns these in lowercase like all other relationship types (you can seedefinesanddefines_functionworking correctly at line 209). This means when someone uses--include-types,sl.Typeswill always be empty because the relationship type comparisons never match.Change line 238 from:
if rel.Type != "DECLARES_CLASS" && rel.Type != "DEFINES" {to:
if rel.Type != "declares_class" && rel.Type != "defines" {Also worth noting—lines 134 and 182 have the same issue with uppercase
"CALLS","CONTAINS_CALL","IMPORTS", and"WILDCARD_IMPORTS". Those should be lowercase too to match what the API returns.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/focus/handler.go` around lines 237 - 241, The relationship-type comparisons in extractTypes are using uppercase strings and thus never match the API's lowercase types; update the checks in extractTypes (e.g., the condition comparing rel.Type to "DECLARES_CLASS" and "DEFINES") to use "declares_class" and "defines". Also find and fix the other uppercase rel.Type comparisons in this file (the checks against "CALLS", "CONTAINS_CALL", "IMPORTS", and "WILDCARD_IMPORTS") to their lowercase forms ("calls", "contains_call", "imports", "wildcard_imports") so include-type and call/import handling works correctly. Ensure you modify the exact rel.Type comparisons in the same functions where those symbols appear (extractTypes and the call/import handling blocks) without changing other logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@internal/focus/handler.go`:
- Around line 133-137: The loop iterating over rels in the focus handler is
still comparing rel.Type to uppercase "CALLS" and "CONTAINS_CALL", but the API
returns lowercase; update those comparisons to the lowercase strings "calls" and
"contains_call" (mirror the fix you made in buildCalleesOf) so the external
callers ("Called by") logic that checks fnIDSet[rel.EndNode] actually matches
returned relation types.
- Around line 181-185: The loop in reachableImports is checking rel.Type against
uppercase strings ("IMPORTS", "WILDCARD_IMPORTS") but the API returns lowercase;
update the comparisons inside reachableImports (where rels is iterated and
rel.Type is tested) to use "imports" and "wildcard_imports" (match the change
made in blastradius/handler.go) so the BFS will actually follow import edges
(ref: reachableImports, rels, rel.Type, visited, cur).
- Around line 237-241: The relationship-type comparisons in extractTypes are
using uppercase strings and thus never match the API's lowercase types; update
the checks in extractTypes (e.g., the condition comparing rel.Type to
"DECLARES_CLASS" and "DEFINES") to use "declares_class" and "defines". Also find
and fix the other uppercase rel.Type comparisons in this file (the checks
against "CALLS", "CONTAINS_CALL", "IMPORTS", and "WILDCARD_IMPORTS") to their
lowercase forms ("calls", "contains_call", "imports", "wildcard_imports") so
include-type and call/import handling works correctly. Ensure you modify the
exact rel.Type comparisons in the same functions where those symbols appear
(extractTypes and the call/import handling blocks) without changing other logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1e2bb0b2-f761-400d-8a34-9097942f8cf5
📒 Files selected for processing (7)
internal/blastradius/handler.gointernal/blastradius/handler_test.gointernal/deadcode/handler.gointernal/deadcode/handler_test.gointernal/focus/handler.gointernal/mcp/server.goscripts/check-architecture/main.go
Before / After (tested against supermodel-public-api, same cached graph)
|
Validation: CLI vs raw API dataComputed dead code, blast radius, and focus independently from the raw API response JSON (same graph, same repo) using Python — no CLI involved. Results match exactly. Dead code
Breakdown: 1,527 Function nodes total, 645 have incoming Blast radius — AuthConstants.java
Focus — codegraph.service.ts
|
Summary
The API returns relationship types in lowercase (
imports,calls,defines_function) but handlers compared against uppercase (IMPORTS,CALLS,DEFINES_FUNCTION). Since Go string comparison is case-sensitive, every check silently failed.What broke
Changes
10 string literals upppercase → lowercase across 7 files. Nothing else.
Test results (before → after)
Unit tests: all pass. Integration test: pass.
Summary by CodeRabbit
Bug Fixes
Tests