Skip to content

Commit a92f145

Browse files
committed
fix: fall back to in-process clustering in source mode
1 parent 8217e7e commit a92f145

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/api-core/src/service.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,8 @@ export class GHCrawlService {
29882988
return aggregated;
29892989
}
29902990

2991-
const shouldParallelize = sourceKinds.length > 1 && totalItems >= CLUSTER_PARALLEL_MIN_EMBEDDINGS && os.availableParallelism() > 1;
2991+
const workerRuntime = this.resolveEdgeWorkerRuntime();
2992+
const shouldParallelize = workerRuntime !== null && sourceKinds.length > 1 && totalItems >= CLUSTER_PARALLEL_MIN_EMBEDDINGS && os.availableParallelism() > 1;
29922993
if (!shouldParallelize) {
29932994
const rows = this.loadParsedStoredEmbeddings(repoId);
29942995
const bySource = new Map<EmbeddingSourceKind, Array<{ id: number; normalizedEmbedding: number[] }>>();
@@ -3019,14 +3020,13 @@ export class GHCrawlService {
30193020
return aggregated;
30203021
}
30213022

3022-
const workerUrl = this.resolveEdgeWorkerUrl();
30233023
const progressBySource = new Map<EmbeddingSourceKind, { processedItems: number; totalItems: number; currentEdgeEstimate: number }>();
30243024

30253025
const edgeSets = await Promise.all(
30263026
sourceKinds.map(
30273027
(sourceKind) =>
30283028
new Promise<Array<{ leftThreadId: number; rightThreadId: number; score: number }>>((resolve, reject) => {
3029-
const worker = new Worker(workerUrl, {
3029+
const worker = new Worker(workerRuntime.url, {
30303030
workerData: {
30313031
dbPath: this.config.dbPath,
30323032
repoId,
@@ -3121,12 +3121,13 @@ export class GHCrawlService {
31213121
return row.count;
31223122
}
31233123

3124-
private resolveEdgeWorkerUrl(): URL {
3124+
private resolveEdgeWorkerRuntime(): { url: URL } | null {
31253125
const jsUrl = new URL('./cluster/edge-worker.js', import.meta.url);
31263126
if (existsSync(fileURLToPath(jsUrl))) {
3127-
return jsUrl;
3127+
return { url: jsUrl };
31283128
}
3129-
return new URL('./cluster/edge-worker.ts', import.meta.url);
3129+
// Source-mode runs do not have a compiled worker entrypoint, so keep clustering in-process.
3130+
return null;
31303131
}
31313132

31323133
private persistClusterRun(

0 commit comments

Comments
 (0)