Skip to content

Log rotation fails permanently on Windows: GNU tar parses the drive-letter archive path as a remote host #252

Closed

Description

@hubertrm

Summary

rotate_logs() in scripts/log.sh builds an absolute archive path and passes it to tar -czf. On Windows, REMEMBER_LOG_DIR is a drive-letter path (C:/Users/...), and GNU tar parses an -f argument containing a colon as host:path — so it tries to open a network connection to a machine named C and fails.

Because stderr is discarded (2>/dev/null) and the failure branch only writes a log line, rotation fails silently and permanently: every invocation re-finds the same aged logs, fails again, and never archives or deletes anything. It does not self-correct.

Environment

  • Plugin version: 0.10.0
  • OS: Windows 11 Pro 26200, Git Bash (MINGW64)
  • tar: GNU tar 1.35 (/usr/bin/tar)
  • REMEMBER_DIR: C:\Users\<user>\Projects\<project>/.remember (legacy in-project storage mode)

Observed behaviour

Daily, in .remember/logs/memory-YYYY-MM-DD.log:

08:33:14 [rotate] ERROR: tar failed for 19 logs

The log directory keeps growing — 29 *.log files / 2.3 MB in one project, none ever archived, going back to 2026-06-23.

Reproduction

$ cd /c/Users/me/scratch && echo x > a.log
$ tar -czf "C:/Users/me/scratch/logs-2026-07.tar.gz" -C "C:/Users/me/scratch" a.log
tar (child): Cannot connect to C: resolve failed
tar: Child returned status 128
tar: Error is not recoverable: exiting now
$ echo $?
2

Note the same parsing applies when reading the archive back (tar -tzf "C:/..." fails identically), so any future restore/inspection path that takes an absolute Windows path has the same bug.

Root cause

scripts/log.sh, rotate_logs():

local archive="${REMEMBER_LOG_DIR}/logs-${archive_month}.tar.gz"
...
if tar -czf "$archive" -C "$REMEMBER_LOG_DIR" "${basenames[@]}" 2>/dev/null; then

$archive contains C:. Only the -f argument is subject to tar's host:path parsing — the -C argument is not — so the archive path alone triggers it.

Proposed fix (portable)

--force-local is the usual GNU tar answer, but it does not exist on bsdtar (stock macOS), so it would trade a Windows failure for a macOS one.

Since the call already -Cs into REMEMBER_LOG_DIR and passes bare basenames, the archive can simply be named relatively from inside that directory. A relative name has no colon, so neither GNU tar nor bsdtar treats it as remote, and the resulting archive and member names are identical.

-    if tar -czf "$archive" -C "$REMEMBER_LOG_DIR" "${basenames[@]}" 2>/dev/null; then
+    if ( cd "$REMEMBER_LOG_DIR" && tar -czf "logs-${archive_month}.tar.gz" "${basenames[@]}" 2>/dev/null ); then

$archive is still used by the success log line (basename "$archive"), so it can stay as-is.

Verified

Applied locally against 0.10.0 and exercised end-to-end with three 20-day-old memory-*.log files in a sandbox log dir:

rotate_logs exit=0
$ ls logs/
logs-2026-07.tar.gz
$ tar -tzf logs/logs-2026-07.tar.gz
memory-2026-07-10.log
memory-2026-07-11.log
memory-2026-07-12.log

Archive created, member names correct, originals removed — i.e. the intended behaviour, which had never once run on this machine.

Secondary suggestion

The failure was invisible for ~5 weeks because 2>/dev/null discards tar's diagnostic and the error line doesn't include it. Including tar's stderr in the ERROR: log line would have made this self-diagnosing:

err=$( ( cd "$REMEMBER_LOG_DIR" && tar -czf "logs-${archive_month}.tar.gz" "${basenames[@]}" ) 2>&1 ) || \
    log "rotate" "ERROR: tar failed for ${count} logs: ${err}"

hook-errors.log was also empty throughout, so nothing surfaced there either.

Activity

  1. fdaviddpt commented on Jul 31, 2026

    @fdaviddpt
    Contributor

    Fixed and merged — thank you, this was an unusually good report.

    Three things in it did the heavy lifting, and I want to name them because they are the reason this took hours rather than weeks:

    • The minimal reproduction. tar -czf "C:/…" -C "C:/…" a.log with the exact error and exit code meant the mechanism could be verified on macOS against a locally installed GNU tar 1.35 — no Windows machine needed, because the parse rule is the bug. Most Windows reports we get can only be reproduced on the reporter's own hardware.
    • You identified the permanence, not just the failure. "It does not self-correct" was the more important half. The tar call was one line; the reason nobody noticed for five weeks was 2>/dev/null plus a failure branch that returned success. That is the part that got fixed properly.
    • The environment detail. GNU tar 1.35 at /usr/bin/tar under MINGW64 told us which implementation was actually parsing the path, which turned out to matter — see below.

    What changed. The archive name is now relative (logs-2026-07.tar.gz), so the drive letter never reaches -f. Your instinct about the colon was right and slightly generalised in the process: GNU tar only treats a colon as host:path when it precedes the first slash, so /tmp/x/we:ird.tar.gz is fine. A relative name is therefore safe by construction rather than by luck.

    Why not --force-local. It was the obvious candidate and we measured it before adopting it: bsdtar 3.5.3 — which is /usr/bin/tar on macOS, where this project is developed — rejects the flag outright, exit 1, no archive written. Hardcoding it would have fixed Windows by silently disabling rotation on macOS, inside the same branch whose stderr was being discarded. Detecting the implementation was considered and rejected: that is a second bug waiting to happen, keyed on the wrong axis.

    Rotation now has three outcomes instead of two: nothing to do (silent), archived N logs (logged), and could not archive — a non-zero return with tar's own diagnostic in the line, escalating after three consecutive failures. There is also a breadcrumb that /remember:doctor reports, chosen specifically because your hook-errors.log was empty for the entire five weeks; a fix that only wrote to a log nobody reads would have repeated the original mistake.

    Your report also surfaced a second, worse bug we had not noticed: the archive is named by month and tar -czf truncates, so a second rotation in the same month destroys the first archive — and the original logs were already deleted. That is platform-independent data loss, now filed as #255 and being fixed separately. It only came to light because someone finally looked closely at this function.

    Your 29 accumulated log files should archive on the next consolidation run once you are on a release containing this. I will follow up here when that ships — a fix that has not reached your install is not a fix, and we have been caught by exactly that before.

  2. fdaviddpt commented on Jul 31, 2026

    @fdaviddpt
    Contributor

    Shipped in v0.12.0 — it's on your machine's next plugin update rather than just on main.

    If you'd rather not wait for the updater to notice, FORCE_AUTOUPDATE_PLUGINS=1 on a session start moves a stale cache immediately. Worth knowing that the cache directory name is not the version — one install here read 0.7.1 as a path while its manifest said 0.8.0, and the updater compares manifests. .claude-plugin/plugin.json inside the install is the honest answer; it should say 0.12.0.

    What you should see: your 29 accumulated logs archive on the next consolidation run, into logs-YYYY-MM.tar.gz — named relatively now, so no tar can read the drive letter as a hostname. And if rotation ever fails again, it returns non-zero with tar's own diagnostic in the log line, escalates after three consecutive failures, and /remember:doctor reports it. That last part is specifically because your hook-errors.log was empty for the entire five weeks.

    One thing found because of your report, which you should know about since it affects the same function: rotate_logs names archives by month and tar -czf truncates, so two rotations in the same calendar month overwrite the first archive — after the originals were deleted. Filed as #255, not fixed in this release. It predates your report and is not made worse by it, but if you have a logs-2026-07.tar.gz already, don't assume it holds everything from July.

    Thanks again. The reproduction is what made this a few hours rather than a few weeks.

  3. added a commit that references this issue on Oct 7, 2026
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