Skip to content

fix(cli): keep a downloaded drop recoverable when the inbox keep fails - #240

Merged
philbert440 merged 1 commit into
release/0.8.19-rcfrom
fix/issue-237
Nov 25, 2026
Merged

philbert440 merged 1 commit into
release/0.8.19-rcfrom
fix/issue-237

Conversation

@philbert440

@philbert440 philbert440 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #237

Why

A once-only drop is consumed on the server when rh memory receive downloads it. If Inbox::keep then failed on sync_all or persist_noclobber (disk full, permissions, a name collision), the tempfile was deleted and the bundle was lost. The sender had to share again. Recovery has to bring that drop back without promoting bad bytes or replacing a good copy.

What changes

On a keep failure the bytes persist as <slot>.rcv in the inbox, without replacing an existing one. The recovered file and the inbox directory are synced, and if that sync fails the error says the file may not survive a crash. The error names the path and says to rerun rh memory receive with the same code. If even the rename fails, the tempfile is kept under its own name and the error says where it is and what to rename it to.

The recovery suffix is .rcv, no longer than .age, so the recovery name fits whenever the ciphertext name fits. .partial could exceed the 255-byte filename limit for long server authorities.

Receive now reads both the .age and the .rcv copy and opens them with the share code's key and the trust store. The .age is tried first. If it is unreadable or fails to open, the .rcv copy is tried, and both files stay on disk until one opens. If neither opens, the error is the .age copy's.

A .rcv copy that opened is promoted with a hard link and an unlink, so an existing .age, including one written by a concurrent receive, is never replaced. If the destination exists the candidate stays where it is. A copy that fails the key check is never promoted. The "ciphertext stays in" messages name the copy that actually opened.

prune skips a file that another receive already removed instead of failing. mark_received removes both names.

Not changed: retention is still measured from the file's write time.

Proved with: unit tests in inbox.rs for an unreadable primary falling back to the recovery copy, both copies staying on disk, no-clobber promotion, a 255-byte .age name still fitting its .rcv name, and prune skipping a vanished file. Integration tests that plant a corrupt .age beside a valid .rcv and receive with zero GETs, plant a forged .rcv and assert no .age appears, and plant a valid .rcv and receive with zero GETs. The long-name unit test and the two new integration tests fail on the previous commit. cargo xtask check GATE OK, cargo xtask commits origin/release/0.8.19-rc..HEAD GATE OK, and nextest on cli and rivethub at 754 passed.

A failed sync or noclobber persist dropped the tempfile and lost a drop
the server had already consumed. The bytes now persist as <slot>.rcv,
synced with the inbox directory, and the error names the path and says
if durability could not be confirmed.

Receive opens the kept .age first and falls back to the .rcv copy when
the primary is unreadable or fails the share code's key check, keeping
both files until one opens. Only a copy that opened is promoted, with a
hard link so an existing .age is never replaced, and prune treats a file
another receive already removed as nothing to do.

Fixes #237
@philbert440
philbert440 merged commit ff2ae20 into release/0.8.19-rc Nov 25, 2026
8 checks passed
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.

1 participant