fix: native visibility crash and dual-SQLite WAL corruption in benchmarks#689
fix: native visibility crash and dual-SQLite WAL corruption in benchmarks#689carlos-alm merged 6 commits intomainfrom
Conversation
…fields (#687) napi-rs v3 handles `undefined` → `Option<T>::None` correctly but fails when it sees `null` — it attempts String conversion instead of treating it as None. The marshaling code in insert-nodes.ts explicitly coerced `undefined` visibility/endLine fields to `null` via `?? null`, triggering a crash on every codebase (parameters never have visibility set). Remove the `?? null` coercion so `undefined` flows through naturally.
…L corruption (#688) When engine is 'wasm', insertNodes writes via better-sqlite3 but other stages (buildStructure, classifyRoles, finalize, buildEdges, detectChanges) read/write via nativeDb (rusqlite). Both bundle their own SQLite copy — two bundled SQLite instances accessing the same WAL file causes corruption: "database disk image is malformed". Gate all nativeDb read/write usage in pipeline stages on `ctx.engineName === 'native'` so the same SQLite library handles all operations within a single build. nativeDb is still opened for schema init (safe — happens before WAL divergence) and closed at finalize.
|
Claude finished @carlos-alm's task —— View job PR Review: Native Visibility Crash and Dual-SQLite WAL Corruption FixTodo List:
Root Cause AnalysisProblem Being Solved: Two critical bugs causing all v3.5.0 benchmarks to fail:
Why This Approach: Both fixes are minimal and surgical:
Risk Assessment: Very low risk. These are defensive changes that prevent dual-engine access patterns rather than changing core logic. Configuration/Test Integrity Assessment✅ No problematic changes detected:
Code Quality Assessment✅ High quality fixes:
Technical Accuracy:
Backlog Compliance
Critical AssessmentStrengths:
Potential Concerns:
Verification: The PR commits (5fa6804, 94afe7e) are already on the branch, indicating these fixes have been tested and proven to resolve the benchmark failures. Final RecommendationThis PR demonstrates exemplary bug-fixing: precise root cause analysis, minimal surgical changes, consistent implementation patterns, and direct resolution of critical production issues. The dual-engine architecture complexity is handled correctly with proper defensive guards. |
Greptile SummaryThis PR fixes two independent crashes that caused all v3.5.0 benchmarks to fail. It gates every Key changes:
Confidence Score: 5/5Safe to merge — both crash paths are definitively fixed, 85/85 integration tests pass, and the changes are tightly scoped with no logic regressions. All changes are focused bug fixes with clear root-cause analysis. The pipeline.ts fix directly addresses the WAL corruption in the only window where both SQLite connections are simultaneously open. Stage-file guards are consistent and correct. The types.ts change aligns the interface with the companion insert-nodes.ts fix. No P0 or P1 issues found. No files require special attention. All changed files have confidence 5/5. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[setupPipeline] --> B["open ctx.db via better-sqlite3"]
B --> C["open ctx.nativeDb via rusqlite (if native addon available)"]
C --> D[checkEngineSchemaMismatch]
D --> E{"ctx.engineName === 'native'?"}
E -- "Yes (native engine)" --> F["read metadata via ctx.nativeDb"]
E -- "No (WASM engine)" --> G["read metadata via ctx.db (better-sqlite3)"]
F --> H[setupPipeline complete]
G --> H
H --> I[runPipelineStages]
I --> J["close ctx.nativeDb, set to undefined (pre-existing guard)"]
J --> K[Pipeline stages run]
K --> L["Stage guards: engineName==='native' checks (defensive)"]
L --> M[All DB ops use ctx.db path in both engines]
Reviews (3): Last reviewed commit: "fix: resolve merge conflicts with main" | Re-trigger Greptile |
…n DB corruption (#689) setupPipeline opens both better-sqlite3 and rusqlite on the same WAL file. When the engine resolves to wasm, concurrent connections corrupt the DB. Close nativeDb at the start of runPipelineStages so all stages use JS fallback paths exclusively. Also disable tryNativeInsert when ctx.db exists, narrow type annotations to remove stale | null that could invite regression, and always run JS initSchema even when nativeDb succeeds.
When native addon is available, openRepo returns NativeRepository. annotateDataflow checked instanceof SqliteRepository and silently skipped dataflow annotation. Open a separate readonly better-sqlite3 connection when the repo is not SqliteRepository so dataflow return arrows and parameter labels work regardless of engine.
|
Both P2 findings addressed in 95d03f2 and 97158c0: 1. Stale 2. Residual idle rusqlite connection in WASM mode — Implemented the suggested approach: Also fixed a third issue found during CI investigation: All 2178 tests pass, lint clean, TypeScript compiles. |
Summary
Fixes two bugs that caused all v3.5.0 benchmarks to fail (both engines crashed during graph build):
Native engine (fix(native): napi-rs null visibility crashes insertNodes #687): napi-rs v3
Option<String>fails on JSnullbut handlesundefinedcorrectly. The marshaling code ininsert-nodes.tscoercedundefinedvisibility fields tonullvia?? null, crashing on every codebase since parameters never set visibility. Fix: remove?? nullcoercion.WASM engine (fix(db): dual-SQLite WAL corruption when nativeDb reads after better-sqlite3 writes #688): When native addon is available,
setupPipelineopens both better-sqlite3 and rusqlite (nativeDb) on the same DB. In WASM mode, inserts go through better-sqlite3 but reads inbuildStructure/classifyRoles/finalize/buildEdges/detectChangesgo through rusqlite — two bundled SQLite copies on the same WAL = corruption. Fix: gate allnativeDbusage onctx.engineName === 'native'.Closes #687, closes #688.
Test plan
npm run build)npm run lint)