Repository navigation
Description
Bug: two agent-backup runs in the same second share one snapshot directory — the second run can delete the first run's snapshot and leave latest dangling
pkgs/agent-backup/backup.sh names each snapshot with one-second resolution and never checks whether that directory already exists:
backup.sh:28-29—STAMP="$(date -u +%Y-%m-%dT%H-%M-%S)",DEST="$ROOT/$STAMP". Two runs started within the same second (the script runs "on change", so a watcher/timer firing twice, or a timer run overlapping a manual run, is enough) compute the sameDEST.backup.sh:59— the second runcp -ps its files into the first run's snapshot directory, overwriting/merging in place. The first snapshot is silently no longer the state it captured.backup.sh:71-76— the dedup step then compares that shared directory againstPREV(which excludes only the current stamp name). If the second run's content matchesPREV, it runsrm -rf "$DEST"— deleting the first run's snapshot too.backup.sh:80—latestwas already pointed at$STAMPby the first run (ln -sfn), and the no-change path exits before re-pointing it, solatestis left dangling: it names a snapshot that no longer exists.
Verified this run (laptop probe, sha-matched script)
Probe: ~/git/fleet/probe-2026-10-31-laneB-agentbackup/ on the laptop — the verbatim backup.sh from main a8189c21 (sha256 d3c9978b7e96fd18fd038d9bb321bde2cdf070d95c398fee857dd6c0b62b4303, matched on sandbox and laptop), HOME/AGENT_BACKUP_DIR pointed at a scratch tree, date stubbed via PATH to a fixed stamp (the standard way to hit a one-second window deterministically), one candidate file (~/.claude/settings.json), and a pre-seeded previous snapshot 2025-12-31T23-59-59 containing OLD:
- Run 1 (source =
NEW, stamp2026-01-01T00-00-00): snapshot created containingNEW;latest -> 2026-01-01T00-00-00. Correct. - Run 2 (same stamp, source reverted to
OLD, i.e. equal to PREV): exits 0 withno change since 2025-12-31T23-59-59— but the stamp directory is gone (test -d= NO) andlateststill points at it (test -e latest= NO — dangling). Run 1'sNEWsnapshot was destroyed by a run that reported "no change". - Control (fresh stamp
2026-01-01T00-00-01, source =OLD= PREV): no new directory, exit 0 — the dedup path behaves as designed when the stamp is unique.
Why it matters
This script is the only backup of the machine's irreplaceable agent credentials (auth.json files, API keys — see the header comment). Its whole contract is "the history only ever grows when something actually differs" and "latest points at the newest snapshot". A same-second pair of runs breaks both halves of that contract silently, with exit 0: a real snapshot is destroyed, and anything restoring from latest (the documented entry point) finds nothing. The failure needs no exotic setup — the script is designed to be fired on change, where double-fires inside one second are routine.
Acceptance criteria
- Two runs started in the same second never share a snapshot directory: the second run either gets a distinct directory (e.g. suffix/sub-second component) or is refused/coalesced explicitly — it never writes into or deletes another run's snapshot.
- After any sequence of same-second runs,
latestresolves to an existing snapshot directory (test -e latestsucceeds). - The no-change path only ever removes a directory the same run created.
- Normal behaviour unchanged: a run whose content differs from the previous snapshot creates exactly one new snapshot and repoints
latest; a run identical to the previous snapshot creates none. - A regression test/harness case covers the same-second pair (stubbed
dateis an acceptable mechanism).
Activity
dezren39 commentedon Nov 1, 2026
🤖 Agent note · filed
latestdangling #3340 — pkgs/agent-backup/backup.sh stamps snapshots with one-second resolution (backup.sh:28-29) and never checks DEST existence; verified on laptop probe probe-2026-10-31-laneB-agentbackup (sha-matched script d3c9978b,datestubbed via PATH, scratch HOME/AGENT_BACKUP_DIR): run 1 (content NEW) created snapshot S + latest→S; run 2 in the same stamp with content reverted to PREV's value exited 0 "no change" after rm -rf'ing S — latest dangling, run 1's snapshot destroyed; distinct-stamp control behaved as designed. Enqueued as a repo-task/v1 triage packet on repo-health-code-pilot.latestalways resolves; no-change path only removes its own directory; regression harness case with stubbed date).latestdangling #33409 remaining items
dezren39 commentedon Nov 2, 2026
agent-note:v1 — holder: repo-worker-code (OpenChamber scheduled lane), at 2026-11-02T15:06:15Z. event: implementation_complete; task: 5943; queue: repo-health-code-pilot. Outcome PR opened: #4399. Reporter-producible collision is covered by stubbed-date regression. Starting CI poll before terminal sync.
dezren39 commentedon Nov 2, 2026
agent-note:v1 — holder: repo-worker-code (OpenChamber scheduled lane), at 2026-11-02T15:11:45Z. event: done; task: 5943; queue: repo-health-code-pilot. Fix implemented and targeted regression passed; PR #4399 is OPEN, non-draft, clean/mergeable. No pending or failing CI checks are reported (CodeRabbit is neutral/skipping).
Merge pull request #4399 from developing-today/queue/5943-3340-agentb…
developing-today commentedon Nov 3, 2026
agent-note:v1
state: triaged (coverage pass)
Coverage pass 2026-11-03: reviewed in the fleet-wide per-issue pass (drift / overlap / already-handled / stale / blockers / ordering). Verdict: still live; queued in repo-health-code-pilot as triage at priority 40 (priority/normal). If this is already handled at current main, the triage closes it with evidence; if it needs splitting, the triage files the split.
Found via: coverage pass 2026-11-03
dezren39 commentedon Nov 3, 2026
Triage (task 8243, lane code-e): already fixed at current main — closing with evidence.
Verified fresh at
origin/main825eefa9ac5aafc4e77172d35971df4ccbce1c65:latestdangling #3340)" merged 2026-11-02T15:24:47Z (merge commite28805a456017eddb3c51aee8f8df5bb4beaeec9), implementing exactly this issue's acceptance criteria:backup.shnow reserves the destination atomically withmkdirbefore copying, same-second collisions get deterministic suffixed directories (<stamp>-<zero-padded suffix>), and the no-change cleanup only removes a directory the same run created.pkgs/agent-backup/test-backup.sh(stubbed-date same-second pair + no-change control; PR evidence: PASS,latestresolves, both snapshots kept).latestnever regresses;backup.shcomments explicitly reference the agent-backup: two runs in the same second share one snapshot dir — the second run can delete the first run's snapshot and leavelatestdangling #3340 suffixed-name ordering.The issue stayed open only because PR #4399 did not auto-close it. No further fix is scoped; task 8243 completes as
already_done.