Skip to content

Auto-save pipeline broken on Windows/Git Bash: CRLF + single-quote path wrapping in safe_eval #84

Closed

Description

@qzftsh7f44-design

Title:

Auto-save pipeline broken on Windows/Git Bash: CRLF + single-quote path wrapping in safe_eval

Body:

Description

The save pipeline (save-session.sh) fails on every run under Windows / Git Bash.
SessionStart context injection works fine (it's pure cat/echo), but nothing is
ever saved — now.md/recent.md/etc. stay empty and .remember/logs/hook-errors.log
fills up. Two distinct root causes, both in the shell↔Python variable bridge.

Reproduction

  1. Install the plugin on Windows (Git Bash / MSYS2 bash).
  2. Run a normal Claude Code session until the PostToolUse delta threshold (50 lines)
    triggers a background save.
  3. Check .remember/logs/hook-errors.log.

Actual behavior

Every save attempt produces (.remember/logs/autonomous/save-*.log are all 0 bytes):

save-session.sh: line 131: [: 15: integer expression expected
save-session.sh: line 133: [: 2: integer expression expected
Traceback (most recent call last):
  ...
  File ".../pipeline/shell.py", line 102, in cmd_build_prompt
    with open(extract_file, encoding="utf-8") as f:
OSError: [Errno 22] Invalid argument: "'C:\Users\VANDER~1\AppData\Local\Temp\remember-extract-3f2xu6lg.txt'"

Root cause 1 — CRLF not stripped in one of the two safe_eval copies

There are two definitions of safe_eval:

  • scripts/detect-tools.sh:85 — strips CR: line="${line%$'\r'}" ✅
  • scripts/log.sh:139 — does not strip CR ❌

session-start-hook.sh (and the save path) source detect-tools.sh first and
log.sh afterwards, so the CRLF-unsafe version from log.sh shadows the correct one.
On Windows the Python pipeline's stdout arrives as \r\n, so values keep a trailing \r:
EXCHANGE_COUNT=15\r, HUMAN_COUNT=2\r. The integer tests at
save-session.sh:131 ([ "$EXCHANGE_COUNT" -eq 0 ]) and :133
([ "$HUMAN_COUNT" -lt ... ]) then fail with "integer expression expected".

Fix: add line="${line%$'\r'}" to the safe_eval in log.sh (or dedupe to a
single shared definition).

Root cause 2 — escaper/parser mismatch wraps temp paths in literal quotes

pipeline/shell.py:80 emits the temp path via _shell_escape() (shell.py:37),
which single-quote-wraps values per the POSIX eval convention:
EXTRACT_FILE='C:\Users\...txt'.

But safe_eval does not eval — it assigns verbatim with
printf -v "$_key" '%s' "$_val" (detect-tools.sh:91 / log.sh:144), which keeps
the surrounding single quotes as part of the value. So $EXTRACT_FILE becomes
'C:\Users\...txt' including the quotes, gets passed to
pipeline.shell build-prompt, and Python's open() receives a filename containing
literal ' → OSError: [Errno 22].

This is why it passes on Linux but fails on Windows: a Linux temp path
(/tmp/remember-extract-xxx.txt) contains only shell-safe characters, so
_shell_escape returns it unquoted and printf -v stores it cleanly. Windows
paths contain backslashes, which force _shell_escape to quote them.

Fix: make escaper and parser agree — either have safe_eval strip the
surrounding single quotes / actually use eval, or have _shell_escape emit output
compatible with the printf -v assignment (e.g. don't single-quote, or have the
shell unwrap it). Note the same _shell_escape is also used for HAIKU_TEXT_FILE
(shell.py:155), so it'll hit the consolidation path too.

Expected behavior

Saves complete; staging/tier files populate; hook-errors.log stays empty.

Proposed fix (verified on Windows)

Both root causes live in safe_eval. Fixing the parser side covers both and needs
no Python changes. Applied to both copies (detect-tools.sh and log.sh) so it
works regardless of source order:

safe_eval() {
    while IFS= read -r line; do
        line="${line%$'\r'}"                    # RC1: strip CR (was missing in log.sh)
        if [[ "$line" =~ ^([A-Z_][A-Z0-9_]*)=(.*)$ ]]; then
            local _key="${BASH_REMATCH[1]}"
            local _val="${BASH_REMATCH[2]}"
            # RC2: unwrap single-quote wrapping from Python _shell_escape;
            # printf -v stores verbatim and does not strip quotes like eval would.
            if [[ "$_val" == \'*\' ]]; then
                _val="${_val#\'}"
                _val="${_val%\'}"
                _val="${_val//"'\\''"/"'"}"
            fi
            printf -v "$_key" '%s' "$_val"
        fi
    done
}

Verified end-to-end on the environment below: a forced
save-session.sh <id> --force now extracts cleanly, passes the integer thresholds,
calls Haiku, and writes today-YYYY-MM-DD.md, with hook-errors.log empty.
(Alternatively the fix could live on the Python side by not single-quoting in
_shell_escape, since safe_eval's printf -v already stores values verbatim and
needs no quoting for single-line values — your call which side owns it.)

Environment

  • claude-remember version: 0.7.2 (commit c9b3441)
  • Claude Code version: 2.1.152
  • Shell: Git Bash (GNU bash 5.2.37 / MSYS2)
  • OS: Windows 11 Pro 26200
  • Python version: 3.13.1

Activity

  1. added
    bug
    on May 27, 2026
  2. fdaviddpt commented on May 27, 2026

    @fdaviddpt
    Contributor

    Thank you for the deep dive — the analysis was spot-on, both root causes nailed exactly where you said they were.

    Fix shipped in #85 (released as v0.7.3). I took the Python-side path you mentioned as an alternative: _shell_escape now emits verbatim and safe_eval strips CR. Removed the redundant safe_eval override from detect-tools.sh so there's a single source of truth in log.sh.

    Why CI missed this: the existing CRLF tests sourced only detect-tools.sh (the file that had the CR strip), never the broken copy in log.sh that the real orchestrators reach. Added tests/test_safe_eval_seam.py to pin the Python↔bash roundtrip across Linux paths, Windows backslash paths, spaces, and single quotes — closes the gap your report exposed.

    Once #85 merges and v0.7.3 is published to our marketplace, could you try a fresh install on your Windows box?

    /plugin marketplace update
    /plugin install remember@dpt-plugins
    

    (or /plugin marketplace add Digital-Process-Tools/claude-marketplace first if you haven't already)

    Then run a normal session and check that .remember/now.md and the daily file populate, and hook-errors.log stays clean. If anything still misbehaves on Windows, please reopen with the new logs — we'd love to lock it down end-to-end on a real Windows machine.

    Thanks again — issues this well-written save us hours.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions