Repository navigation
Name the rotation archive relatively, and let a failed rotation say so (#252) - #254
Merged
Merged
Conversation
#252) rotate_logs() passed an absolute archive path to `tar -czf`. On Windows that path starts with a drive letter, and GNU tar reads an `-f` argument whose colon precedes the first slash as `host:path` -- so it tried to resolve a machine named `C` and exited 2. Nothing had been archived on the reporter's install since 2026-06-23: 29 files, 2.3 MB, one identical error line per day for five weeks. The archive is now named relatively from inside the log directory. Not `--force-local`: bsdtar (/usr/bin/tar on macOS) rejects that flag outright with exit 1 and writes no archive, so hardcoding it would have fixed Windows by disabling macOS -- inside a branch whose stderr was discarded. Not implementation detection either: the axis is the tar binary, not the OS, since Windows also carries a bsdtar that can win the PATH. A name with no slash has nowhere to put a colon, so no tar parses it as remote and none needs a flag. Verified against GNU tar 1.35 and bsdtar 3.5.3. The permanence was the larger half. `2>/dev/null` discarded the one sentence that identified the cause, and rotate_logs returned 0 whether it had archived, failed, or found nothing to do. There are now three states: silent success, logged success, and a non-zero return carrying tar's own diagnostic. After three consecutive failures the line names the consequence instead of repeating itself, and /remember:doctor reports the breadcrumb with its reason -- hook-errors.log was empty throughout those five weeks, so that report would have said OK the entire time. Rotation deliberately does not self-correct by deleting: those logs are the only record of what went wrong, on a machine that has just proved it cannot run the archive path. run-consolidation.sh now calls `rotate_logs || true`, load-bearing under its `set -e`. Tests first, red 5/9 then green 9/9, and green again with GNU tar forced ahead of bsdtar on PATH. Full suite 1129 passed, coverage 94.13%. Co-Authored-By: Max <noreply>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
rotate_logs()passed an absolute archive path totar -czf. On Windows that path begins with a drive letter, and GNU tar reads an-fargument whose colon precedes the first slash ashost:path— so it tried to resolve a machine namedC.Reproduced locally against GNU tar 1.35 (no Windows needed — the parse rule is the bug):
That second line is the whole mechanism: it is the colon's position, not its presence. Only
-fis parsed this way —-Cnever was, which is why already passing the directory separately did not save it.The reporter's install had archived nothing since 2026-06-23: 29 files, 2.3 MB, one identical
ERROR: tar failed for 19 logsper day for five weeks.The tar decision — and why not
--force-local--force-localis the usual GNU answer and is the trap. Tested on both implementations:/usr/bin/tar, macOS)-f--force-local-f, no directory prefixHardcoding
--force-localwould have fixed Windows by disabling rotation on macOS entirely — into the branch whose stderr was discarded, so nobody would have seen it. That is #204's shape.Detecting the implementation was the other option and was also rejected, for a subtler reason: the axis is the tar binary, not the OS. Git Bash ships GNU tar, but Windows also carries a bsdtar in System32 that can win the
PATH, so a platform-keyed detector would be a second bug waiting to happen.So the archive is named relatively, from inside the log directory. A name with no slash has nowhere to put a colon, so no tar can parse it as remote and none of them needs a flag.
Both implementations produce identical member lists.
The defect underneath — why it was permanent
The tar call was the visible half.
2>/dev/nulldiscarded the one sentence that identified the cause, androtate_logsreturned 0 whether it had archived, failed, or found nothing to do — so "nothing to rotate" and "permanently broken" were the same event to every caller.Now there are three states:
00archived N logs → logs-2026-07.tar.gz1ERROR: … : <tar's own stderr>Plus two things one line a day demonstrably could not do:
/remember:doctornow reports it, with the reason.hook-errors.logwas empty throughout the reporter's five weeks, so that report would have said "OK" the entire time.commands/doctor.mdalready relaysWARNlines verbatim, so no doc change was needed.It deliberately does not self-correct by deleting. A stuck rotation could bound the growth by deleting aged logs instead of archiving them, and does not: those logs are the only record of what went wrong, on a machine that has just proved it cannot run the archive path. Accumulation is visible and recoverable; deletion is neither. Bounded by making it loud, not destructive.
run-consolidation.shnow callsrotate_logs || true— load-bearing under itsset -e, since a log directory that cannot be tidied must not abort the consolidation.Tests — RED then GREEN
tests/test_log_rotation.py, 9 tests. RED 5/9, then GREEN 9/9 — and green again with GNU tar 1.35 forced ahead of bsdtar onPATH.RED: the argv pin, tar's reason reaching the log, failure distinguishable from empty, the 3-failure escalation, and doctor reporting it.
The argv assertion is deliberately about the constructed
-fargument, not tar's behaviour on the runner: a POSIX box has no drive letter to reproduce with, but "the argument contains no/" is checkable anywhere and is strictly stronger than "contains no colon". Real artifacts elsewhere — a real temp log dir, really backdated mtimes (find -mtime +7is what selects them, so faking that would be testing the fixture), and a real tar for the success path. The two tar shims assert they actually executed, and the breadcrumb-clearing test asserts the breadcrumb exists before checking it is cleared, so it cannot pass vacuously.Found while here — not fixed, needs its own issue
rotate_logscan silently destroy previously archived logs. The archive is named fromdate -v-7d +%Y-%m, so two rotations in the same month target the samelogs-YYYY-MM.tar.gz, andtar -czftruncates. Second run wins; the first run's logs are gone, and their originals were already deleted. Demonstrated:Unrecoverable, independent of this bug, and reachable on every platform. Related: because the month comes from "7 days ago" rather than from the logs being archived, a backlog spanning a month boundary — exactly what a previously-broken rotation guarantees — all lands in one archive whose name misstates its contents.
#251's idiom is in
log.shtwice, atlog.sh:268andlog.sh:332, both[ -n "$X" ] && echo "$X" || echo "$default". If theechofails the default is appended after the partial output, so a config read can return value-plus-default. Same shape assave-session.sh:211.Closes #252