feat: semantic code impact analysis and change propagation engine - #1298
kashviporwal-byte wants to merge 2 commits into
Conversation
|
@kashviporwal-byte is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
👋 Thanks for contributing to CodeGraphContext! Since this PR was opened, |
|
Triage update: change-impact analysis is a compelling direction (and pairs naturally with the cgc diff request in #1312). The branch conflicts with main's current query layer; @kashviporwal-byte please rebase, and make sure the new engine has unit tests against at least the Kùzu backend (our embedded default on several platforms) — backend-portable Cypher has bitten us before. 🙏 |
Resolves CodeGraphViewer.tsx conflicts with the dual-engine AI explorer (CodeGraphContext#1588): both sides added a sidebar mode, so isImpactMode and isAIMode are chained in the ternary rather than replacing each other. Also updates the _FakeDBManager stub for get_driver(graph_name). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Shashankss1205
left a comment
There was a problem hiding this comment.
I've resolved the conflicts and pushed the merge to your branch, so this is up to date with main now — but I can't merge it yet, because analyze_impact fails on every call against KùzuDB. The unit tests don't catch this: _FakeSession returns canned rows without validating against a real schema.
Blocker 1 — File nodes have no uid.
code_finder.py:1585 does RETURN f.uid as uid for File, but File is the one node label keyed by path, not uid:
("File", "path STRING, name STRING, relative_path STRING, package_name STRING, is_dependency BOOLEAN, PRIMARY KEY (path)")
(database_embedded_kuzu.py:173 — compare Function/Class/Variable on lines 177-179, which do have uid.) This query runs unconditionally before the symbol lookup, so:
RuntimeError: Binder exception: Cannot find property uid for f.
Blocker 2 — the propagation query uses a construct KùzuDB doesn't support.
Patching past blocker 1 locally, code_finder.py:1661 then fails:
RuntimeError: Binder exception: Variable n is not in scope.
from
RETURN [n in nodes(p) | {uid: n.uid, name: n.name, path: n.path, labels: labels(n)}] as path_nodesPath-list comprehensions over nodes(p)/relationships(p) are a Neo4j-ism. This is the same class of problem as #1512.
Note blocker 2 also affects the criticality_query at line 1719 (target.uid) once a File ends up in target_uids.
What I'd suggest:
- Give
Filea synthetic identity in the query (RETURN f.path as uid) and handle it consistently intarget_uids— the genericMATCH (target) WHERE target.uid IN ...will hit the same missing-property error whenever a File is a target. - Rewrite the propagation query without path comprehensions, or gate the whole feature on backend and provide a Kùzu-compatible variant.
report_generator.pyandjava_toolkit.pyare good references for queries that work across backends. - Add at least one test that runs against a real embedded Kùzu database rather than
_FakeSession—tests/unit/core/test_database_kuzu_kotlin_metadata.pyshows the pattern.
The design and the UI side are good, and the merge conflict with #1588's AI explorer is already sorted out for you. It's specifically the backend query compatibility that needs another pass. Happy to help if you get stuck — just reply here.
Resolves #1164
Overview
This PR implements the Semantic Code Impact Analysis & Change Propagation Engine. It enables developers to predict the blast radius of modifying a code symbol or file before merging changes, reducing the risk of regressions and speeding up code review.
It leverages the repository knowledge graph to traverse upstream dependencies (like callers, subclasses, decorator modifications, and injected classes), calculates a custom risk score, and displays propagation paths and testing recommendations.
Detailed Changes
1. Backend Engine & Graph Traversal (
src/codegraphcontext/)tool_definitions.py): Defined theanalyze_impacttool accepting arguments:target(required),target_type,repo_path, anddepth.tools/handlers/analysis_handlers.py&server.py): Connected the tool call through the FastAPI REST server/api/tools/call.tools/code_finder.py): Implemented the core logic for the change propagation analyzer:CALLS,INHERITS,IMPLEMENTS,INJECTS,DECORATED_BY, andIMPORTSrelationships backward up to a configurabledepth.nodes(p)andrelationships(p)mapping), making it fully compatible with Neo4j, FalkorDB, and KuzuDB.git rev-list --count) to retrieve file modification counts, integrating historical churn into the risk calculations.2. Risk Scoring System
Computes a normalized risk score out of
10.0based on:5.0): Distance of the propagation path.5.0): Count of distinct files affected.5.0): In-degree centrality (incoming links to target).5.0): How often the target files are modified in git history.3. Visual Dependency Explorer (
website/)CodeGraphViewer.tsx):Verification & Testing
Automated Tests
Created unit test suite
tests/unit/tools/test_impact_analysis.pycovering target symbol resolution, file-level containment queries, risk scoring heuristics, empty states, and local Git command fallbacks.Run commands:
Status: All 3 tests passed successfully.
Manual Verification
/tools/callendpoint returns exact propagation paths.Checklist