Skip to content

save-session: format validator warns on malformed Haiku output but writes it to memory anyway #136

Closed

Description

@oliver-mee

Description

The format validator in scripts/save-session.sh (Step 5b) detects a malformed Haiku response, logs a warning, and then writes the entry to memory anyway. The comment on line 189 says this is intentional ("warn, never discard"), so this is a design question rather than a plain oversight, but the consequence is that anything Haiku returns in the wrong shape still lands in now.md.

I hit this on a real session: a permission prompt was stored as a memory entry.

23:56:47 [validate] WARNING: unexpected format: Bash needs approval to SSH into preface-vps and check. Shall I proceed?
23:56:47 [write] appended: Bash needs approval to SSH into preface-vps and check. Shall I proceed?
23:56:47 [write] position → 2309

The validator did its job. It just has no ability to act on the result.

The reason I think this is worth changing rather than leaving as a warning: the memory layer is a summary of summaries. now.md rolls into today-*.md, then recent.md, then archive.md, and each hop compresses. A malformed entry that survives the first hop does not fade, it gets summarised downstream as though it were real work. In my case a permission prompt is now sitting in a daily file waiting to be consolidated into a week's worth of context.

This is also a defence-in-depth gap rather than a single bug. #119 covers the prompt-side cause (no SKIP condition for no-work sessions), and one of the polluted examples there is "a literal unfilled ## HH:MM | main header", which is exactly the shape this validator already detects. A validator that could reject would have contained that pollution even with the prompt unchanged.

The existing reject gate does not cover it either. DEFAULT_REJECT_PATTERN in pipeline/haiku.py is anchored to refusal stems (i cannot, could you, please provide, i'm sorry), which is a sensible narrow default. My line started with "Bash needs approval", so it missed gate A, and gate B could only warn.

Reproduction

Steps to reproduce:

  1. Run a session where Haiku's summarize call returns a line that is not a ## HH:MM | branch header (in my case a mid-turn permission prompt was captured as the response).
  2. Let save-session.sh run normally, without --force.
  3. Check .remember/logs/memory-YYYY-MM-DD.log and .remember/now.md.

The warning and the write appear in the same second, and the malformed line is in now.md.

Relevant code, scripts/save-session.sh on current main:

# --- Step 5b: Validate format (warn, never discard) ---
if [ "$IS_SKIP" != "true" ]; then
    FIRST_LINE=$(head -1 "$HAIKU_TEXT_FILE")
    if ! echo "$FIRST_LINE" | grep -qE '^## ([0-9]{2}:[0-9]{2}|[0-9]{1,2}:[0-9]{2} (AM|PM)) \|'; then
        log "validate" "WARNING: unexpected format: $(echo "$FIRST_LINE" | head -c 80)"
    fi
fi

Expected behavior

A response that fails the header check should not reach the memory files. Either dropped like a SKIP (position still advanced, so it does not retry forever), or held somewhere recoverable.

I can see the argument against failing closed, which I assume is the reason for the current design: a false positive silently loses a real summary, and that is worse than one junk line. If that is the concern, a couple of options that keep the safe default:

  • A config knob (features.strict_validation, default false) so people who care more about clean memory than complete memory can opt in. That fits the existing config ".key" default pattern and changes nothing for anyone else.
  • Write rejects to .remember/tmp/rejected-*.md instead of now.md. Nothing is lost, it just does not enter the compression chain.

Happy to open a PR for either if you have a preference. I would rather ask first than guess at which trade-off you want.

Actual behavior

The warning is logged, the entry is written to now.md, and the position advances as though the save succeeded. From that point it is indistinguishable from a valid entry, so consolidation treats it as real memory.

Environment

  • claude-remember version: 0.8.3 (also confirmed present on current main)
  • Claude Code version: 2.1.216
  • Shell: bash 5.2.21(1)-release
  • OS: Ubuntu 24.04.4 LTS (aarch64)
  • Python version: 3.12.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions