fix(crons): probe stat -c before stat -f in writeback.sh#34
Open
jdbridgeman wants to merge 1 commit into
Open
Conversation
`_refresh_reconciling_if_fresh` probed the .reconciling marker's mtime with BSD-style `stat -f %m` first. On GNU coreutils `-f` means "filesystem status", so `stat -f %m <file>` prints a multi-line filesystem block to stdout and exits non-zero. The `|| stat -c %Y` fallback then appends the real epoch, leaving `marker_mtime` as a blob containing the word "File". The arithmetic on the next line dereferences `File` as a variable and, under `set -u`, exits the whole script. This crashes both `audit` and `set-alive` (each calls the helper at its tail, after the registry write) whenever the marker is present — i.e. during every `/agent:crons reconcile` and heartbeat cron-repair on a GNU/Linux host (reproduced on WSL2 / Ubuntu coreutils). Probe `stat -c %Y` first: it succeeds on GNU and fails cleanly with no stdout on BSD/macOS, where `stat -f %m` then takes over. Matches the GNU-first, value-checked convention already used by `_detect_date_flavor`. A numeric guard is added so any future stat oddity can't re-trip `set -u`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
On Linux,
_refresh_reconciling_if_freshcrashes the script — which breaks/agent:crons reconcileand the heartbeat's cron repair.It reads the marker's mtime with
stat -f %mfirst. On GNU coreutils-fmeans "filesystem status", so that prints a multi-line block to stdout and exits non-zero — the|| stat -c %Yfallback then appends the real epoch, leavingmarker_mtimeas a blob containing the wordFile. The next line's$((now_s - marker_mtime))treatsFileas a variable, andset -ukills the script.Repro on any Linux host:
Fix: probe
stat -c %Yfirst (works on GNU, fails clean on BSD/macOS wherestat -f %mtakes over) — same GNU-first approach already used in_detect_date_flavor. Plus a numeric guard so a bad read can't tripset -uagain.Hit this on WSL2/Ubuntu; reconcile and audit pass after the change.