From d9cce17a751661efe4fc35ebbe741be75429ec70 Mon Sep 17 00:00:00 2001 From: zeroaltitude Date: Mon, 9 Mar 2026 23:15:47 -0700 Subject: [PATCH] fix: check blockPreSet before hasCustomContent to prevent misleading log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restructured entry construction to test blockPreSet first — eliminates the misleading 'Using custom session content' debug log that fired before the 'will be ignored' correction when both flags were pre-set. Removed redundant duplicate blockPreSet check in the write-decision block. --- src/hooks/bundled/session-memory/handler.ts | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/hooks/bundled/session-memory/handler.ts b/src/hooks/bundled/session-memory/handler.ts index 6aeb0ddcdda..5b89d0c5b13 100644 --- a/src/hooks/bundled/session-memory/handler.ts +++ b/src/hooks/bundled/session-memory/handler.ts @@ -357,14 +357,26 @@ const saveSessionToMemory: HookHandler = async (event) => { // When blockPreSet is true, skip entry construction entirely — the inline // write won't happen and the value would be discarded. let entry: string; - if (hasCustomContent) { + if (blockPreSet) { + // Block takes precedence — skip entry construction entirely since the + // inline write won't happen and the value would be discarded. + entry = ""; + if (hasCustomContent) { + log.debug( + "blockSessionSave pre-set — sessionSaveContent was also set but will be ignored " + + "(blockSessionSave takes precedence over sessionSaveContent)", + ); + } else { + log.debug("Session save blocked by upstream hook (inline check)"); + } + } else if (hasCustomContent) { // An empty string is a valid redaction signal — hooks may intentionally // set it to persist a blank marker while avoiding transcript retention. entry = context.sessionSaveContent as string; log.debug("Using custom session content from upstream hook", { length: entry.length, }); - } else if (!blockPreSet) { + } else { const entryParts = [ `# Session: ${dateStr} ${timeStr} UTC`, "", @@ -379,8 +391,6 @@ const saveSessionToMemory: HookHandler = async (event) => { } entry = entryParts.join("\n"); - } else { - entry = ""; // Block pre-set — writtenEntry will be null regardless. } // Write inline (fail-safe: if postHookActions never drains, the file @@ -392,14 +402,7 @@ const saveSessionToMemory: HookHandler = async (event) => { // erasure of prior memory files when LLM slugs collide on the same day. let preExistingContent: string | null = null; if (blockPreSet) { - if (hasCustomContent) { - log.debug( - "blockSessionSave pre-set — sessionSaveContent was also set but will be ignored " + - "(blockSessionSave takes precedence over sessionSaveContent)", - ); - } else { - log.debug("Session save blocked by upstream hook (inline check)"); - } + // Already logged above — nothing to write. } else { await fs.mkdir(memoryDir, { recursive: true }); try {