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

Method sync

src/index.ts:1168–1991  ·  view source on GitHub ↗
(options: IndexOptions = {})

Source from the content-addressed store, hash-verified

1166 }
1167
1168 async sync(options: IndexOptions = {}): Promise<SyncResult> {
1169 const {
1170 ESM_IMPORT_LANGUAGES,
1171 aliasMayName,
1172 changedModuleConfigs,
1173 changedRoutes,
1174 createImportReader,
1175 hasSynthesisPattern,
1176 isJsxChildCandidate,
1177 moduleConfigLanguages,
1178 parseManifestStamp,
1179 parseModuleConfigSnapshot,
1180 reopenNameMatchedImports,
1181 reopenReferencesThroughAddedFiles,
1182 reopenReferencesThroughBarrels,
1183 reopenReferencesThroughChangedDefaults,
1184 reopenReferencesThroughDeclaredPackages,
1185 reopenReferencesThroughObjectMembers,
1186 reopenReferencesThroughRetargetedModules,
1187 trustedManifestList,
1188 } = engine();
1189 return this.indexMutex.withLock(async () => {
1190 const startedAt = Date.now();
1191 try {
1192 this.fileLock.acquire();
1193 } catch (err) {
1194 throw new LockUnavailableError(
1195 `Sync could not acquire the file lock; retry when the index is available. ${err instanceof Error ? err.message : String(err)}`
1196 );
1197 }
1198 // A full rebuild in another process (`codegraph index` → recreate)
1199 // unlinks the database and creates a new file at the same path. A
1200 // long-lived instance — the MCP daemon's watcher — would otherwise keep
1201 // "syncing" into the dead inode, and nothing it wrote there is visible
1202 // to anyone (#1902). Follow the path before writing (one stat), and
1203 // widen a scoped sync to a full one: whatever the old handle absorbed
1204 // since the rebuild is gone, so the new file has to be reconciled whole.
1205 // If the reopen fails (the rebuild is mid-way), report lock contention
1206 // so the watcher keeps its pending files and retries.
1207 try {
1208 this.reopenReplacedDatabase();
1209 } catch (err) {
1210 this.fileLock.release();
1211 throw new LockUnavailableError(
1212 `Sync could not open the rebuilt index yet; retry when the rebuild finishes. ${err instanceof Error ? err.message : String(err)}`
1213 );
1214 }
1215 if (this.pendingFullReconcile) {
1216 // The lock above keeps sync out of a live rebuild. If the rebuild
1217 // stopped before indexAll set index_state, give the fresh empty file
1218 // a bounded grace period before reconciling it.
1219 if (this.getIndexState() === null && this.isFreshlyRecreated()) {
1220 this.fileLock.release();
1221 throw new LockUnavailableError('A rebuild of this index is in progress; retry when it finishes.');
1222 }
1223 // Cleared only once this run completes (below): a sync that throws
1224 // must leave the full catch-up for the next one.
1225 options = { ...options, paths: undefined };

Callers 15

openMethod · 0.95
watchMethod · 0.95
syncEditFunction · 0.45
convergesFunction · 0.45
syncedFunction · 0.45
syncEditFunction · 0.45

Calls 15

getIndexStateMethod · 0.95
isFreshlyRecreatedMethod · 0.95
pythonFilePathsMethod · 0.95
stampPhpWebRootsMethod · 0.95
synthesisHoldMsMethod · 0.95
armDeferredSynthesisMethod · 0.95

Tested by 15

syncEditFunction · 0.36
convergesFunction · 0.36
syncedFunction · 0.36
syncEditFunction · 0.36
reindexFunction · 0.36
convergeAfterFunction · 0.36
syncEditFunction · 0.36
indexThenSyncFunction · 0.36
syncsFunction · 0.36
syncEditFunction · 0.36
editAndSyncFunction · 0.36
syncEditFunction · 0.36