# 17. Change impact from the graph: spans, a transitive walk, and freshness

**Status:** Accepted · 2026-10-12 · extends [ADR-0010](./0010-own-code-graph.md)

## Context

ADR-0010 built the code graph to answer "where does this live" and "what
depends on this". Four properties of the graph shape the second answer:

- References point from files to symbols, and a file's only incoming edges are
  imports. A reverse walk therefore needs a hop from each dependent file to the
  declarations it makes before it can reach the next ring, and the file that
  defines a seed is not one of its dependents.
- A reviewer starts from a diff, not from a symbol name, so the walk needs a
  way to turn changed lines into declarations.
- The manifest written at build time records each file's size and mtime, which
  is enough to tell whether an answer describes the current tree.
- A query budget is only honest when it is charged for the text the caller
  receives.

Two public tools solved parts of this. One maps a diff onto the symbols that contain the changed lines and walks
outward for blast radius, and reports whether the paths asked about are indexed
and fresh. The other seeds its affected walk from a
declaration's members and counts the tokens of the answer it actually returns.
Neither is a dependency: the first is a C daemon with tree-sitter
grammars, a file watcher and a browser UI, the second a Python service with
incremental reconciliation, and ADR-0004 forbids a native runtime dependency.

## Decision

Extend the graph in place:

- **Spans.** Every definition gets an `endLine`: the line before the next
  definition at the same or a lower indentation, or the end of the file. It is
  derived from the indentation signal the engine already uses for nesting, so
  it needs no parser and holds across the brace languages and Python. Schema
  1.1.0; a 1.0.0 graph stays readable.
- **Diff seeding.** `graph-affected --diff` maps each hunk onto the innermost
  declaration it touches and seeds the walk with it and its enclosing
  declarations. A file from a pre-1.1.0 graph is seeded whole and listed as
  such; a changed file the graph does not contain is listed as not indexed.
  The diff is read on the side the graph describes: the new side when the
  graph matches the tree, otherwise the old side, where its spans hold.
- **A transitive walk.** Dependents are files; the walk continues through what
  each dependent file declares, never follows `defines`, and never reports a
  seed's defining file.
- **Freshness on every answer.** Size and mtime against the manifest, plus the
  build commit against HEAD. A stale answer says it is stale.
- **Risk.** `diff-risk-score --graph` adds `dependents_reached`, combined with
  the existing security, public-API and missing-test signals and capped, so a
  change is not ranked by graph distance alone.
- **Honest budgets.** `graph-query` charges for the printed line.

## Not adopted

A daemon or watcher, incremental reconciliation (a full build takes seconds;
an existing tool's history shows how many defects incremental state produces), Cypher,
a UI, LLM-labelled edges and confidence scores. The single-candidate rule from
ADR-0010 stays: an ambiguous reference gets no edge rather than a guessed one.

## Consequences

A reviewer and Phase 3 get the blast radius of the actual diff. A span is an
upper bound, so a hunk in trailing blank lines or a closing brace counts toward
the declaration above it; that errs toward more dependents, not fewer. Method
level precision is still bounded by regex extraction; confirming candidates
through the language server (`code_references`) is the next step and is not
part of this decision.
