From 1e11385cbdfa93c3fe8e16a3040ed12a10c4dfe8 Mon Sep 17 00:00:00 2001 From: zeroaltitude Date: Sat, 7 Mar 2026 10:54:03 -0700 Subject: [PATCH] fix: add random suffix to fallback slug to prevent same-second collisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Second-resolution (HHMMSS) fallback slugs can collide when automated or multi-channel setups emit rapid /new or /reset commands within the same second — both writes target the same filename and the later one silently overwrites the earlier memory entry. Append a 4-char random alphanumeric suffix (e.g. 103022-x7f2) to make collisions effectively impossible without LLM slug generation. --- src/hooks/bundled/session-memory/handler.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hooks/bundled/session-memory/handler.ts b/src/hooks/bundled/session-memory/handler.ts index fcb04eb1c28..56321d26b1d 100644 --- a/src/hooks/bundled/session-memory/handler.ts +++ b/src/hooks/bundled/session-memory/handler.ts @@ -317,10 +317,15 @@ const saveSessionToMemory: HookHandler = async (event) => { } } - // If no slug, use timestamp + // If no slug, use timestamp with a random suffix to avoid collisions. + // Second-resolution (HHMMSS) alone can collide when automated or + // multi-channel setups emit rapid /new or /reset commands within the + // same second — both writes target the same filename and the later + // one silently overwrites the earlier memory entry. if (!slug) { const timeSlug = now.toISOString().split("T")[1].split(".")[0].replace(/:/g, ""); - slug = timeSlug.slice(0, 6); // HHMMSS — seconds prevent same-minute overwrites + const rand = Math.random().toString(36).slice(2, 6); // 4-char alphanumeric + slug = `${timeSlug.slice(0, 6)}-${rand}`; log.debug("Using fallback timestamp slug", { slug }); }