codegraph icon indicating copy to clipboard operation
codegraph copied to clipboard

CLI `callers` / `callees` / `impact` print stale line numbers with no warning, while `node` and `explore` warn

Open arifpambudi242 opened this issue 3 weeks ago • 2 comments

Environment

  • CodeGraph: main at f72c9d2 (2026-11-01), built locally; codegraph --version prints 1.6.2
  • Node.js v22.23.3
  • Linux 7.0.0

What happens

After a file changes on disk and before it is synced, codegraph node and codegraph explore say the file changed since the last index sync. codegraph callers, callees and impact print the old line numbers as if they were current. They exit 0 and print nothing on stderr, and callers --json has no field that marks the answer as stale. The same thing happens with and without CODEGRAPH_NO_DAEMON=1, when no MCP session has the project open.

Steps to reproduce

mkdir repro && cd repro && mkdir src
printf '[package]\nname = "repro"\nversion = "0.1.0"\nedition = "2021"\n' > Cargo.toml
cat > src/main.rs <<'EOF'
struct Model { name: String }
fn plain_helper(m: &Model) -> String { m.name.clone() }
fn direct(m: &Model) -> String { plain_helper(m) }
fn main() { let m = Model { name: "a".into() }; direct(&m); }
EOF
codegraph init --yes .
codegraph callers plain_helper     # direct at src/main.rs:3 (correct)

sed -i '1i // a\n// b\n// c' src/main.rs   # shift every line down by 3, don't sync
codegraph status                   # Pending Changes: Modified 1 files
codegraph callers plain_helper     # still src/main.rs:3, no warning (actual line: 6)
codegraph callees direct           # still old lines, no warning
codegraph impact plain_helper      # still old lines, no warning
codegraph node plain_helper        # "⚠ as of the last index sync; the file has changed on disk since..."

Expected

callers, callees and impact say that a file in the answer changed on disk after the last sync, the way node and explore already do. With --json, the notice goes on stderr or into a field, so the output stays parseable. Another option is a flag that syncs pending files before answering.

Why it matters

These three commands are the ones people use to decide what to edit, often from scripts or hooks where no MCP watcher is running. A line number that is off with no sign of it sends the reader to the wrong place.

Where it seems to come from

explore runs through ToolHandler (src/bin/codegraph.ts:1555-1560), which adds the changed-on-disk notice. callers / callees read cg.getCallSites directly (src/bin/codegraph.ts:2520-2541). openIndexToRead only warns when a rebuild is in progress (src/bin/codegraph.ts:399-407).

Not a duplicate of #602 (git hooks) or #3211 (a fork's --fresh option, offered as a note).

arifpambudi242 avatar Nov 09 '26 03:11 arifpambudi242

I can take this. I'll align callers, callees, and impact with the disk drift detection already present in node/explore, including warning to stderr when --json is specified to keep JSON output clean. Preparing a PR with regression tests.

mohitdixit02 avatar Nov 09 '26 13:11 mohitdixit02

Thanks for the clear repro, @arifpambudi242. callers, callees and impact printed line numbers straight from the index, without the on-disk check node and explore use. #3344 shares that check with them, so they now name any file in the answer that changed since it was indexed (on stderr, plus a changedOnDisk field under --json). It is merged to main today (2026-11-17) and ships in the next release.

colbymchenry avatar Nov 18 '26 03:11 colbymchenry