fix(native): resolve version-mismatch that broke incremental builds#930
fix(native): resolve version-mismatch that broke incremental builds#930carlos-alm wants to merge 2 commits intomainfrom
Conversation
…l builds 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
Impact: 1 functions changed, 5 affected
|
Claude finished @carlos-alm's task —— View job PR Review: Fix Native Incremental Version MismatchRoot Cause AnalysisProblem Being Solved: Version ping-pong between JS ( Why This Approach: The fix ensures both sides of the version check use consistent values. When native engine builds, it now writes the Rust addon version to Risk Assessment: ✅ Low risk. The changes are surgical and well-isolated. The logic preserves existing WASM behavior while fixing the native-specific issue. Backlog Compliance
Critical ConcernsNone identified. This is a well-executed performance fix. Code Quality Analysis ⭐⭐⭐⭐Positive aspects:
Technical correctness:
Security: No security implications. Changes only affect version metadata consistency. Test CoverageThe existing test in Recommendation: Consider adding a specific test case for the native vs JS version scenario, but this is not blocking. Performance ValidationThe benchmark results are impressive and consistent with the described fix:
These improvements directly address the core issue of AI coding assistants being slowed down by unnecessary full rebuilds. Final Recommendation
The only reason this doesn't get 5 stars is the lack of specific test coverage for the new logic, but the risk is low given the surgical nature of the changes. |
Greptile SummaryThis PR fixes the version ping-pong between the JS pipeline (
Confidence Score: 4/5Safe to merge for the primary use case, but the incomplete fix in The core fix is correct and delivers the 145× speedup for the normal incremental path. However,
Important Files Changed
Sequence DiagramsequenceDiagram
participant JS as JS checkEngineSchemaMismatch
participant NO as tryNativeOrchestrator
participant FIN as finalize.persistBuildMetadata
participant DB as build_meta (codegraph_version)
Note over JS,DB: Normal incremental path (FIXED)
DB-->>JS: prevVersion = 3.9.2
JS->>JS: effectiveVersion = ctx.engineVersion = 3.9.2
JS->>NO: forceFullRebuild = false, native orchestrator runs
NO->>DB: codegraph_version = ctx.engineVersion = 3.9.2
Note over JS,DB: After schema migration (REGRESSION)
DB-->>JS: prevSchema != current, forceFullRebuild = true
JS->>NO: shouldSkipNativeOrchestrator returns forceFullRebuild
NO-->>JS: returns undefined, JS pipeline runs
FIN->>DB: codegraph_version = CODEGRAPH_VERSION = 3.9.3 (wrong)
Note over JS,DB: Next build (infinite loop)
DB-->>JS: prevVersion = 3.9.3
JS->>JS: effectiveVersion = ctx.engineVersion = 3.9.2
JS->>JS: 3.9.3 != 3.9.2, forceFullRebuild = true
JS->>NO: shouldSkipNativeOrchestrator returns forceFullRebuild
NO-->>JS: returns undefined, JS pipeline runs again
FIN->>DB: codegraph_version = 3.9.3 (loop repeats)
Reviews (1): Last reviewed commit: "style: fix biome formatting in pipeline...." | Re-trigger Greptile |
| const effectiveVersion = | ||
| ctx.engineName === 'native' && ctx.engineVersion ? ctx.engineVersion : CODEGRAPH_VERSION; |
There was a problem hiding this comment.
finalize.ts still writes CODEGRAPH_VERSION, re-creating the loop
checkEngineSchemaMismatch now correctly compares against ctx.engineVersion when native is active, but finalize.persistBuildMetadata (stages/finalize.ts:89–101) still writes CODEGRAPH_VERSION as codegraph_version unconditionally. This leaves an inconsistency: any time the JS-pipeline fallback runs a full rebuild (triggered by schema migration, engine switch, etc.), it persists the npm package version, and on the very next build this check sees prevVersion = CODEGRAPH_VERSION ≠ effectiveVersion = ctx.engineVersion, sets forceFullRebuild = true, skips the native orchestrator again, and the cycle repeats indefinitely. Before this PR the same schema-change scenario produced a two-build cycle via the Rust orchestrator; after the PR, this check closes the loop entirely in JS — every subsequent build is a wasted full rebuild.
The symmetric fix is needed in finalize.ts:
// persistBuildMetadata in finalize.ts
const codeVersionToWrite =
ctx.engineName === 'native' && ctx.engineVersion ? ctx.engineVersion : CODEGRAPH_VERSION;
// …then use codeVersionToWrite for the codegraph_version field in both branches
Codegraph Impact Analysis2 functions changed → 7 callers affected across 5 files
|
Summary
CODEGRAPH_VERSIONfrom package.json) and Rust (CARGO_PKG_VERSIONfrom Cargo.toml) that silently forced every native incremental build to be a full rebuildsetBuildMetanow writes the Rust addon version ascodegraph_version, andcheckEngineSchemaMismatchchecks against the engine version — both sides agreeRoot cause
Two independent version-mismatch checks fought over
codegraph_versioninbuild_meta:checkEngineSchemaMismatch): compared DB value against JSCODEGRAPH_VERSION(npm package version, e.g.3.9.3)check_version_mismatch): compared DB value againstCARGO_PKG_VERSION(Rust crate version, e.g.3.9.2)After a native build, JS wrote
3.9.3→ next build, Rust saw3.9.3 ≠ 3.9.2→ forced full rebuild. If Rust wrote3.9.2, JS saw3.9.2 ≠ 3.9.3→ setforceFullRebuild=true→ skipped native orchestrator → fell through to JS pipeline for a full rebuild.Benchmark results (before → after)
Test plan
codegraph_versioninbuild_metamatches Rust addon version after native buildCODEGRAPH_VERSIONas before)Related: #929 (edge accumulation in native incremental — separate issue)