fix: prevent ONNX model cache corruption from bun cache clears
Remove nuclear `bun pm cache rm` from smart-install.js and sync-marketplace.cjs (only needed for removed sharp dependency). Add `bun install` in cache version directory after sync so worker can resolve dependencies. Move HuggingFace model cache to ~/.claude-mem/models/ so reinstalls don't corrupt it. Add self-healing retry for Protobuf parsing failures. Fixes recurring issues #1104, #1105, #1110. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+316
-269
File diff suppressed because one or more lines are too long
@@ -263,14 +263,6 @@ function installDeps() {
|
|||||||
// Quote path for Windows paths with spaces
|
// Quote path for Windows paths with spaces
|
||||||
const bunCmd = IS_WINDOWS && bunPath.includes(' ') ? `"${bunPath}"` : bunPath;
|
const bunCmd = IS_WINDOWS && bunPath.includes(' ') ? `"${bunPath}"` : bunPath;
|
||||||
|
|
||||||
// Clear Bun's package cache to prevent stale native module artifacts
|
|
||||||
try {
|
|
||||||
execSync(`${bunCmd} pm cache rm`, { cwd: ROOT, stdio: 'pipe', shell: IS_WINDOWS });
|
|
||||||
console.error(' Cleared Bun package cache');
|
|
||||||
} catch {
|
|
||||||
// Cache may not exist yet on first install
|
|
||||||
}
|
|
||||||
|
|
||||||
execSync(`${bunCmd} install`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS });
|
execSync(`${bunCmd} install`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS });
|
||||||
|
|
||||||
// Write version marker
|
// Write version marker
|
||||||
|
|||||||
@@ -80,14 +80,6 @@ try {
|
|||||||
{ stdio: 'inherit' }
|
{ stdio: 'inherit' }
|
||||||
);
|
);
|
||||||
|
|
||||||
// Clear Bun's package cache to prevent stale native module artifacts
|
|
||||||
try {
|
|
||||||
execSync('bun pm cache rm', { cwd: INSTALLED_PATH, stdio: 'pipe' });
|
|
||||||
console.log('Cleared Bun package cache');
|
|
||||||
} catch {
|
|
||||||
// Cache may not exist yet on first install
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Running bun install in marketplace...');
|
console.log('Running bun install in marketplace...');
|
||||||
execSync(
|
execSync(
|
||||||
'cd ~/.claude/plugins/marketplaces/thedotmack/ && bun install',
|
'cd ~/.claude/plugins/marketplaces/thedotmack/ && bun install',
|
||||||
@@ -107,6 +99,10 @@ try {
|
|||||||
{ stdio: 'inherit' }
|
{ stdio: 'inherit' }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Install dependencies in cache directory so worker can resolve them
|
||||||
|
console.log(`Running bun install in cache folder (version ${version})...`);
|
||||||
|
execSync(`bun install`, { cwd: CACHE_VERSION_PATH, stdio: 'inherit' });
|
||||||
|
|
||||||
console.log('\x1b[32m%s\x1b[0m', 'Sync complete!');
|
console.log('\x1b[32m%s\x1b[0m', 'Sync complete!');
|
||||||
|
|
||||||
// Trigger worker restart after file sync
|
// Trigger worker restart after file sync
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export class ChromaSync {
|
|||||||
private collectionName: string;
|
private collectionName: string;
|
||||||
private readonly VECTOR_DB_DIR: string;
|
private readonly VECTOR_DB_DIR: string;
|
||||||
private readonly BATCH_SIZE = 100;
|
private readonly BATCH_SIZE = 100;
|
||||||
|
private modelCacheCorruptionRetried = false;
|
||||||
|
|
||||||
constructor(project: string) {
|
constructor(project: string) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
@@ -189,6 +190,10 @@ export class ChromaSync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Store model cache outside node_modules so reinstalls don't corrupt it
|
||||||
|
const { env } = await import('@huggingface/transformers');
|
||||||
|
env.cacheDir = path.join(os.homedir(), '.claude-mem', 'models');
|
||||||
|
|
||||||
// Use WASM backend to avoid native ONNX binary issues (#1104, #1105, #1110).
|
// Use WASM backend to avoid native ONNX binary issues (#1104, #1105, #1110).
|
||||||
// Same model (all-MiniLM-L6-v2), same embeddings, but runs in WASM —
|
// Same model (all-MiniLM-L6-v2), same embeddings, but runs in WASM —
|
||||||
// no native binary loading, no segfaults, no ENOENT errors.
|
// no native binary loading, no segfaults, no ENOENT errors.
|
||||||
@@ -204,8 +209,22 @@ export class ChromaSync {
|
|||||||
collection: this.collectionName
|
collection: this.collectionName
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
|
||||||
|
// Self-heal: corrupted model cache → clear and retry once
|
||||||
|
if (errorMessage.includes('Protobuf parsing failed') && !this.modelCacheCorruptionRetried) {
|
||||||
|
this.modelCacheCorruptionRetried = true;
|
||||||
|
logger.warn('CHROMA_SYNC', 'Corrupted model cache detected, clearing and retrying...');
|
||||||
|
const modelCacheDir = path.join(os.homedir(), '.claude-mem', 'models');
|
||||||
|
const fs = await import('fs');
|
||||||
|
if (fs.existsSync(modelCacheDir)) {
|
||||||
|
fs.rmSync(modelCacheDir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
return this.ensureCollection(); // retry once
|
||||||
|
}
|
||||||
|
|
||||||
logger.error('CHROMA_SYNC', 'Failed to get/create collection', { collection: this.collectionName }, error as Error);
|
logger.error('CHROMA_SYNC', 'Failed to get/create collection', { collection: this.collectionName }, error as Error);
|
||||||
throw new Error(`Collection setup failed: ${error instanceof Error ? error.message : String(error)}`);
|
throw new Error(`Collection setup failed: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user