* 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)
| 131 | * search misses (just leaves `cg` null so the next call can retry). |
| 132 | */ |
| 133 | async ensureInitialized(searchFrom: string): Promise<void> { |
| 134 | if (this.closed) return; |
| 135 | if (this.toolHandler.hasDefaultCodeGraph()) return; |
| 136 | if (this.initPromise) { |
| 137 | try { await this.initPromise; } catch { /* let caller retry */ } |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | this.initPromise = this.doInitialize(searchFrom).finally(() => { |
| 142 | this.initPromise = null; |
| 143 | }); |
| 144 | try { |
| 145 | await this.initPromise; |
| 146 | } catch { |
| 147 | // Init errors are logged inside `doInitialize`; falling through here |
| 148 | // matches MCPServer's previous "retry on next tool call" behavior. |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Synchronous last-resort init used by the per-session retry loop when the |
no test coverage detected