Skip to content

agent-backup: PREV selection picks a future-dated snapshot — dedup compares against the wrong snapshot and latest repoints backwards #4602

Description

@dezren39

Bug: agent-backup compares against a future-dated snapshot and repoints latest backwards

pkgs/agent-backup/backup.sh (at origin/main 12da9503c) chooses the "previous" snapshot by name order, not by position relative to the new snapshot, and unconditionally repoints latest at the new stamp:

  • backup.sh:87-88 — PREV="$(find "$ROOT" -mindepth 1 -maxdepth 1 -type d -not -name "$STAMP" -printf '%f\n' | sort | tail -n1)" picks the lexicographically greatest directory that is not the new one. The header contract (backup.sh:9-11) is "the most recent previous snapshot" — a directory with a stamp later than the new run's (clock stepped backwards after an NTP correction or a VM restore, a backup root restored/copied from another machine, or any future-dated snapshot planted by a test) is not previous, but it wins this selection.
  • backup.sh:96 — ln -sfn "$STAMP" "$ROOT/latest" runs whenever the new snapshot survives the comparison, even when a newer snapshot already exists, so latest regresses behind the newest snapshot, contradicting the header: "A latest symlink points at the newest snapshot."

Reproduction (verified this run, laptop probe probe-2026-11-02-laneB-backupfuture/, backup.sh md5 32956cfd09b8f2b61b21d1b679af9088 = origin/main)

Seed a backup root with two snapshots and latest -> 2027-01-01T00-00-00, stub date to 2026-06-01T00-00-00 (the pattern test-backup.sh already uses), and make the current content (CURRENT) identical to the true previous snapshot 2026-01-01T00-00-00 but different from the future snapshot 2027-01-01T00-00-00 (FUTURE):

$ bash backup.sh
agent-backup: snapshot 2026-06-01T00-00-00 (1 files)   # kept — dedup compared against 2027, not 2026-01-01
$ ls backups
2026-01-01T00-00-00  2026-06-01T00-00-00  2027-01-01T00-00-00  latest
$ readlink backups/latest
2026-06-01T00-00-00                                     # regressed behind 2027-01-01T00-00-00

Control, same setup without the future-dated directory: agent-backup: no change since 2026-01-01T00-00-00, no new directory, latest unchanged. So both defects are caused by the future-dated entry alone:

  1. Duplicate snapshot kept. Content unchanged since the actual previous snapshot is stored again, because the no-change comparison ran against the future snapshot — the history grows when nothing actually differs (header contract, backup.sh:9-11).
  2. latest points at stale content. Any consumer resolving latest (restores, audits) silently gets an older snapshot than the newest one on disk.

The mirror-image case also misbehaves: current content identical to the future snapshot but changed versus the true previous one is dropped as "no change since ", erasing the transition from the history ordering.

Why it matters

This script is the safety net for irreplaceable agent credentials/config. Its two promises are exactly the ones broken here: dedup against the previous snapshot, and latest = newest. Both fail silently (exit 0, normal-looking output) in the clock-skew/restore situations a backup tool is most likely to meet.

Acceptance criteria

Distinct from #3340 (same-second collision, fixed in b974eb6): this is about a snapshot directory stamped later than the running clock, which the #3340 fix does not address.

Activity

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

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b, run 2026-11-02 15:50 CST
    • Found via: filed this run
    • Task: Triage the future-dated-snapshot PREV/latest defect in pkgs/agent-backup/backup.sh (probe-verified on the laptop against origin/main 12da950, with a no-future-dir control)
    • Expectation: effort/s — done when the dedup comparison uses the newest snapshot strictly before the new stamp, latest never regresses, and a fake-date regression test covers the future-dated case
    • Links: laptop probe ~/git/fleet/probe-2026-11-02-laneB-backupfuture/; related 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 (distinct, same-second collision)
  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 2, 2026
  4. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked-up

  5. 24 remaining items

  6. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: parked
    task: 6501 (repo-health-code-pilot, repo-worker-code; lane code-i, execution opencode ses_e5e61952257ffe2D0mv2mw30Mx)
    state: parked for 20 minutes after the five-minute CI poll; work/assigned remains.
    fresh_evidence: #4602 OPEN; canonical PR #4608 OPEN and MERGEABLE at 398967b (awk-free PREV fix pushed this run); required basic OpenCode metered-provider guard still QUEUED (run 41540896648); CodeRabbit skipping. Codex P2 review findings answered on the PR (awk fixed + verified with failing-awk-stub run; overlap race noted as out-of-scope staleness, not a regression).
    resume: re-read issue and PR/check state fresh; run/verify tests as needed and merge only when required checks are green and the diff matches intent.
    labels: queue/parked, status/parked, work/assigned; removed queue/claimed, status/in-progress.

  7. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  8. added a commit that references this issue on Nov 3, 2026
  9. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — fixed and merged

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

Metadata

Metadata

Assignees

No one assigned

    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/lowNice to have; do when convenientsource/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