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

Method retryInitializeSync

src/mcp/engine.ts:164–197  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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)

Callers 1

retryInitIfNeededMethod · 0.80

Calls 12

logSubprojectAdoptionMethod · 0.95
startWatchingMethod · 0.95
catchUpSyncMethod · 0.95
maybeStartPoolMethod · 0.95
resolveServerRootFunction · 0.90
setDefaultProjectHintMethod · 0.80
setKnownSubprojectsMethod · 0.80
openSyncMethod · 0.80
setDefaultCodeGraphMethod · 0.80
loadCodeGraphFunction · 0.70
closeMethod · 0.65
hasDefaultCodeGraphMethod · 0.45

Tested by

no test coverage detected