Skip to content

Commit e3edd63

Browse files
authored
fix(build): warn before --no-incremental wipes embeddings (#986)
* fix(build): warn before --no-incremental wipes embeddings A full rebuild (either via --no-incremental or when promoted by an engine/ schema/version mismatch) silently drops every row from the embeddings table. Users who just spent minutes generating embeddings lose them with no warning, and subsequent \`codegraph search\` returns zero hits with no indication why. Add a warnOnEmbeddingsWipe step to setupPipeline that runs after the incremental/forceFullRebuild decision is made. When the build will be full AND the embeddings table is non-empty, log: Full rebuild will discard N embeddings; re-run \`codegraph embed\` after the build. The warning sits at the pipeline entry, so it fires uniformly for the native orchestrator and the JS fallback path. It is silent when the embeddings table is missing, empty, or when the build is incremental. Closes #982 * fix(build): re-check embeddings on native-orchestrator version mismatch (#986) The catch block that handles native-orchestrator throws performs a late promotion to a full rebuild when the codegraph_version mismatch is detected. warnOnEmbeddingsWipe already ran in setupPipeline before forceFullRebuild was set here, so this path previously wiped embeddings silently — exactly the scenario the initial guard was meant to close. Call warnOnEmbeddingsWipe again after setting ctx.forceFullRebuild = true so the late-promotion path surfaces the same warning as the other full rebuild paths. Impact: 1 functions changed, 6 affected
1 parent badeaed commit e3edd63

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/domain/graph/builder/pipeline.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ function checkEngineSchemaMismatch(ctx: PipelineContext): void {
106106
}
107107
}
108108

109+
function warnOnEmbeddingsWipe(ctx: PipelineContext): void {
110+
const willBeFullBuild = !ctx.incremental || ctx.forceFullRebuild;
111+
if (!willBeFullBuild) return;
112+
let count = 0;
113+
try {
114+
count = (ctx.db.prepare('SELECT COUNT(*) AS c FROM embeddings').get() as { c: number }).c;
115+
} catch {
116+
return; // embeddings table missing — nothing to warn about
117+
}
118+
if (count === 0) return;
119+
warn(
120+
`Full rebuild will discard ${count} embedding${count === 1 ? '' : 's'}; re-run \`codegraph embed\` after the build.`,
121+
);
122+
}
123+
109124
function loadAliases(ctx: PipelineContext): void {
110125
ctx.aliases = loadPathAliases(ctx.rootDir);
111126
if (ctx.config.aliases) {
@@ -151,6 +166,7 @@ function setupPipeline(ctx: PipelineContext): void {
151166

152167
initializeEngine(ctx);
153168
checkEngineSchemaMismatch(ctx);
169+
warnOnEmbeddingsWipe(ctx);
154170
loadAliases(ctx);
155171

156172
// Workspace packages (monorepo)
@@ -960,6 +976,10 @@ export async function buildGraph(
960976
`Codegraph version changed (${prevVersion}${CODEGRAPH_VERSION}), promoting to full rebuild.`,
961977
);
962978
ctx.forceFullRebuild = true;
979+
// Re-check embeddings: the initial warnOnEmbeddingsWipe ran before
980+
// forceFullRebuild was set here, so the silent-data-loss guard
981+
// would otherwise miss this late-promotion path (#986 follow-up).
982+
warnOnEmbeddingsWipe(ctx);
963983
}
964984
}
965985
}

0 commit comments

Comments
 (0)