Skip to content

fix(agent-backup): PREV is newest-before-stamp and latest never regresses (#4602) - #4608

Merged
dezren39 merged 2 commits into
mainfrom
queue/6501-4602-agent-backup-prev
Nov 3, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/6501-4602-agent-backup-prev

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #4602.

PREV compared against the greatest snapshot name, so a future-dated directory became the dedup baseline: a duplicate of the true previous snapshot was kept, and latest repointed backwards. This change selects the newest snapshot strictly before STAMP instead, and only moves latest forward when the new snapshot is the newest on disk.

Evidence:

  • Reproduced pre-fix with a fake-date probe (future dir present): duplicate of true previous kept as new snapshot, latest regressed 2027 -> stamp.
  • Post-fix probe: no change since <true-prev>, duplicate removed, latest stays on future snapshot.
  • bash pkgs/agent-backup/test-backup.sh: same-second collision regression PASS (unchanged), new future-dated PREV/latest regression PASS.

Same-second suffixed names (#3340) keep in-second order (string comparison); candidate list unchanged.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…sses (#4602)

PREV compared against the greatest snapshot name, so a future-dated
directory became the dedup baseline: a duplicate of the true previous
snapshot was kept, and latest repointed backwards. Select the newest
snapshot strictly before STAMP instead, and only move latest forward
when the new snapshot is the newest on disk.

Regression test covers duplicate-of-true-previous, mirror, and
newest-run cases with the existing fake-date pattern.
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 22:09
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e26c506-c8a8-4778-b2d4-ea55f10cfde2
Commits

Reviewing files that changed from the base of the PR and between 9f730f1 and 398967b.

Files selected for processing: 2
  • pkgs/agent-backup/backup.sh
  • pkgs/agent-backup/test-backup.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T22:54:11.740688Z 398967b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 329a112246

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/agent-backup/backup.sh Outdated
# included: a bare stamp sorts before its suffixed siblings.
PREV="$(find "$ROOT" -mindepth 1 -maxdepth 1 -type d -not -name "$STAMP" -printf '%f\n' |
sort | tail -n1 || true)"
awk -v stamp="$STAMP" '$0 < stamp' | sort | tail -n1 || true)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add awk to the backup service's runtime dependencies

In the deployed systemd service, home/common/default.nix:492–499 explicitly sets PATH to only coreutils, diffutils, and findutils; none provides awk. This new pipeline therefore fails with awk: command not found, but the trailing || true masks the failure and leaves PREV empty. Every invocation retains its snapshot even when nothing changed, silently disabling deduplication. Add pkgs.gawk to the service PATH or implement the filter using an existing dependency.

Useful? React with 👍 / 👎.

Comment on lines +103 to +106
NEWEST="$(find "$ROOT" -mindepth 1 -maxdepth 1 -type d -not -name "$STAMP" -printf '%f\n' |
sort | tail -n1 || true)"

if [ -z "$NEWEST" ] || [[ "$STAMP" > "$NEWEST" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude in-flight snapshots from the latest-pointer guard

When two backups overlap, the newer directory may only be an incomplete reservation. With latest pointing to an older snapshot P, run A can finish copying changed content X while run B reserves a newer timestamp and pauses before copying. A sees B here and skips updating latest; B then copies X, deduplicates against A, and deletes itself. Both runs succeed, but latest remains on P rather than the newest retained snapshot A, and subsequent unchanged runs exit without repairing it. Serialize deduplication/publication or distinguish completed snapshots from reservations before suppressing the update.

Useful? React with 👍 / 👎.

…#4602)

The service PATH is coreutils+diffutils+findutils only, so the awk
filter failed (masked by || true) and left PREV empty. Use a sorted
sentinel scan with bash builtins instead; same newest-before-stamp
semantics, same-second suffixed names keep in-second order.
@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Reply to Codex P2 (awk in runtime PATH): fixed in 398967b. The awk -v stamp ... '$0 < stamp' filter assumed a tool the agent-backup systemd service does not provide (PATH is coreutils+diffutils+findutils only), and the trailing || true masked the failure by leaving PREV empty. Replaced with a sorted-sentinel scan using only findutils+coreutils+bash builtins (find -printf, LC_ALL=C sort -u, [[ == ]] equality walk). Verified: test-backup.sh same-second PASS + future-dated PASS, plus a green run with a failing awk stub on PATH, bash -n clean, and a code-line scan with no awk/grep/sed/perl/python. Same newest-before-stamp semantics; suffixed #3340 names keep in-second order.

Reply to Codex P2 (overlapping reservations leaving latest stale): acknowledged as a real but out-of-scope race. This task's acceptance is that latest never regresses; the newer-run-reserves-then-dedups sequence leaves latest on the older retained snapshot instead of the newest retained one, which is stale but not a regression. Serializing dedup/publication (flock or completed-vs-reserved marking) would be a separate change with its own tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant