How tirth8205/code-review-graph's Blast Radius Analysis Works Internally

The blast radius analysis uses a bidirectional breadth-first search (BFS) on a pre-computed SQLite code graph to identify all nodes and files potentially affected by a change within a configurable depth limit.

The blast radius feature in tirth8205/code-review-graph determines which parts of a codebase are potentially affected by a modification. This analysis operates entirely through read-only SQL queries against a stored dependency graph, ensuring fast and deterministic results without database mutations.

The Three-Stage Blast Radius Pipeline

The implementation follows a clear three-step process orchestrated across the VS Code extension's backend and UI layers.

Stage 1: Resolving Seed Nodes from Cursor Position

When a user invokes the Show Blast Radius command, the system first identifies the starting point. The SqliteReader.getNodeAtCursor method in src/features/cursorResolver.ts resolves the specific file or innermost AST node under the cursor. If no specific node is found, the system falls back to using the full file path as the seed identifier.

Stage 2: Executing the BFS Graph Traversal

The core logic resides in SqliteReader.getImpactRadius within src/backend/sqlite.ts. This method performs a bidirectional breadth-first search with the following steps:

  • Seed collection: Gathers all graph nodes belonging to the changed files via getNodesByFile, extracting their qualifiedName values as the initial seed set.
  • BFS traversal: Walks both forward (outgoing edges) and backward (incoming edges) directions for a configurable number of hops specified by maxDepth (defaulting to 2). Each newly discovered node is recorded as impacted.
  • Result assembly: Resolves qualified names back to full GraphNode objects, deduplicates file paths, and collects all connecting edges via getEdgesAmong. The method returns an ImpactRadius object containing changedNodes (original seeds), impactedNodes (reachable within depth limit), impactedFiles (distinct paths), and edges (connections between all involved nodes).

This implementation mirrors the Python backend's GraphStore.get_impact_radius to ensure consistent behavior between the VS Code UI and the underlying analysis engine.

Stage 3: Rendering the Impact Visualization

The registerBlastRadiusCommand function in src/features/blastRadius.ts orchestrates the UI presentation. It feeds the changedNodes and impactedNodes into a BlastRadiusTreeProvider, which renders the results as a tree view in the VS Code sidebar. The command also displays a summary toast message indicating the total count of impacted nodes and files.

Core SQL-Based Graph Traversal Mechanics

The analysis is a pure-SQL read-only BFS performed on the pre-computed code graph. The getImpactRadius method efficiently queries the SQLite database to traverse relationships without loading the entire graph into memory. By limiting the search depth via maxDepth, the system prevents excessive noise while capturing the most relevant dependencies. The bidirectional traversal ensures both upstream dependencies (callers) and downstream dependencies (callees) are identified, providing a complete picture of the change's ripple effect.

Programmatic Usage Examples

Developers can interact with the blast radius analysis programmatically through the TypeScript API.

Registering the command during extension activation:

registerBlastRadiusCommand(
  context,
  () => currentReader,           // function returning the active SqliteReader
  blastRadiusProvider,
  workspaceRoot,
);

Direct API usage for custom integrations:

const reader = await SqliteReader.create(dbPath);
const changed = ['src/utils/file.ts'];
const radius = reader.getImpactRadius(changed, 3); // depth = 3

console.log('Impacted nodes:', radius.impactedNodes.length);
console.log('Impacted files:', radius.impactedFiles);

Manual invocation via the command palette:

  1. Place the cursor on a symbol or open a target file.
  2. Press Ctrl+Shift+P and select "Code Review Graph: Show Blast Radius".
  3. Observe the sidebar tree update and the status message (e.g., "Blast radius: 42 nodes impacted across 7 files").

Summary

  • The blast radius analysis uses a bidirectional BFS on an SQLite-backed code graph to find impacted code.
  • Seed resolution occurs via cursorResolver.ts, identifying the starting node or file under the cursor.
  • The core algorithm in sqlite.ts traverses up to maxDepth hops (default 2) in both directions to find affected nodes.
  • Results are encapsulated in an ImpactRadius object containing nodes, files, and edges for visualization.
  • The analysis is read-only and deterministic, ensuring safe, fast operation without database mutations.

Frequently Asked Questions

What database does the blast radius analysis use?

The analysis queries a pre-computed SQLite database that stores the code graph. The SqliteReader class provides a read-only interface to this database, ensuring the analysis does not modify the underlying data during traversal.

How does the system determine the starting point for the analysis?

The system uses SqliteReader.getNodeAtCursor in src/features/cursorResolver.ts to resolve the innermost AST node at the current cursor position. If no specific node is identified, the analysis falls back to using the full file path as the seed.

What is the default search depth for the blast radius?

The default maxDepth is 2 hops, meaning the algorithm traverses two levels of dependencies in both forward (outgoing) and backward (incoming) directions. This default strikes a balance between capturing relevant impacts and minimizing noise.

Does the blast radius analysis modify the codebase or database?

No. The blast radius analysis is a pure read-only operation. It performs SQL SELECT queries against the existing graph database without mutating either the database or the source code files.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →