Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): R1-L2 contain quarantine cleanup

Josué1e035bb40d93
diff --git a/desktop-app/src/__tests__/chatStoreBinding.test.ts b/desktop-app/src/__tests__/chatStoreBinding.test.ts
index b36088984..5ee2b5f76 100644
--- a/desktop-app/src/__tests__/chatStoreBinding.test.ts
+++ b/desktop-app/src/__tests__/chatStoreBinding.test.ts
@@ -38,6 +38,24 @@ describe('chatStoreBinding', () => {
expect(() => requireChatStore()).toThrow(/Not authenticated/)
})
+ it('does not follow symlinked quarantine roots during retention cleanup', async () => {
+ const externalDir = await fs.mkdtemp(path.join(os.tmpdir(), 'clerum-external-quarantine-'))
+ const sentinel = path.join(externalDir, 'corrupt-old')
+ await fs.mkdir(sentinel)
+ const old = new Date('2000-01-01T00:00:00.000Z')
+ await fs.utimes(sentinel, old, old)
+ const corruptRoot = path.join(tmpBase, ENV_A, 'user-a', 'agent-x', '.corrupt')
+ await fs.mkdir(path.dirname(corruptRoot), { recursive: true })
+ await fs.symlink(externalDir, corruptRoot, process.platform === 'win32' ? 'junction' : 'dir')
+
+ try {
+ await bindChatStoreForUser('user-a', ENV_A)
+ expect(await exists(sentinel)).toBe(true)
+ } finally {
+ await fs.rm(externalDir, { recursive: true, force: true })
+ }
+ })
+
it('does not publish a stale store when logout interrupts an in-flight bind', async () => {
await bindChatStoreForUser('seed-user', ENV_A)
unbindChatStore()
diff --git a/desktop-app/src/chatStoreBinding.ts b/desktop-app/src/chatStoreBinding.ts
index 658cce12f..8ac5d15f0 100644
--- a/desktop-app/src/chatStoreBinding.ts
+++ b/desktop-app/src/chatStoreBinding.ts
@@ -302,6 +302,7 @@ async function sweepExpiredCorruptQuarantines(userDir: string, nowMs = Date.now(
await removeExpiredQuarantineEntries(join(agentDir, '.corrupt'), () => true, nowMs)
const snapshotRoot = join(agentDir, 'chats', '.snapshots')
+ if (!(await isRealDirectory(snapshotRoot))) return
const chatEntries = await fs.readdir(snapshotRoot, { withFileTypes: true }).catch(() => [])
await Promise.all(
chatEntries
@@ -318,11 +319,17 @@ async function sweepExpiredCorruptQuarantines(userDir: string, nowMs = Date.now(
)
}
+async function isRealDirectory(directory: string): Promise<boolean> {
+ const stat = await fs.lstat(directory).catch(() => null)
+ return Boolean(stat?.isDirectory() && !stat.isSymbolicLink())
+}
+
async function removeExpiredQuarantineEntries(
directory: string,
shouldRemove: (name: string) => boolean,
nowMs: number
): Promise<void> {
+ if (!(await isRealDirectory(directory))) return
const entries = await fs.readdir(directory, { withFileTypes: true }).catch(() => [])
await Promise.all(
entries