You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NDC's commit mvs across filesystems, so the atomicity #142's design rests on is not the atomicity it gets #242
$MEMORY_FILE is ${REMEMBER_DIR}/now.md. $TMPDIR is a different filesystem in ordinary configurations — /tmp is tmpfs on most Linux distributions, and external storage mode (data_dir) can put REMEMBER_DIR on a different volume from $TMPDIR on any platform. Across filesystems mv is not a rename: it is copy-then-unlink, and now.md is destroyed and rewritten in place rather than swapped.
#142's suggested fix wrote "$MEMORY_FILE.tmp" — beside the target, where the atomicity argument holds. The implementation moved it to $TMPDIR and kept the argument.
What it costs
The window is the copy, not a syscall. A machine that loses power, a SIGKILL, a full destination filesystem, or an ENOSPC partway through leaves now.mdtruncated mid-copy: not the old content, not the new content, a prefix of the tail. The save lock is held (#223/#224), so no concurrent writer is involved — this is single-process durability, which the lock cannot help with.
It also silently changes the file's inode, mode and — on a copy — its ownership semantics, which is why the .remember/.gitignore and permissions assumptions elsewhere are worth a look in the same pass.
Fix
mktemp "${MEMORY_FILE}.ndc-XXXXXX" (or "$(dirname "$MEMORY_FILE")"/…) so the mv is a same-directory rename and the atomicity the comment claims is the atomicity the code gets. The same applies to any other temp that is mv'd onto a memory file; the temps that are only read ($NDC_PROMPT, $HAIKU_STDERR, $TMP_PROMPT) are fine where they are and should stay there.
Worth a test that plants a destination on a distinct filesystem, or — cheaper and portable — asserts the temp path is a sibling of the target rather than asserting an mv failure mode.
Found while building the save.lock hold-time recorder for #226; not fixed there, because it deserves its own red test.
Correction to this issue's own body, recorded because it is closed and nobody will revisit it otherwise.
The body predicts truncation — "a crash mid-copy leaves now.md truncated", a surviving prefix. That understates it. Reproduced during #245 against a real second filesystem:
BSD mv unlinks the partial destination, so now.md was gone entirely — total loss, not a prefix.
GNU mv leaves the prefix, which is the case the body describes.
Either way the log reported kept 5400000b appended during compression — a byte count taken off the temp file before the move, so it prints whether or not the commit landed.
So on macOS the failure is: the memory file is destroyed, and the log says it kept 5.4 MB.
Fixed in #245 (64cea0c) by committing through a sibling-directory rename — a real rename(2), which has no intermediate state — with the result checked and the #141 day marker moved only inside the success arm. The pattern was already in this repo three times over (lib-env-cache.sh:170-174, whose comment reads "Rename, so no reader ever parses a partial file", and post-tool-hook.sh:260); the NDC commit was the one call site that had not adopted it.
Recording this because scoping from a closed issue's body is exactly how a fix gets sized wrong: the same mv still exists one file over in run-consolidation.sh:201 (#246), and anyone reading this issue to size that one would come away expecting a recoverable prefix.
Activity
fix(ndc): commit now.md by rename and gate the day marker on it (#245)
fdaviddpt commentedon Jul 30, 2026
Correction to this issue's own body, recorded because it is closed and nobody will revisit it otherwise.
The body predicts truncation — "a crash mid-copy leaves
now.mdtruncated", a surviving prefix. That understates it. Reproduced during #245 against a real second filesystem:mvunlinks the partial destination, sonow.mdwas gone entirely — total loss, not a prefix.mvleaves the prefix, which is the case the body describes.kept 5400000b appended during compression— a byte count taken off the temp file before the move, so it prints whether or not the commit landed.So on macOS the failure is: the memory file is destroyed, and the log says it kept 5.4 MB.
Fixed in #245 (
64cea0c) by committing through a sibling-directory rename — a realrename(2), which has no intermediate state — with the result checked and the#141day marker moved only inside the success arm. The pattern was already in this repo three times over (lib-env-cache.sh:170-174, whose comment reads "Rename, so no reader ever parses a partial file", andpost-tool-hook.sh:260); the NDC commit was the one call site that had not adopted it.Recording this because scoping from a closed issue's body is exactly how a fix gets sized wrong: the same
mvstill exists one file over inrun-consolidation.sh:201(#246), and anyone reading this issue to size that one would come away expecting a recoverable prefix.fix(#246): checked, same-directory rename for the consolidation stagi…