Skip to content

fix(watch): watch-mode rebuild now populates full node schema - #2380

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2220-watch-insertnode-missing-columns
Aug 9, 2026
Merged

carlos-alm merged 2 commits into
mainfrom
fix/issue-2220-watch-insertnode-missing-columns

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Closes #2220

Root cause

codegraph watch's single-file rebuild path (prepareWatcherStatements in src/domain/graph/watcher.ts, insertFileNodes in src/domain/graph/builder/incremental.ts) only ever inserted (name, kind, file, line, end_line, accessor_kind) into nodes, and never set exported = 1 on an exported symbol. The full-build path (insertDefinitionsAndExports/collectChildRowsAndFileEdges in stages/insert-nodes.ts) additionally populates qualified_name, scope, visibility, parent_id, content_hash, and exported.

A symbol touched only by a watch-mode rebuild would silently diverge from one touched by a full or regular incremental codegraph build — any downstream query that filters/joins on those columns (cross-file reference lookups, "go to definition", exported-symbol queries) could behave differently depending purely on which rebuild path last touched it.

Fix

  • insertNode's column set now mirrors the full-build path's getNodeStmt exactly: (name,kind,file,line,end_line,parent_id,qualified_name,scope,visibility,content_hash,accessor_kind).
  • insertFileNodes computes qualified_name/scope the same way insertDefinitionsAndExports does (a dotted definition name yields a scope from everything before the last dot), and resolves a child's parent_id via a real post-insert getNodeId lookup — not lastInsertRowid, which INSERT OR IGNORE makes unreliable when a definition already exists from a prior rebuild.
  • Added a markExported statement (mirroring the full-build path's getExportStmt) so an exported symbol gets exported = 1 regardless of which rebuild path touched it.

Test infrastructure cleanup

Fixing the schema meant every one of the ~18 watch-mode integration test files needed the same update to their local, hand-rolled makeStmts(db) helper (each duplicated the same prepared-statement set, one paste away from drifting out of sync with production the next time this schema changes — which is exactly what happened here). Extracted them into a single shared tests/helpers/incremental-stmts.ts.

Test plan

  • New tests/integration/issue-2220-watch-insertnode-columns.test.ts: verifies a watch-mode rebuild gives a top-level exported function qualified_name/exported = 1, a dotted method definition the correct scope, and a parameter child the correct parent_id/qualified_name.
  • Verified this new test fails (crashes on a bind-parameter arity mismatch) with the production fix reverted, and passes with it restored.
  • All 18 migrated test files individually verified passing.
  • Full local suite: npm test (292 files / 4749 tests passed), tsc --noEmit, biome check all clean.
  • No native-engine changes needed — watch mode's rebuild path is JS-only end-to-end (verified no native dispatch in watcher.ts/incremental.ts).

…orted

codegraph watch's single-file rebuild path (prepareWatcherStatements in
watcher.ts, insertFileNodes in incremental.ts) only ever inserted
(name, kind, file, line, end_line, accessor_kind) and never set
exported=1 on an exported symbol — unlike the full-build path
(insertDefinitionsAndExports/collectChildRowsAndFileEdges in
stages/insert-nodes.ts), which populates qualified_name, scope,
visibility, parent_id, content_hash, and exported. A symbol touched only
by a watch-mode rebuild would silently diverge from one touched by a
full or regular incremental build, affecting any downstream query that
filters/joins on those columns.

insertNode's column set now mirrors the full-build path's getNodeStmt
exactly, and a child's parent_id is resolved via a real post-insert
lookup (getNodeId), not lastInsertRowid — which INSERT OR IGNORE makes
unreliable when a def already exists from a prior rebuild.

Extracted the ~18 near-identical local makeStmts(db) helpers duplicated
across watch-mode integration tests into a single shared
tests/helpers/incremental-stmts.ts, since fixing the schema meant every
one of them needed the same update anyway — each was one paste away from
drifting out of sync with production the next time this schema changes.

docs check acknowledged: bug fix only, no language/architecture/CLI change

Impact: 4 functions changed, 6 affected
@greptile-apps

greptile-apps Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR aligns watch-mode node insertion with the full graph-build schema and consolidates duplicated incremental-test statement bundles.

  • Persists qualified names, scopes, visibility, parent relationships, content hashes, and exported status during watch rebuilds.
  • Resolves child parent IDs from the inserted definition's stable database key.
  • Replaces duplicated integration-test statement factories with a shared production-equivalent helper.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/domain/graph/builder/incremental.ts Extends watch-mode node insertion to persist full-build metadata, resolve child parent IDs, and mark exported symbols.
src/domain/graph/watcher.ts Updates watcher prepared statements to support the expanded node schema and exported-state update.
tests/helpers/incremental-stmts.ts Introduces a shared incremental statement bundle matching the production watcher configuration.
tests/integration/issue-2220-watch-insertnode-columns.test.ts Covers exported status, qualified names, dotted scopes, and child parent relationships after watch rebuilds.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Change["Source file change"] --> Watcher["Watcher"]
  Watcher --> Parse["Incremental parse"]
  Parse --> Insert["Insert file, definitions, and children"]
  Insert --> Lookup["Resolve parent IDs"]
  Lookup --> Export["Mark exported symbols"]
  Export --> Edges["Rebuild containment and reference edges"]
  Edges --> DB["Persist full node schema"]
Loading

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

3 functions changed → 6 callers affected across 3 files

  • insertFileNodes in src/domain/graph/builder/incremental.ts:127 (3 transitive callers)
  • prepareWatcherStatements in src/domain/graph/watcher.ts:19 (3 transitive callers)
  • createIncrementalStmts in tests/helpers/incremental-stmts.ts:11 (0 transitive callers)

@carlos-alm
carlos-alm merged commit 1bda5ac into main Aug 9, 2026
24 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2220-watch-insertnode-missing-columns branch August 9, 2026 08:52
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

watch-mode incremental rebuild's insertNode never populates qualified_name/scope/visibility (or now content_hash)

1 participant