fix(tui): handle storage watcher errors after startup (#51243)

Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot]
2026-09-24 20:25:06 -05:00
committed by GitHub
parent 8061220b08
commit 85b98e7da4
+10 -4
View File
@@ -110,14 +110,20 @@ export function createStorage(root: string, channel: string) {
},
}
let reload: ReturnType<typeof setTimeout> | undefined
let reloadTimer: ReturnType<typeof setTimeout> | undefined
let watcher: ReturnType<typeof watch> | undefined
try {
watcher = watch(directory, () => {
clearTimeout(reload)
clearTimeout(reloadTimer)
// Atomic writes notify for the temporary file before its final rename, and some
// platforms coalesce the rename event. Reload after the event burst has settled.
reload = setTimeout(() => entries.forEach((entry) => entry.reload()), 50)
reloadTimer = setTimeout(() => entries.forEach((entry) => entry.reload()), 50)
})
watcher.on("error", (error) => {
clearTimeout(reloadTimer)
watcher?.close()
watcher = undefined
console.error("Storage directory watcher failed, live-reload disabled", { directory, error })
})
} catch (error) {
// fs.watch throws synchronously (e.g. ENOSPC when the inotify watch limit is
@@ -128,7 +134,7 @@ export function createStorage(root: string, channel: string) {
return {
storage,
close: () => {
clearTimeout(reload)
clearTimeout(reloadTimer)
watcher?.close()
},
}