MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / onWorkerGone

Method onWorkerGone

src/mcp/query-pool.ts:439–459  ·  view source on GitHub ↗
(w: PoolWorker)

Source from the content-addressed store, hash-verified

437 // retry its in-flight job once; a job that keeps crashing workers fails
438 // gracefully so it can't loop the pool forever.
439 private onWorkerGone(w: PoolWorker): void {
440 if (!this.workers.has(w)) return; // already handled (error+exit both fire)
441 this.workers.delete(w);
442 this.pendingWorkers.delete(w);
443 this.idle = this.idle.filter((x) => x !== w);
444 this.totalCrashes++;
445 const job = this.inflight.get(w);
446 this.inflight.delete(w);
447 try { void w.terminate(); } catch { /* already gone */ }
448 if (this.healthy) this.spawnOne(); // keep capacity
449 if (job) {
450 if (job.retries < this.maxRetries && this.healthy) {
451 job.retries++;
452 job.startedAt = undefined; // waiting again, for the worker that replaces this one
453 this.queue.unshift(job); // head of line — retry promptly
454 } else {
455 this.settle(job, { isError: true, content: [{ type: 'text', text: 'codegraph worker crashed; please retry the call.' }] });
456 }
457 }
458 this.drain();
459 }
460
461 private drain(): void {
462 // Grow toward maxSize while queued work outstrips workers that are idle OR

Callers 2

spawnOneMethod · 0.95
onMessageMethod · 0.95

Calls 7

spawnOneMethod · 0.95
settleMethod · 0.95
drainMethod · 0.95
hasMethod · 0.80
deleteMethod · 0.65
getMethod · 0.65
terminateMethod · 0.65

Tested by

no test coverage detected