Skip to content

Commit 762ab9d

Browse files
committed
fix(reranker): narrow initFailed guard to corrupt-cache errors only
Transient load failures (network, timeout, etc.) now reset initPromise=null so the next call can retry. Only Protobuf/parse/corrupt errors are marked permanently failed — those require a cache re-download in a new session. Long-lived MCP servers can now recover from transient load failures without requiring a restart. Addresses grey-area identified during PR #95 Greptile audit.
1 parent 37b43cd commit 762ab9d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/core/reranker.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ async function ensureModelLoaded(): Promise<void> {
7676
console.error('[reranker] Cross-encoder loaded successfully');
7777
} catch (err) {
7878
const msg = err instanceof Error ? err.message : String(err);
79-
if (msg.includes('Protobuf') || msg.includes('parse') || msg.includes('corrupt')) {
79+
const isCorrupt =
80+
msg.includes('Protobuf') || msg.includes('parse') || msg.includes('corrupt');
81+
82+
if (isCorrupt) {
8083
// Corrupted cache — clear it so next session re-downloads
8184
console.error(`[reranker] Cache corruption detected: ${msg}`);
8285
console.error('[reranker] Clearing corrupted cache. Next startup will re-download.');
@@ -93,9 +96,15 @@ async function ensureModelLoaded(): Promise<void> {
9396
} catch {
9497
// Cache clear is best-effort
9598
}
99+
rerankerHealth = 'unavailable';
100+
// Permanent fail — corrupt cache can't be retried in this session.
101+
initFailed = true;
102+
throw err;
96103
}
104+
105+
// Transient error (network, timeout, etc.) — allow retry on next call.
97106
rerankerHealth = 'unavailable';
98-
initFailed = true;
107+
initPromise = null;
99108
throw err;
100109
}
101110
})();

0 commit comments

Comments
 (0)