code-graph-context 2.10.0 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -174,6 +174,13 @@ export class EmbeddingSidecar {
|
|
|
174
174
|
});
|
|
175
175
|
if (!res.ok) {
|
|
176
176
|
const detail = await res.text();
|
|
177
|
+
const isOOM = detail.toLowerCase().includes('out of memory');
|
|
178
|
+
if (res.status === 500 && isOOM) {
|
|
179
|
+
// OOM leaves GPU memory in a corrupted state — kill the sidecar
|
|
180
|
+
// so the next request spawns a fresh process with clean memory
|
|
181
|
+
console.error('[embedding-sidecar] OOM detected, restarting sidecar to reclaim GPU memory');
|
|
182
|
+
await this.stop();
|
|
183
|
+
}
|
|
177
184
|
throw new Error(`Sidecar embed failed (${res.status}): ${detail}`);
|
|
178
185
|
}
|
|
179
186
|
const data = (await res.json());
|
|
@@ -183,6 +190,9 @@ export class EmbeddingSidecar {
|
|
|
183
190
|
}
|
|
184
191
|
catch (err) {
|
|
185
192
|
if (err instanceof Error && err.name === 'AbortError') {
|
|
193
|
+
// Timeout likely means the sidecar is stuck — kill it
|
|
194
|
+
console.error('[embedding-sidecar] Request timed out, restarting sidecar');
|
|
195
|
+
await this.stop();
|
|
186
196
|
throw new Error(`Embedding request timed out after ${this.config.requestTimeoutMs}ms`);
|
|
187
197
|
}
|
|
188
198
|
throw err;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { debugLog } from '../../mcp/utils.js';
|
|
7
7
|
import { getEmbeddingSidecar } from './embedding-sidecar.js';
|
|
8
8
|
const BATCH_CONFIG = {
|
|
9
|
-
maxBatchSize:
|
|
9
|
+
maxBatchSize: 8, // Small batches — 1.5B model on MPS OOMs at higher values on 16GB machines
|
|
10
10
|
};
|
|
11
11
|
export class LocalEmbeddingsService {
|
|
12
12
|
async embedText(text) {
|
|
@@ -20,12 +20,14 @@ export class LocalEmbeddingsService {
|
|
|
20
20
|
return sidecar.embed(texts);
|
|
21
21
|
}
|
|
22
22
|
async embedTextsInBatches(texts, batchSize = BATCH_CONFIG.maxBatchSize) {
|
|
23
|
+
// Cap batch size — callers (e.g. graph-generator) may pass 100 which OOMs the local model
|
|
24
|
+
const safeBatchSize = Math.min(batchSize, BATCH_CONFIG.maxBatchSize);
|
|
23
25
|
await debugLog('Batch embedding started', { provider: 'local', textCount: texts.length });
|
|
24
26
|
const sidecar = getEmbeddingSidecar();
|
|
25
27
|
const results = [];
|
|
26
|
-
const totalBatches = Math.ceil(texts.length /
|
|
27
|
-
for (let i = 0; i < texts.length; i +=
|
|
28
|
-
const batch = texts.slice(i, i +
|
|
28
|
+
const totalBatches = Math.ceil(texts.length / safeBatchSize);
|
|
29
|
+
for (let i = 0; i < texts.length; i += safeBatchSize) {
|
|
30
|
+
const batch = texts.slice(i, i + safeBatchSize);
|
|
29
31
|
const batchIndex = Math.floor(i / batchSize) + 1;
|
|
30
32
|
await debugLog('Embedding batch progress', {
|
|
31
33
|
provider: 'local',
|
package/dist/mcp/mcp.server.js
CHANGED
|
@@ -124,11 +124,13 @@ process.on('uncaughtException', async (error) => {
|
|
|
124
124
|
console.error(JSON.stringify({ level: 'error', message: 'Uncaught exception', error: String(error), stack: error.stack }));
|
|
125
125
|
await debugLog('Uncaught exception', { error: String(error), stack: error.stack });
|
|
126
126
|
await logServerStats('uncaught-exception');
|
|
127
|
+
await stopEmbeddingSidecar();
|
|
127
128
|
});
|
|
128
129
|
process.on('unhandledRejection', async (reason) => {
|
|
129
130
|
console.error(JSON.stringify({ level: 'error', message: 'Unhandled rejection', reason: String(reason) }));
|
|
130
131
|
await debugLog('Unhandled rejection', { reason: String(reason) });
|
|
131
132
|
await logServerStats('unhandled-rejection');
|
|
133
|
+
await stopEmbeddingSidecar();
|
|
132
134
|
});
|
|
133
135
|
// Log other process events that might indicate issues
|
|
134
136
|
process.on('warning', async (warning) => {
|
|
@@ -137,6 +139,7 @@ process.on('warning', async (warning) => {
|
|
|
137
139
|
process.on('beforeExit', async (code) => {
|
|
138
140
|
await debugLog('Process beforeExit', { code });
|
|
139
141
|
await logServerStats('before-exit');
|
|
142
|
+
await stopEmbeddingSidecar();
|
|
140
143
|
});
|
|
141
144
|
process.on('exit', (code) => {
|
|
142
145
|
// Note: Can't use async here, exit is synchronous
|
package/package.json
CHANGED