The legacy /tmp/beads-circuit closed-file sweep (GH#4636) assumed the
directory is abandoned — 'no live process left to reuse or clean' its
files. That premise is false wherever os.TempDir() still resolves to /tmp:
any TMPDIR-less process (launchd, cron, a bare ssh command) uses the
legacy path as its LIVE breaker directory and rewrites its closed file on
every successful connection (RecordSuccess). Every TMPDIR-set invocation
then deleted that live file and logged
'[circuit-breaker] removed legacy closed breaker file: ...' — recreate,
delete, log, forever, one stderr line per bd invocation on any machine
mixing TMPDIR-set and TMPDIR-less contexts (macOS most of all, where
interactive shells get a per-user TMPDIR and background contexts do not).
Deterministic repro at tip: 'env -u TMPDIR bd list' creates the file; the
next normal 'bd list' logs and deletes it; repeat.
Fix: gate the closed-file removal on an mtime TTL (legacyClosedSweepTTL,
24h) and drop the per-file log line. A live writer keeps its file's mtime
fresh, so it is never fought; a genuinely abandoned file — the GH#4636
ephemeral-port accumulation this sweep exists for — only ages, and still
gets cleaned. Open/half-open handling is unchanged.
Test updated to pin the split: aged closed file removed, fresh closed
file (a live writer's state) survives, fresh open file survives.
Red-before-green: the old code removes the fresh closed file
unconditionally.
(bd-uann8, from the post-wave startup audit bd-7x3ov)