diff --git a/src/auto-reply/reply/session.ts b/src/auto-reply/reply/session.ts index 35ee66b71..49e9d2208 100644 --- a/src/auto-reply/reply/session.ts +++ b/src/auto-reply/reply/session.ts @@ -278,10 +278,13 @@ export async function initSessionState(params: { ctx.MessageThreadId, ); } - // Fresh start for new sessions - don't inherit old state like compactionCount - sessionStore[sessionKey] = isNewSession - ? sessionEntry - : { ...sessionStore[sessionKey], ...sessionEntry }; + if (isNewSession) { + sessionEntry.compactionCount = 0; + sessionEntry.memoryFlushCompactionCount = undefined; + sessionEntry.memoryFlushAt = undefined; + } + // Preserve per-session overrides while resetting compaction state on /new. + sessionStore[sessionKey] = { ...sessionStore[sessionKey], ...sessionEntry }; await updateSessionStore(storePath, (store) => { if (groupResolution?.legacyKey && groupResolution.legacyKey !== sessionKey) { if (store[groupResolution.legacyKey] && !store[sessionKey]) { @@ -289,10 +292,8 @@ export async function initSessionState(params: { } delete store[groupResolution.legacyKey]; } - // Fresh start for new sessions - don't inherit old state like compactionCount - store[sessionKey] = isNewSession - ? sessionEntry - : { ...store[sessionKey], ...sessionEntry }; + // Preserve per-session overrides while resetting compaction state on /new. + store[sessionKey] = { ...store[sessionKey], ...sessionEntry }; }); const sessionCtx: TemplateContext = {