* Synchronous last-resort init used by the per-session retry loop when the * background `ensureInitialized` already finished (or failed) and we need * to pick up a project that appeared *after* the engine started.
(searchFrom: string)
| 162 | * to pick up a project that appeared *after* the engine started. |
| 163 | */ |
| 164 | retryInitializeSync(searchFrom: string): void { |
| 165 | if (this.closed) return; |
| 166 | if (this.toolHandler.hasDefaultCodeGraph()) return; |
| 167 | this.toolHandler.setDefaultProjectHint(searchFrom); |
| 168 | // Same resolution `doInitialize` used: up-walk, then the bounded workspace |
| 169 | // down-scan (#1606) — this retry is exactly the path that picks up a |
| 170 | // project (root or child) `codegraph init`'d after the server started. The |
| 171 | // down-scan is throttled so the persistent no-default state doesn't pay a |
| 172 | // directory walk on every tool call; the up-walk always runs. |
| 173 | const scanDue = Date.now() - this.lastRetrySubScanAt >= RETRY_SUBSCAN_TTL_MS; |
| 174 | const res = resolveServerRoot(searchFrom, { subprojectScan: scanDue }); |
| 175 | if (scanDue) { |
| 176 | this.lastRetrySubScanAt = Date.now(); |
| 177 | if (!res.root) this.toolHandler.setKnownSubprojects(res.candidates, searchFrom); |
| 178 | } |
| 179 | const resolvedRoot = res.root; |
| 180 | if (!resolvedRoot) return; |
| 181 | if (res.viaSubScan) this.logSubprojectAdoption(searchFrom, resolvedRoot); |
| 182 | try { |
| 183 | // Close any previously failed instance to avoid leaking resources. |
| 184 | if (this.cg) { |
| 185 | try { this.cg.close(); } catch { /* ignore */ } |
| 186 | this.cg = null; |
| 187 | } |
| 188 | this.cg = loadCodeGraph().openSync(resolvedRoot); |
| 189 | this.projectPath = resolvedRoot; |
| 190 | this.toolHandler.setDefaultCodeGraph(this.cg); |
| 191 | this.startWatching(); |
| 192 | this.catchUpSync(); |
| 193 | this.maybeStartPool(resolvedRoot); |
| 194 | } catch { |
| 195 | // Still failing — caller will try again on the next tool call. |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Close everything. Used on graceful daemon shutdown (SIGTERM/idle timeout) |
no test coverage detected