From e20a7684f52e657ff3e3b652551acc28aae4b715 Mon Sep 17 00:00:00 2001 From: carlos-alm <127798846+carlos-alm@users.noreply.github.com> Date: Tue, 14 Apr 2026 23:58:42 -0600 Subject: [PATCH 1/3] fix(native): resolve version-mismatch ping-pong that broke incremental builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When JS and Rust crate versions diverge (e.g. npm 3.9.3 vs Cargo 3.9.2), the JS side wrote CODEGRAPH_VERSION (npm) into build_meta while the Rust side checked it against CARGO_PKG_VERSION (crate). This mismatch caused every native incremental build to be promoted to a full rebuild — the version check in setupPipeline set forceFullRebuild=true, and the Rust check_version_mismatch returned force_full_rebuild=true. Fix: when the native engine is active, use the Rust addon version (ctx.engineVersion) consistently for both writing and checking codegraph_version in build_meta. Before: native no-op rebuild ~5,800ms (full rebuild every time) After: native no-op rebuild ~40ms (proper early exit) Closes #929 (related: edge accumulation in native incremental) Impact: 2 functions changed, 7 affected --- src/domain/graph/builder/pipeline.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/domain/graph/builder/pipeline.ts b/src/domain/graph/builder/pipeline.ts index 0d85751b..4a89bfd0 100644 --- a/src/domain/graph/builder/pipeline.ts +++ b/src/domain/graph/builder/pipeline.ts @@ -88,10 +88,18 @@ function checkEngineSchemaMismatch(ctx: PipelineContext): void { ); ctx.forceFullRebuild = true; } + // When the native engine is active, the Rust addon's version (ctx.engineVersion) + // is written into codegraph_version by setBuildMeta after a native orchestrator + // build. The check must compare against the same version, otherwise JS and Rust + // fight over which version to record — causing every incremental build to be + // promoted to a full rebuild when npm and crate versions diverge. + const effectiveVersion = ctx.engineName === 'native' && ctx.engineVersion + ? ctx.engineVersion + : CODEGRAPH_VERSION; const prevVersion = meta('codegraph_version'); - if (prevVersion && prevVersion !== CODEGRAPH_VERSION) { + if (prevVersion && prevVersion !== effectiveVersion) { info( - `Codegraph version changed (${prevVersion} → ${CODEGRAPH_VERSION}), promoting to full rebuild.`, + `Codegraph version changed (${prevVersion} → ${effectiveVersion}), promoting to full rebuild.`, ); ctx.forceFullRebuild = true; } @@ -631,10 +639,16 @@ async function tryNativeOrchestrator( const p = result.phases; // Sync build_meta so JS-side version/engine checks work on next build. + // Use the Rust addon version as codegraph_version when the native + // orchestrator performed the build — the Rust side's check_version_mismatch + // compares this value against CARGO_PKG_VERSION. Writing the JS + // CODEGRAPH_VERSION here would create a permanent mismatch whenever the + // npm package version diverges from the Rust crate version, forcing every + // subsequent native build to be a full rebuild (no incremental). setBuildMeta(ctx.db, { engine: ctx.engineName, engine_version: ctx.engineVersion || '', - codegraph_version: CODEGRAPH_VERSION, + codegraph_version: ctx.engineVersion || CODEGRAPH_VERSION, schema_version: String(ctx.schemaVersion), built_at: new Date().toISOString(), node_count: String(result.nodeCount ?? 0), From d9da50ce2eb434e2ce47088e68ac20f2519c281d Mon Sep 17 00:00:00 2001 From: carlos-alm <127798846+carlos-alm@users.noreply.github.com> Date: Tue, 14 Apr 2026 23:59:06 -0600 Subject: [PATCH 2/3] style: fix biome formatting in pipeline.ts Impact: 1 functions changed, 5 affected --- src/domain/graph/builder/pipeline.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/domain/graph/builder/pipeline.ts b/src/domain/graph/builder/pipeline.ts index 4a89bfd0..2f004526 100644 --- a/src/domain/graph/builder/pipeline.ts +++ b/src/domain/graph/builder/pipeline.ts @@ -93,9 +93,8 @@ function checkEngineSchemaMismatch(ctx: PipelineContext): void { // build. The check must compare against the same version, otherwise JS and Rust // fight over which version to record — causing every incremental build to be // promoted to a full rebuild when npm and crate versions diverge. - const effectiveVersion = ctx.engineName === 'native' && ctx.engineVersion - ? ctx.engineVersion - : CODEGRAPH_VERSION; + const effectiveVersion = + ctx.engineName === 'native' && ctx.engineVersion ? ctx.engineVersion : CODEGRAPH_VERSION; const prevVersion = meta('codegraph_version'); if (prevVersion && prevVersion !== effectiveVersion) { info( From ddeba084f9521f61504dc5177cfaa5f618607472 Mon Sep 17 00:00:00 2001 From: carlos-alm <127798846+carlos-alm@users.noreply.github.com> Date: Wed, 15 Apr 2026 13:44:20 -0600 Subject: [PATCH 3/3] fix: persist engine version in finalize.ts to close rebuild loop (#930) persistBuildMetadata was unconditionally writing CODEGRAPH_VERSION (the npm package version) as codegraph_version. When the JS-pipeline fallback runs a full rebuild with the native engine active, this created a permanent mismatch against ctx.engineVersion, forcing every subsequent build to be a full rebuild. Now uses ctx.engineVersion when the native engine is active, matching the logic in checkEngineSchemaMismatch and tryNativeOrchestrator. Impact: 1 functions changed, 3 affected --- src/domain/graph/builder/stages/finalize.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/domain/graph/builder/stages/finalize.ts b/src/domain/graph/builder/stages/finalize.ts index 857bbf40..7794d742 100644 --- a/src/domain/graph/builder/stages/finalize.ts +++ b/src/domain/graph/builder/stages/finalize.ts @@ -81,13 +81,20 @@ function persistBuildMetadata( ): void { const useNativeDb = ctx.engineName === 'native' && !!ctx.nativeDb; if (!ctx.isFullBuild && ctx.allSymbols.size <= 3) return; + // When the native engine is active, persist the Rust addon version so that + // checkEngineSchemaMismatch compares against the same value on the next build. + // Writing CODEGRAPH_VERSION (the npm package version) here would create a + // permanent mismatch whenever npm and crate versions diverge, forcing every + // subsequent build to be a full rebuild. + const codeVersionToWrite = + ctx.engineName === 'native' && ctx.engineVersion ? ctx.engineVersion : CODEGRAPH_VERSION; try { if (useNativeDb) { ctx.nativeDb!.setBuildMeta( Object.entries({ engine: ctx.engineName, - engine_version: CODEGRAPH_VERSION, - codegraph_version: CODEGRAPH_VERSION, + engine_version: codeVersionToWrite, + codegraph_version: codeVersionToWrite, schema_version: String(ctx.schemaVersion), built_at: buildNow.toISOString(), node_count: String(nodeCount), @@ -97,8 +104,8 @@ function persistBuildMetadata( } else { setBuildMeta(ctx.db, { engine: ctx.engineName, - engine_version: CODEGRAPH_VERSION, - codegraph_version: CODEGRAPH_VERSION, + engine_version: codeVersionToWrite, + codegraph_version: codeVersionToWrite, schema_version: String(ctx.schemaVersion), built_at: buildNow.toISOString(), node_count: nodeCount,