Skip to content

fix: a backup copy directory holds one installation's backups - #116

Merged
TusanHomichi merged 5 commits into
mainfrom
claude/115-copy-ownership
Oct 15, 2026
Merged

TusanHomichi merged 5 commits into
mainfrom
claude/115-copy-ownership

Conversation

@TusanHomichi

@TusanHomichi TusanHomichi commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Primary Issue

Closes #115 (found by the #97 restore drill)

Problem And Outcome

Following docs/install.md's "server's disk is gone" procedure literally restored an empty database. The new server's scheduler copied its own blank snapshot into the share, where it became the newest file, and "restore the newest file" restored it. A new server left running also pruned the real copies within 14 backups, and a restore's set-aside database was copied off the server too.

After this PR, the same procedure, followed literally, brings the records back unchanged. This is proven against a share written by the published v0.1.0.

Changes

  • backup_copy::copy_snapshot, the one path for every copy (scheduler, backup --backup-copy-dir, pre-migration copy):
    • refuses a snapshot whose installation differs from the share's;
    • the share's installation is the one in its newest readable own backup, falling back to its newest readable copy of any kind, since 0.1.0 also copied pre-restore snapshots;
    • ids are read from the files through the new storage::open_snapshot, which is read-only and immutable, so no sidecar lands on the share;
    • unreadable files neither claim the share nor block it;
    • the refusal says to restore, or to give the installation its own directory.
  • Catch-up's retention runs the same check before pruning anything, so a same-named foreign file can never authorize deleting the lost installation's copies.
  • Own backups only. backup::own_backups_in returns scheduled and pre-migration snapshots, never prerestore ones. It is used by:
    • catch-up;
    • copy status (doctor, /api/backups/status, home page);
    • freshness (latest_snapshot_mtime, which drives the scheduler and doctor);
    • doctor's backups line, which warns when only a set-aside database exists.
  • restore:
    • ends with backup::run_after_restore, so the restored database is the newest backup and copying resumes at once;
    • the set-aside goes through the same snapshot owner (backup::set_aside_before_restore) instead of a duplicate path;
    • a snapshot within a second of the last waits for a new name instead of failing. That collision used to mislabel the set-aside database as .damaged, as the drill observed.
  • Docs:
    • docs/install.md gives the step-by-step replacement-server procedure;
    • ADR 0024 is amended ("A copy directory holds one installation's backups");
    • CHANGELOG Fixed.

Correction rungs:

  • 1: one owner each for copying (copy_snapshot), making snapshots (take_snapshot), and the own-backup selection (own_backups_in);
  • 2: integration tests.

Verification

  • tests/copy_ownership.rs, 7 tests:
    • a replacement server never copies over the installation it replaces, then copies again after restoring;
    • a newer pre-restore snapshot is never copied or counted;
    • the same installation keeps copying;
    • a foreign copy with the same name is never pruned;
    • a share holding only a pre-restore copy is still owned;
    • a fresh pre-restore snapshot doesn't make old backups look current, for the scheduler or doctor;
    • only a set-aside database counts as no backup.
  • Negative controls, each run once: removing the owner check, the pre-prune check, the legacy fallback, or the own-backup freshness fails the matching test.
  • Full local proof on a609ab5: passed, all 7 gates. The browser suite was 61/0/0. Receipt .proof/20261015T014618Z-a609ab53b7ce/receipt.json, sha256 1c83d21be60f6f0318239f576000a3799045e2a44b6668d64d7407d1b4bf48fe. Earlier heads cd4c5bc, f046775, and 0691a75 passed too.
  • Restore drill against the real v0.1.0 release (recovery: clean-room restore drill from a release install #97):
    • Before (0.1.0 as host B): host B copied its own empty database into the share, restoring the newest copy restored it, and sign-in failed with 401.
    • After (this code as host B):
      • host B logged backup copy failed: … holds the backups of installation 67789a46-…;
      • the share was unchanged;
      • restore reported host A's id and backed up the restored database;
      • doctor was all ok with the copy current;
      • all 3 records match on content hash, chain hash and acknowledgment;
      • every export passes export verify.
  • Codex, four rounds:
    • Fixed: the prune path, legacy pre-restore ownership, freshness from own backups, and the doctor warning with no own backup.
    • Declined with traced reasoning on each thread: a first-copy race between two installations on one empty share; a same-second cross-installation name collision showing current; and two concurrent same-second backups. Each needs an unsupported two-writer setup or same-second timing, and the outcomes are benign or self-reported.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts


Generated by Claude Code

A new server set up to replace a lost one copied its own empty database
into the share as the newest backup, so restoring "the newest copy" (as
the install guide said) brought back nothing; the #97 restore drill hit
it against the v0.1.0 release.

- copy_snapshot refuses a snapshot whose installation differs from the
  newest readable copy's, both read from the files read-only and
  immutable, so shares written by 0.1.0 are protected too.
- Catch-up and copy status consider only the installation's own backups:
  never the database a restore set aside.
- restore ends with a backup of the restored database, so copies resume
  from it at once; the set-aside goes through the same snapshot owner,
  and a snapshot within a second of the last waits for a new name.

Closes #115

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-10-15T01:51:42.088038Z a609ab5 Manual request
ℹ️ 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: 62e8f6573e

ℹ️ 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".

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: cd4c5bc085

ℹ️ 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".

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: f0467756fc

ℹ️ 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 crates/consolebook-server/src/doctor.rs Resolved
A database a restore set aside no longer postpones the next backup or
makes old backups look fresh to doctor and the health read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: 0691a7546e

ℹ️ 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 crates/consolebook-server/src/doctor.rs Resolved

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: a609ab53b7

ℹ️ 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 crates/consolebook-server/src/backup.rs Resolved
@TusanHomichi
TusanHomichi merged commit bb4d7f3 into main Oct 15, 2026
4 checks passed
@TusanHomichi
TusanHomichi deleted the claude/115-copy-ownership branch October 15, 2026 01:57
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.

backup copies: a replacement server copies its empty database over the share's newest backup

2 participants