diff --git a/src/hooks/bundled/session-memory/handler.ts b/src/hooks/bundled/session-memory/handler.ts index 1ccf017451d..2478770e26c 100644 --- a/src/hooks/bundled/session-memory/handler.ts +++ b/src/hooks/bundled/session-memory/handler.ts @@ -397,8 +397,18 @@ const saveSessionToMemory: HookHandler = async (event) => { await fs.mkdir(memoryDir, { recursive: true }); try { preExistingContent = await fs.readFile(memoryFilePath, "utf-8"); - } catch { + } catch (err: unknown) { // File doesn't exist yet — normal case, nothing to preserve. + // Rethrow non-ENOENT errors (EACCES, EISDIR, etc.) to avoid silently + // losing preExistingContent, which would cause late-block retraction + // to delete the file instead of restoring a prior session's history. + if ( + err instanceof Error && + "code" in err && + (err as NodeJS.ErrnoException).code !== "ENOENT" + ) { + throw err; + } } await writeFileWithinRoot({ rootDir: memoryDir, diff --git a/src/hooks/internal-hooks.ts b/src/hooks/internal-hooks.ts index 6d2610c670b..8bcbb567aed 100644 --- a/src/hooks/internal-hooks.ts +++ b/src/hooks/internal-hooks.ts @@ -313,7 +313,10 @@ export async function triggerInternalHook(event: InternalHookEvent): Promise