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

Method onMessage

src/mcp/query-pool.ts:286–315  ·  view source on GitHub ↗
(w: PoolWorker, m: WorkerMessage)

Source from the content-addressed store, hash-verified

284 }
285
286 private onMessage(w: PoolWorker, m: WorkerMessage): void {
287 // Before the retired-worker check: destroy() waits on this for a worker
288 // it has already let go of.
289 if (m?.type === 'ready') this.startSettled(w);
290 if (!m || !this.workers.has(w)) return; // ignore late messages from retired workers
291 if (m.type === 'ready') {
292 if (!this.pendingWorkers.delete(w)) return; // already handled this handshake
293 if (m.ok === false) {
294 this.onWorkerGone(w); // failed opens consume the same budget as crashes
295 return;
296 }
297 this.everReady = true;
298 this.idle.push(w);
299 this.drain();
300 this.armIdleShrink(); // the last result may have come while this one started
301 return;
302 }
303 if (m.type === 'result') {
304 const job = this.inflight.get(w);
305 this.inflight.delete(w);
306 this.idle.push(w);
307 this.servedSinceShrink = true;
308 this.lastServer = w;
309 if (job) this.settle(job, m.result ?? busyGuidance(0));
310 this.drain();
311 this.armIdleShrink();
312 return;
313 }
314 if (m.type === 'trimmed') this.replaceIfHeavy(w, m.heldBytes ?? 0);
315 }
316
317 /** Nothing queued or running, nothing starting, and every worker free. */
318 private get quiescent(): boolean {

Callers 1

spawnOneMethod · 0.95

Calls 11

startSettledMethod · 0.95
onWorkerGoneMethod · 0.95
drainMethod · 0.95
armIdleShrinkMethod · 0.95
settleMethod · 0.95
replaceIfHeavyMethod · 0.95
busyGuidanceFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
deleteMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected