What changed: steady.WriteFile, on a write that went through, removes
the temp files a crashed or failed write of the same file left beside
it - its own .<file>.<digits> shape and edit.WriteAtomic's
.<file>.<digits>.tmp alike, both old enough (10 minutes) to belong to
no write still going on, and only ones whose remainder is digits, so
another file's temps (.models.yml.bak.1.tmp is models.yml.bak's) stand.
edit.WriteAtomic reaps through the same function: one reaper, both
shapes, every folder magpie writes its own files in. Nothing reaped a
steady temp before - edit reaped only its own .tmp shape - so a
multi-instance start-up exiting mid-write (the reaping exists beside
each write, and nothing swept) left hundreds beside magpie's own files
over a run, and every O_EVTONLY descriptor the directory watcher holds
per file with them (#4938 Bug 1: 758 temps, 839 descriptors). A write
younger than the ten minutes stays, as another write may still be on
it; a stalled write that loses its temp here fails its rename and
leaves the file as it was.
Bug 2 beside this one is yetone's b295d1196 (v0.1.2785); Bug 3 stays
open.
Run:
- go test ./internal/steady -run TestWriteFileReapsStaleTemps -count=1
RED before (the .123 and .789.tmp temps a write leaves behind stay),
green after: this package's shape and edit's reaped, a younger one
and another file's stay.
- go test ./internal/edit -count=1, ./internal/steady -count=1: ok.
Generated-by: GLM-5.3-Flash (ZCode)
Reviewed and ported: a follow-up to b295d1196 (Bug 2), not a duplicate.
On mote, with steady.go and edit/file.go at the parent:
TestWriteFileReapsStaleTemps FAIL (".quotas.json.123: stays true, want
false", ".quotas.json.789.tmp: stays true, want false"); green with the
patch. go test ./internal/steady ./internal/edit ok on mote and on
Windows (win-run); GOOS=linux/windows/darwin go vet -tags nogui ok.
Not reaped (siblings, not in this change): plugin-auth.json's
.tmp-<pid> temps and gemini_sigstore's .tmp-* shape. Bug 3 (CPU) stays
open. Not tried: a real multi-instance start-up on the reporter's Mac.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>