Files
pad/internal
xarmian a630f867f4 fix(cli): a credentials save stamps its own file's mtime before it truncates, so the empty-file memo holds off Linux (BUG-3838) (#2203)
* fix(cli): a credentials save sets the mtime before it truncates, so the empty-file memo holds off Linux (BUG-3838)

BUG-3829's emptyConfirmed memo assumed a save's truncate moves an already
empty file's mtime. That was measured on ext4 only; POSIX moves mtime on
ftruncate only when the size changes, and macOS and Windows were never
measured. On such a platform a process that had memoized an empty file could
answer empty during another process's unlocked save and lose an entry.

writeFileInPlace0600 now sets the mtime itself (os.Chtimes, best effort like
the chmod) before the truncate, so the memo no longer depends on the
truncate's side effect. loadStoreLocked also reads once more when the stat
after its last empty read shows a body (hunter r6 on BUG-3829).

Claude-Session: https://claude.ai/code/session_012QxKpjqXTpU84auY5zZ8FR

* fix(cli): on Windows the save touches its own handle, not the path; the stalled-save test releases on failure (BUG-3838)

Codex r1 could not establish that os.Chtimes works on an open file on
Windows. It does not, safely: UtimesNano opens the path again with only
FILE_SHARE_WRITE, so it fails against a reader holding the file and, while
open, makes a concurrent reader's open fail. touchCredentialsFile now uses
SetFileTime on the handle the save already holds (GENERIC_WRITE includes
FILE_WRITE_ATTRIBUTES); other platforms keep os.Chtimes by path.

The test's stalled save is released and waited for in cleanup, so a failure
before the release leaves no goroutine in the seam (codex r1 Low).

Claude-Session: https://claude.ai/code/session_012QxKpjqXTpU84auY5zZ8FR

* test(cli): the stalled-save test's wait for the write is bounded (BUG-3838)

A save that failed after its release left the read seam spinning until the
global test timeout (hunter r2). It now gives up after five seconds and fails;
cleanup reports the save's error.

Claude-Session: https://claude.ai/code/session_012QxKpjqXTpU84auY5zZ8FR

* fix(cli): on Unix the save's touch goes through its descriptor; the stalled-save test bounds its wait for the truncate (BUG-3838)

Codex r3 Medium: os.Chtimes by path stamps whatever the path names when it
runs, so a path replaced or a symlink retargeted after the open could take
the stamp while the file being truncated kept its old mtime. On Linux, the
BSDs and Darwin the touch is now unix.Futimes on the open descriptor (Linux
resolves it through /proc/self/fd), falling back to the path only when that
fails. TestBUG3838_TouchStampsTheOpenedFile retargets the symlink after the
open and checks which file moved.

Codex r3 Low: the test waited on the seam's truncate signal without a bound;
it now fails if the save returns first or never stalls.

Claude-Session: https://claude.ai/code/session_012QxKpjqXTpU84auY5zZ8FR

* fix(cli): the Unix touch has no path fallback (BUG-3838)

Codex r4 Medium (hunter r4 L2): when the descriptor touch failed, the
os.Chtimes(path) fallback re-resolved the path and could stamp a file other
than the one the save opened. A failed descriptor touch now leaves the save
relying on its truncate, which moves an empty file's mtime on Linux, the one
shipped Unix where futimes can fail for want of /proc.

Claude-Session: https://claude.ai/code/session_012QxKpjqXTpU84auY5zZ8FR
2026-10-15 17:49:09 -04:00
..