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

Method runDeferredSynthesis

src/index.ts:1959–1986  ·  view source on GitHub ↗

* The put-off synthesis, under the locks a sync holds. Nothing to do when a * sync ran it meanwhile. When the file lock is taken by another process, * try again after the interval; `synthesis_pending` stays set throughout. * * It runs from a timer, so nothing above it catches a failure,

()

Source from the content-addressed store, hash-verified

1957 * here is logged and tried again after the interval, as lock contention is.
1958 */
1959 private async runDeferredSynthesis(): Promise<void> {
1960 const retryLater = (): void => {
1961 if (!this.db.isOpen()) return;
1962 this.armDeferredSynthesis(parseSynthMinIntervalEnv(process.env.CODEGRAPH_SYNTH_MIN_INTERVAL_MS) ?? 1000);
1963 };
1964 try {
1965 await this.indexMutex.withLock(async () => {
1966 if (this.queries.getMetadata('synthesis_pending') !== '1') return;
1967 try {
1968 this.fileLock.acquire();
1969 } catch {
1970 retryLater();
1971 return;
1972 }
1973 try {
1974 // A rebuild may have replaced the file meanwhile, as sync checks.
1975 this.reopenReplacedDatabase();
1976 if (this.queries.getMetadata('synthesis_pending') !== '1') return;
1977 await this.synthesizeWithWalDeferred();
1978 } finally {
1979 this.fileLock.release();
1980 }
1981 });
1982 } catch (err) {
1983 logWarn(`Put-off synthesis failed, trying again after the interval: ${err instanceof Error ? err.message : String(err)}`);
1984 retryLater();
1985 }
1986 }
1987
1988 /**
1989 * The rebuild, with the WAL handling a sync gives it (#1231, #1248): a whole

Callers 1

armDeferredSynthesisMethod · 0.95

Calls 7

logWarnFunction · 0.90
getMetadataMethod · 0.80
releaseMethod · 0.65
withLockMethod · 0.45
acquireMethod · 0.45

Tested by

no test coverage detected