* 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)
| 212 | * search misses (just leaves `cg` null so the next call can retry). |
| 213 | */ |
| 214 | async ensureInitialized(searchFrom: string): Promise<void> { |
| 215 | if (this.closed) return; |
| 216 | if (this.toolHandler.hasDefaultCodeGraph()) return; |
| 217 | if (this.initPromise) { |
| 218 | try { await this.initPromise; } catch { /* let caller retry */ } |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | this.initPromise = this.doInitialize(searchFrom).finally(() => { |
| 223 | this.initPromise = null; |
| 224 | }); |
| 225 | try { |
| 226 | await this.initPromise; |
| 227 | } catch { |
| 228 | // Init errors are logged inside `doInitialize`; falling through here |
| 229 | // matches MCPServer's previous "retry on next tool call" behavior. |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Synchronous last-resort init used by the per-session retry loop when the |