chore: bump version to 10.0.4

Reverts v10.0.3 chroma-mcp spawn storm fix (broken release).
Restores codebase to v10.0.2 state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2026-02-11 21:36:34 -05:00
parent 0dda593c45
commit 98d87d7573
13 changed files with 213 additions and 709 deletions
+20 -156
View File
@@ -18,16 +18,12 @@ import { USER_SETTINGS_PATH } from '../../shared/paths.js';
import path from 'path';
import os from 'os';
import fs from 'fs';
import { execSync, execFileSync } from 'child_process';
import { parseElapsedTime } from '../infrastructure/ProcessManager.js';
import { execSync } from 'child_process';
// Version injected at build time by esbuild define
declare const __DEFAULT_PACKAGE_VERSION__: string;
const packageVersion = typeof __DEFAULT_PACKAGE_VERSION__ !== 'undefined' ? __DEFAULT_PACKAGE_VERSION__ : '0.0.0-dev';
// Maximum allowed chroma-mcp processes before pre-spawn guard kills excess
const MAX_CHROMA_PROCESSES = 2; // 1 active + 1 starting
interface ChromaDocument {
id: string;
document: string;
@@ -94,16 +90,6 @@ export class ChromaSync {
// MCP SDK's StdioClientTransport uses shell:false and no detached flag, so console is inherited.
private readonly disabled: boolean = false;
// Layer 0: Connection mutex — coalesces concurrent callers onto single spawn
private connectionPromise: Promise<void> | null = null;
// Layer 4: Circuit breaker — stops retry storms after repeated failures
private consecutiveFailures: number = 0;
private lastFailureTime: number = 0;
private static readonly MAX_FAILURES = 3;
private static readonly BACKOFF_BASE_MS = 2000;
private static readonly CIRCUIT_OPEN_MS = 60000; // 1 minute cooldown
constructor(project: string) {
this.project = project;
this.collectionName = `cm__${project}`;
@@ -192,114 +178,14 @@ export class ChromaSync {
}
/**
* Ensure MCP client is connected to Chroma server (mutex wrapper).
* Coalesces concurrent callers onto a single connection attempt.
* This prevents N concurrent calls from each spawning a chroma-mcp subprocess.
* Ensure MCP client is connected to Chroma server
* Throws error if connection fails
*/
private async ensureConnection(): Promise<void> {
if (this.connected && this.client) return;
// Layer 0: Coalesce concurrent callers onto a single connection attempt
if (this.connectionPromise) {
return this.connectionPromise;
if (this.connected && this.client) {
return;
}
this.connectionPromise = this._doConnect();
try {
await this.connectionPromise;
} finally {
this.connectionPromise = null;
}
}
/**
* Layer 4: Circuit breaker — refuse to spawn after repeated failures.
* After MAX_FAILURES consecutive connection failures, stops all spawn
* attempts for CIRCUIT_OPEN_MS to prevent process accumulation storms.
*/
private checkCircuitBreaker(): void {
if (this.consecutiveFailures >= ChromaSync.MAX_FAILURES) {
const elapsed = Date.now() - this.lastFailureTime;
if (elapsed < ChromaSync.CIRCUIT_OPEN_MS) {
throw new Error(
`Chroma circuit breaker open: ${this.consecutiveFailures} consecutive failures. ` +
`Retry in ${Math.ceil((ChromaSync.CIRCUIT_OPEN_MS - elapsed) / 1000)}s`
);
}
// Cooldown expired, allow retry
logger.info('CHROMA_SYNC', 'Circuit breaker cooldown expired, allowing retry', {
consecutiveFailures: this.consecutiveFailures,
cooldownMs: ChromaSync.CIRCUIT_OPEN_MS
});
}
}
/**
* Layer 1: Pre-spawn process count guard.
* Kills excess chroma-mcp processes before spawning a new one.
* Uses execFileSync (no shell) to list processes, filters in JavaScript.
*/
private killExcessChromaProcesses(): void {
if (process.platform === 'win32') return; // Windows has Chroma disabled entirely
try {
// Use execFileSync to avoid shell injection — filter and sort in JavaScript
// Include etime column for reliable age-based sorting (PID order is unreliable)
const output = execFileSync('ps', ['-eo', 'pid,etime,command'], {
encoding: 'utf8',
timeout: 5000,
stdio: ['pipe', 'pipe', 'pipe']
});
// Filter for chroma-mcp, parse elapsed time, sort by actual age
const processes = output.split('\n')
.filter(l => l.includes('chroma-mcp'))
.map(l => {
const parts = l.trim().split(/\s+/);
const pid = parseInt(parts[0], 10);
const etime = parts[1] || '';
const ageMinutes = parseElapsedTime(etime);
return { pid, ageMinutes };
})
.filter(p => p.pid > 0 && p.pid !== process.pid && p.ageMinutes >= 0)
.sort((a, b) => a.ageMinutes - b.ageMinutes); // Ascending: newest (lowest age) first
if (processes.length < MAX_CHROMA_PROCESSES) return;
// Keep newest MAX_CHROMA_PROCESSES - 1 (making room for the one we're about to spawn)
const toKill = processes.slice(MAX_CHROMA_PROCESSES - 1);
for (const { pid } of toKill) {
try {
process.kill(pid, 'SIGTERM');
} catch {
// Process may already be dead
}
}
if (toKill.length > 0) {
logger.warn('CHROMA_SYNC', 'Killed excess chroma-mcp processes before spawning', {
found: processes.length,
killed: toKill.length,
maxAllowed: MAX_CHROMA_PROCESSES
});
}
} catch {
// ps may fail — don't block connection
}
}
/**
* Internal connection logic — called only via ensureConnection() mutex.
* Implements circuit breaker (Layer 4), pre-spawn guard (Layer 1),
* and actual connection setup.
*/
private async _doConnect(): Promise<void> {
// Layer 4: Circuit breaker check — refuse if too many recent failures
this.checkCircuitBreaker();
// Layer 1: Kill excess processes before spawning a new one
this.killExcessChromaProcesses();
logger.info('CHROMA_SYNC', 'Connecting to Chroma MCP server...', { project: this.project });
try {
@@ -352,20 +238,9 @@ export class ChromaSync {
await this.client.connect(this.transport);
this.connected = true;
// Layer 4: Reset circuit breaker on success
this.consecutiveFailures = 0;
logger.info('CHROMA_SYNC', 'Connected to Chroma MCP server', { project: this.project });
} catch (error) {
// Layer 4: Track failure for circuit breaker
this.consecutiveFailures++;
this.lastFailureTime = Date.now();
logger.error('CHROMA_SYNC', 'Failed to connect to Chroma MCP server', {
project: this.project,
consecutiveFailures: this.consecutiveFailures,
circuitBreakerThreshold: ChromaSync.MAX_FAILURES
}, error as Error);
logger.error('CHROMA_SYNC', 'Failed to connect to Chroma MCP server', { project: this.project }, error as Error);
throw new Error(`Chroma connection failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
@@ -416,7 +291,6 @@ export class ChromaSync {
this.connected = false;
this.client = null;
this.transport = null;
this.connectionPromise = null;
logger.error('CHROMA_SYNC', 'Connection lost during collection check',
{ collection: this.collectionName }, error as Error);
throw new Error(`Chroma connection lost: ${errorMessage}`);
@@ -1086,7 +960,6 @@ export class ChromaSync {
this.connected = false;
this.client = null;
this.transport = null;
this.connectionPromise = null;
logger.error('CHROMA_SYNC', 'Connection lost during query',
{ project: this.project, query }, error as Error);
throw new Error(`Chroma query failed - connection lost: ${errorMessage}`);
@@ -1144,37 +1017,28 @@ export class ChromaSync {
}
/**
* Close the Chroma client connection and cleanup subprocess.
* Uses try-finally to guarantee state reset even if close() throws.
* Individual close calls use .catch() to prevent one failure from
* blocking the other (e.g., client.close() failing shouldn't prevent
* transport.close() from killing the subprocess).
* Close the Chroma client connection and cleanup subprocess
*/
async close(): Promise<void> {
if (!this.connected && !this.client && !this.transport) {
return;
}
try {
// Close client first, then transport — catch individual errors
if (this.client) {
await this.client.close().catch((err: Error) => {
logger.debug('CHROMA_SYNC', 'Client close error (may already be disconnected)', {}, err);
});
}
if (this.transport) {
await this.transport.close().catch((err: Error) => {
logger.debug('CHROMA_SYNC', 'Transport close error (may already be dead)', {}, err);
});
}
} finally {
// Always reset state, even if close throws
this.connected = false;
this.client = null;
this.transport = null;
this.connectionPromise = null;
// Close client first
if (this.client) {
await this.client.close();
}
// Explicitly close transport to kill subprocess
if (this.transport) {
await this.transport.close();
}
logger.info('CHROMA_SYNC', 'Chroma client and subprocess closed', { project: this.project });
// Always reset state
this.connected = false;
this.client = null;
this.transport = null;
}
}