fix(gateway): honor retainAttachmentsOnKeep in TTL sweep + start sweeper on restore

1. Guard safeRemoveAttachmentsDir with retainAttachmentsOnKeep check
   in the session-mode TTL sweep, matching the existing pattern in
   finalizeSubagentCleanup (Codex P1)

2. Start sweeper unconditionally in restoreSubagentRunsOnce(), matching
   the register paths — ensures TTL cleanup runs after restart even
   when all restored entries are session-mode (Codex P2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
XING
2026-03-23 18:25:12 +08:00
committed by Josh Lehman
parent e62d0b3d31
commit 08daee7f75

View File

@@ -436,9 +436,8 @@ function restoreSubagentRunsOnce() {
}
// Resume pending work.
ensureListener();
if ([...subagentRuns.values()].some((entry) => entry.archiveAtMs)) {
startSweeper();
}
// Always start sweeper — session-mode runs (no archiveAtMs) also need TTL cleanup.
startSweeper();
for (const runId of subagentRuns.keys()) {
resumeSubagentRun(runId);
}
@@ -495,7 +494,9 @@ async function sweepSubagentRuns() {
});
subagentRuns.delete(runId);
mutated = true;
await safeRemoveAttachmentsDir(entry);
if (!entry.retainAttachmentsOnKeep) {
await safeRemoveAttachmentsDir(entry);
}
}
continue;
}