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

Method ensureInitialized

src/mcp/engine.ts:240–257  ·  view source on GitHub ↗

* Walk up from `searchFrom` to find the nearest `.codegraph/` and open it. * Idempotent: concurrent callers share one in-flight init; subsequent * callers after success are no-ops. * * The original `MCPServer.tryInitializeDefault` carried the same retry-on- * subsequent-tool-call sema

(searchFrom: string)

Source from the content-addressed store, hash-verified

238 * search misses (just leaves `cg` null so the next call can retry).
239 */
240 async ensureInitialized(searchFrom: string): Promise<void> {
241 if (this.closed) return;
242 if (this.toolHandler.hasDefaultCodeGraph()) return;
243 if (this.initPromise) {
244 try { await this.initPromise; } catch { /* let caller retry */ }
245 return;
246 }
247
248 this.initPromise = this.doInitialize(searchFrom).finally(() => {
249 this.initPromise = null;
250 });
251 try {
252 await this.initPromise;
253 } catch {
254 // Init errors are logged inside `doInitialize`; falling through here
255 // matches MCPServer's previous "retry on next tool call" behavior.
256 }
257 }
258
259 /**
260 * Synchronous last-resort init used by the per-session retry loop when the

Callers 15

startMethod · 0.80
startDirectMethod · 0.80
ensureEngineFunction · 0.80
handleInitializeMethod · 0.80
retryInitIfNeededMethod · 0.80
initFromRootsMethod · 0.80
security.test.tsFile · 0.80
startFunction · 0.80
query-pool.test.tsFile · 0.80
openEngineFunction · 0.80

Calls 2

doInitializeMethod · 0.95
hasDefaultCodeGraphMethod · 0.45

Tested by 2

startFunction · 0.64
openEngineFunction · 0.64