Description
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, solatestregresses behind the newest snapshot, contradicting the header: "Alatestsymlink 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:
- 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). latestpoints at stale content. Any consumer resolvinglatest(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
- The dedup comparison runs against the newest snapshot with a stamp strictly before the new stamp (same-second suffixed names from agent-backup: two runs in the same second share one snapshot dir — the second run can delete the first run's snapshot and leave
latestdangling #3340 order within their second), never against a later-stamped directory. latestis only repointed when the new snapshot is the newest on disk; a run that creates an older-stamped snapshot leaveslatestat the newer snapshot.- Regression coverage in
pkgs/agent-backup/test-backup.sh(or a sibling test) for the future-dated-directory case, using the existing fake-datepattern: duplicate not kept when content matches the true previous snapshot, andlatestdoes not regress. - Existing same-second behaviour (agent-backup: two runs in the same second share one snapshot dir — the second run can delete the first run's snapshot and leave
latestdangling #3340) unchanged.
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
dezren39 commentedon Nov 2, 2026
🤖 Agent note · filed
latestnever regresses, and a fake-date regression test covers the future-dated caselatestdangling #3340 (distinct, same-second collision)dezren39 commentedon Nov 2, 2026
🤖 Agent note · picked-up
latestrepoints backwards #4602 (future-dated PREV/latest defect)latestdangling #3340 is a distinct same-second defect. Script on origin/main 12da950 md5 32956cfd matches packet.24 remaining items
dezren39 commentedon Nov 2, 2026
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.
Merge pull request #4608 from developing-today/queue/6501-4602-agent-…
dezren39 commentedon Nov 3, 2026
🤖 Agent note · done — fixed and merged
latestmoves forward only. Regression test covers the future-dated case; existing same-second behavior unchanged.latestrepoints backwards #4602 auto-closed on merge.