MCPcopy Create free account
hub / github.com/Noumena-Network/code / scheduleReload

Function scheduleReload

src/utils/skills/skillChangeDetector.ts:269–293  ·  view source on GitHub ↗

* Debounce rapid skill changes into a single reload. When many skill files * change at once (e.g. auto-update installs a new binary and a new session * touches skill directories), each file fires its own chokidar event. Without * debouncing, each event triggers clearSkillCaches() + clearCommandsC

(changedPath: string)

Source from the content-addressed store, hash-verified

267 * deadlock the Bun event loop via rapid FSWatcher watch/unwatch churn.
268 */
269function scheduleReload(changedPath: string): void {
270 pendingChangedPaths.add(changedPath)
271 if (reloadTimer) clearTimeout(reloadTimer)
272 reloadTimer = setTimeout(async () => {
273 reloadTimer = null
274 const paths = [...pendingChangedPaths]
275 pendingChangedPaths.clear()
276 // Fire ConfigChange hook once for the batch — the hook query is always
277 // 'skills' so firing per-path (which can be hundreds during a git
278 // operation) just spams the hook matcher with identical queries. Pass the
279 // first path as a representative; hooks can inspect all paths via the
280 // skills directory if they need the full set.
281 const results = await executeConfigChangeHooks('skills', paths[0]!)
282 if (hasBlockingResult(results)) {
283 logForDebugging(
284 `ConfigChange hook blocked skill reload (${paths.length} paths)`,
285 )
286 return
287 }
288 clearSkillCaches()
289 clearCommandsCache()
290 resetSentSkillNames()
291 skillsChanged.emit()
292 }, testOverrides?.reloadDebounce ?? RELOAD_DEBOUNCE_MS)
293}
294
295/**
296 * Reset internal state for testing purposes only.

Callers 1

handleChangeFunction · 0.85

Calls 9

executeConfigChangeHooksFunction · 0.85
hasBlockingResultFunction · 0.85
clearSkillCachesFunction · 0.85
clearCommandsCacheFunction · 0.85
resetSentSkillNamesFunction · 0.85
emitMethod · 0.80
logForDebuggingFunction · 0.50
addMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected