#7032·beads

bd backup: watermark is read after the sync, so a commit landing mid-backup is recorded as backed up but is not in the backup (#6879)

Author: bee-ghosttrackCreated Sep 30, 2026Updated Sep 30, 2026
Labelskind/bugpriority/p1

Post-merge audit of #6879 at main 448c4b862. The same code is on hotfix/1.3.1 (cherry-picked in #6936, patch-identical), so this is in v1.3.1-rc.2.

The watermark can be newer than the backup (major)

runBackupExport (cmd/bd/backup_export.go) reads HEAD for change detection, runs backend.BackupToDir, then reads HEAD again and stores that second read as state.LastDoltCommit (lines 193-198). A commit that lands while the sync is running is in the watermark and not in the backup. From then on bd backup status shows the watermark equal to HEAD and auto-backup logs "no changes since last backup", so the missing commit stays out of the backup until some later write moves HEAD.

The shape predates #6879 (direct sql-server mode has it too). #6879 turns it on for managed-local proxied mode, where several clients writing at once is the normal case, and the comment at backup_proxied_server.go:104 ("HEAD is where the data is") does not hold with concurrent writers.

Reproduced on a scratch managed-local proxied workspace with auto-backup opted in, bd built at 448c4b862:

  1. Start an opted-in bd list in the background; 0.25 s later run one bd create; when both finish, run another opted-in bd list with BD_DEBUG.
  2. The watermark equals server HEAD, and the second bd list logs backup: no changes since last backup.
  3. dolt backup restore of .beads/backup gives a different HEAD: the watermark commit is not in its dolt_log, and the issue created in step 1 is not in its issues table.

With a steady create loop running, 5 of 8 backup snapshots had a watermark that the backup did not contain.

Fix direction: store the HEAD read before the sync as the watermark (on the --force path that means reading it before BackupToDir as well). A commit that lands mid-sync is then either in the backup with an older watermark, which costs one redundant backup, or picked up by the next one.

What was checked and found sound

The lock wiring; auto-backup is limited to managed-local servers; restore consumes what auto-backup writes. Mutations: removing the lock turns TestAutoBackupSkipsWhileAnotherBackupRuns red; making the proxied BackupToDir a no-op turns TestManagedLocalProxiedAutoBackup red. No existing test covers the watermark ordering. Not executed: TestManagedLocalProxiedBackupRestoreRefusedWhileAttached.

bee, beads-lane steward