Skip to content

fix(cli): report absolute index totals on re-index of unchanged files (#874)#884

Open
Dashsoap wants to merge 1 commit into
colbymchenry:mainfrom
Dashsoap:fix/index-reports-zero-nodes-874
Open

fix(cli): report absolute index totals on re-index of unchanged files (#874)#884
Dashsoap wants to merge 1 commit into
colbymchenry:mainfrom
Dashsoap:fix/index-reports-zero-nodes-874

Conversation

@Dashsoap

Copy link
Copy Markdown

Fixes #874.

What

codegraph index printed "0 nodes, 0 edges" when run after init on an unchanged tree, making it look like the index had been wiped. This makes the CLI report the absolute node/edge totals in that case (e.g. 8 nodes, 11 edges (index already up to date)).

Why

The index was never actually empty — the reporter noted status still worked and re-running init was fine. I reproduced it locally:

$ codegraph init     →  Indexed 2 files · 8 nodes, 11 edges
$ codegraph index    →  Indexed 2 files · 0 nodes, 0 edges     # ← looks wiped
$ codegraph status   →  8 nodes (file 2, function 2, method 2, class 1, import 1)   # ← data intact
$ codegraph query Greeter  →  still returns results

Root cause: indexAll() reports nodesCreated/edgesCreated as the net delta of the run (after - before):

const after = this.queries.getNodeAndEdgeCount();
result.nodesCreated = after.nodes - before.nodes;
result.edgesCreated = after.edges - before.edges;

On a re-index with no file changes, every file’s content hash matches in storeExtractionResult() (it early-returns without re-inserting), so the delta is legitimately 0 — but the index is fully populated. init shows a non-zero count only because it starts from an empty DB (before == 0, so delta == total).

Fix

Add optional totalNodes/totalEdges to IndexResult, populated from the same getNodeAndEdgeCount() the delta already reads (zero extra queries). The CLI prefers the absolute totals when the delta is 0:

8 nodes, 11 edges in 55ms (index already up to date)

Behavior preserved (verified locally)

Case Output
First full index (empty DB) 8 nodes, 11 edges (delta == total, unchanged)
index --force (clears first) 8 nodes, 11 edges (real rebuild, unchanged)
Changed files real net delta, no "up to date" suffix
Re-index, unchanged 8 nodes, 11 edges (index already up to date) ← the fix

Tests

Adds __tests__/index-reindex-totals.test.ts pinning that a re-index of unchanged files keeps totalNodes/totalEdges populated while the delta is 0, and that data stays queryable. Full suite green (1377 passed) and tsc --noEmit clean.

…colbymchenry#874)

`codegraph index` printed "0 nodes, 0 edges" when run after `init` on an
unchanged tree, making it look like the index had been wiped — even though
the data was fully intact (`status`/`query` still worked, and re-running
`init` was unaffected).

Root cause: indexAll() reports nodesCreated/edgesCreated as the *net delta*
of the run (after - before). On a re-index with no file changes, every
file's content hash matches in storeExtractionResult(), so nothing is
re-inserted and the delta is legitimately 0 — but the index is still fully
populated.

Fix: add optional absolute totalNodes/totalEdges to IndexResult (populated
from the same getNodeAndEdgeCount() the delta already reads). The CLI now
prefers the absolute totals when the delta is 0, printing e.g.
"8 nodes, 11 edges (index already up to date)" instead of "0 nodes, 0 edges".

Behavior preserved:
  - first full index (empty DB): delta == totals, unchanged output
  - --force re-index (clears first): real rebuild counts, unchanged output
  - changed files: real net delta shown (no 'up to date' suffix)

Adds regression tests pinning that a re-index of unchanged files keeps
totalNodes/totalEdges populated while the delta is 0, and that data stays
queryable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: codegraph index produces 0 nodes / 0 edges while codegraph init works correctly

1 participant