fix: use padEnd for truly guaranteed 4-char random slug suffix

Previous approach ((random + '0000').slice(2,6)) still produced 3 chars
when Math.random() === 0 ('0'.toString(36) = '0', '00000'.slice(2,6) = '000').
padEnd(4, '0') guarantees exactly 4 characters for all inputs.
This commit is contained in:
zeroaltitude 2026-03-08 23:08:27 -07:00
parent 419249fabb
commit abd7c877aa
No known key found for this signature in database
GPG Key ID: 77592FB1C703882E

View File

@ -332,7 +332,7 @@ const saveSessionToMemory: HookHandler = async (event) => {
// one silently overwrites the earlier memory entry.
if (!slug) {
const timeSlug = now.toISOString().split("T")[1].split(".")[0].replace(/:/g, "");
const rand = (Math.random().toString(36) + "0000").slice(2, 6); // guaranteed 4-char
const rand = Math.random().toString(36).slice(2, 6).padEnd(4, "0");
slug = `${timeSlug.slice(0, 6)}-${rand}`;
log.debug("Using fallback timestamp slug", { slug });
}