Skip to content

Backup before a file write: fail when the source changes during the copy #1737

Backlog

Description

@smart-ssh-planner

Goal

A backup made before a confirmed file write is a consistent copy of one file version, even if the file is replaced while it is being copied.

Context

Follow-up of #1714 (PR #1728): copy_to_backup_inner (crates/app-logic/src/orchestration/remote_files.rs:370-413) copies via SftpSession::read_range, which opens the file anew for every 256 KiB chunk (crates/ssh-transport/src/sftp.rs). If the file is atomically replaced (rename over it) mid-copy, chunks come from different files and the backup is a mix, while the recorded SHA-256 describes that mix.

Requirements

  • After the copy, stat the source again; when its size or modification time differs from the values taken before the copy, the backup fails: the partial/mixed backup is removed best-effort and the write fails before the target is touched.
  • No change for files that stay unchanged.

Acceptance Criteria

  • Mock: a source whose mtime (or size) changes during the copy makes the write fail, the backup is removed, the target is untouched.
  • An unchanged multi-chunk file is backed up byte-for-byte as before.
  • A failing second stat fails the backup safely (no backup left).
  • Relevant automated tests pass

Technical Notes

Chosen over a single open handle because the trait has no handle-based read (adding one would change every SftpSession implementation and mock). Alternative for the coder: a new read_handle API. Spec 0020 §4.2.4: one sentence that a file changing during the backup fails the write.

Files: crates/app-logic/src/orchestration/remote_files.rs, crates/app-logic/src/orchestration/action_exec/tests_activity.rs, crates/core/src/ssh/mock.rs, docs/specs/0020-sftp-file-transfer.md

Spec impact: update 0020

Open questions

  • Re-check by stat (recommended) or add a handle-based read to the trait.

Related Work

Activity

  1. added
    follow-up
    on Dec 4, 2026
  2. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    Needs maintainer: The issue waits for #1733, but "blocked by" could not be set. Set it on the issue (Relationships), then remove needs-maintainer: The code this issue changes (copy_to_backup_inner, chunked read_range backup from #1714/PR #1728) exists only on release/0.8.0; develop still has the old read_file-based write_via_sftp_with_backup. Waiting for the back-merge of release/0.8.0 into develop (#1733).

  3. added
    needs-maintainer
    question-triage
    and removed
    question-triage
    needs-maintainer
    on Dec 4, 2026
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

    follow-upsecurityssh

    Type

    Fields

    Priority

    P3 - Low

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions