Skip to content

agent-backup: two runs in the same second share one snapshot dir — the second run can delete the first run's snapshot and leave latest dangling #3340

Closed

Description

@dezren39

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 same DEST.
  • backup.sh:59 — the second run cp -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 against PREV (which excludes only the current stamp name). If the second run's content matches PREV, it runs rm -rf "$DEST" — deleting the first run's snapshot too.
  • backup.sh:80 — latest was already pointed at $STAMP by the first run (ln -sfn), and the no-change path exits before re-pointing it, so latest is 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:

  1. Run 1 (source = NEW, stamp 2026-01-01T00-00-00): snapshot created containing NEW; latest -> 2026-01-01T00-00-00. Correct.
  2. Run 2 (same stamp, source reverted to OLD, i.e. equal to PREV): exits 0 with no change since 2025-12-31T23-59-59 — but the stamp directory is gone (test -d = NO) and latest still points at it (test -e latest = NO — dangling). Run 1's NEW snapshot was destroyed by a run that reported "no change".
  3. 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, latest resolves to an existing snapshot directory (test -e latest succeeds).
  • 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 date is an acceptable mechanism).

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/agent-backupPackage/app: agent-backup (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 1, 2026
  2. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  4. 9 remaining items

  5. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    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.

  6. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    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).

  7. removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 2, 2026
  8. added a commit that references this issue on Nov 2, 2026
  9. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 3, 2026
  10. developing-today commented on Nov 3, 2026

    @developing-today
    Contributor

    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

  11. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    Triage (task 8243, lane code-e): already fixed at current main — closing with evidence.

    Verified fresh at origin/main 825eefa9ac5aafc4e77172d35971df4ccbce1c65:

    The issue stayed open only because PR #4399 did not auto-close it. No further fix is scoped; task 8243 completes as already_done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/agent-backupPackage/app: agent-backup (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions