fix: check blockPreSet before hasCustomContent to prevent misleading log

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.
This commit is contained in:
zeroaltitude 2026-03-09 23:15:47 -07:00
parent 8ccb587965
commit d9cce17a75
No known key found for this signature in database
GPG Key ID: 77592FB1C703882E

View File

@ -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 {