Stop wiping Comfy inputs and sibling outputs during disk cleanup.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-03 18:16:56 -05:00
co-authored by Cursor
parent de433c40d3
commit a6756c1f1a
3 changed files with 24 additions and 53 deletions
+16 -19
View File
@@ -610,7 +610,7 @@ function fileStem(filename) {
return dot > 0 ? name.slice(0, dot) : name
}
function removeNamedFile(roots, filename, subfolders) {
function removeNamedFile(roots, filename, subfolders, { stemSiblings = true } = {}) {
const deleted = []
const name = basename(String(filename || ''))
if (!name) return deleted
@@ -622,7 +622,7 @@ function removeNamedFile(roots, filename, subfolders) {
const dir = sub ? join(root, String(sub).replace(/\.\./g, '')) : root
const exact = safeFile(root, sub, name)
if (removeFile(exact)) deleted.push(exact)
if (!stem || !existsSync(dir)) continue
if (!stemSiblings || !stem || !existsSync(dir)) continue
let files = []
try { files = readdirSync(dir) } catch { continue }
for (const file of files) {
@@ -700,6 +700,7 @@ function readJson(req) {
function purgeDesktopFiles(body) {
const deleted = []
const allowSweep = body?.sweep !== false
const names = [
String(body?.imageName || body?.filename || ''),
...(Array.isArray(body?.imageNames) ? body.imageNames : [])
@@ -716,7 +717,8 @@ function purgeDesktopFiles(body) {
deleted.push(...removeNamedFile(
rootsForType(type),
videoName,
[video.subfolder, imageOut ? '' : 'video', '']
[video.subfolder, imageOut ? '' : 'video', ''],
{ stemSiblings: false }
))
}
const audio = body?.audio || null
@@ -725,7 +727,8 @@ function purgeDesktopFiles(body) {
deleted.push(...removeNamedFile(
rootsForType(String(audio?.type || 'output')),
audioName,
[audio.subfolder, 'audio', '']
[audio.subfolder, 'audio', ''],
{ stemSiblings: false }
))
}
const output = body?.output || null
@@ -734,10 +737,13 @@ function purgeDesktopFiles(body) {
deleted.push(...removeNamedFile(
rootsForType(String(output?.type || 'output')),
outputName,
[output.subfolder, 'image', 'still', '']
[output.subfolder, 'image', 'still', ''],
{ stemSiblings: false }
))
}
deleted.push(...sweepStaleStudioOutputs(body?.sweepPrefixes, body?.sweepSubfolders, body?.sweepMaxAgeMs))
if (allowSweep) {
deleted.push(...sweepStaleStudioOutputs(body?.sweepPrefixes, body?.sweepSubfolders, body?.sweepMaxAgeMs))
}
const unique = [...new Set(deleted)]
console.log(JSON.stringify({
src: 'comfy-host-agent',
@@ -747,7 +753,8 @@ function purgeDesktopFiles(body) {
imageNames: names,
video: videoName || null,
audio: audioName || null,
output: outputName || null
output: outputName || null,
sweep: allowSweep
}))
return { ok: true, deleted: unique }
}
@@ -857,18 +864,8 @@ const server = http.createServer(async (req, res) => {
})
function logStartupSweep() {
try {
const deleted = sweepStaleStudioOutputs()
if (!deleted.length) return
console.log(JSON.stringify({
src: 'comfy-host-agent',
event: 'startup-sweep',
deleted: deleted.length,
files: deleted.map((path) => basename(path))
}))
} catch (error) {
console.log(JSON.stringify({ src: 'comfy-host-agent', event: 'startup-sweep-error', error: String(error?.message || error) }))
}
// Disabled: sweeping studio outputs on agent start was deleting Comfy
// files that are still part of the generation / recover workflow.
}
server.listen(port, '0.0.0.0', async () => {