Space rename convergence can adopt an existing folder (possible second takeover path) #931

Closed
opened 2026-10-15 22:28:29 +00:00 by Cordy · 5 comments
Owner

Found while writing the fix-923 spec (R7, §13, 2026-10-16); confirmed by reading the code only, not yet by a test.

What happens: convergeBackend (spacerename.go:186-192) adopts the target folder as the space's folder when the old folder is missing. A rename onto the name of an existing orphan folder could therefore take that folder's files into the space. The convergence sweep can do the same.

Plan: fix-923 refuses renames onto an existing folder for everyone and tests the takeover first (Task 1). This issue tracks the sweep and any remaining adoption path: the sweep must never adopt a folder it did not create or move itself.

Found while writing the fix-923 spec (R7, §13, 2026-10-16); confirmed by reading the code only, not yet by a test. **What happens:** `convergeBackend` (`spacerename.go:186-192`) adopts the target folder as the space's folder when the old folder is missing. A rename onto the name of an existing orphan folder could therefore take that folder's files into the space. The convergence sweep can do the same. **Plan:** fix-923 refuses renames onto an existing folder for everyone and tests the takeover first (Task 1). This issue tracks the sweep and any remaining adoption path: the sweep must never adopt a folder it did not create or move itself.
Author
Owner

Confirmed by test (fix-923 Task 1, on v0.6.345 main code).

S3: a space owner renamed their space onto Stray, an existing folder with no registry record. The rename answered 200, convergence adopted the folder, and the owner could read the folder's existing file old.txt. That is a takeover by rename.

POSIX: the same rename answers 200, but convergence cannot move into the non-empty folder. The space is left named Stray while its backend stays Tiny. There is no file access, but the state is broken.

Folders that already have a registry record (like Orphan): main already refuses the rename with 409.

fix-923 refuses a rename onto any existing folder (R7), for everyone. This issue stays open for the convergence sweep's own adoption rule.

**Confirmed by test** (fix-923 Task 1, on v0.6.345 main code). **S3:** a space owner renamed their space onto `Stray`, an existing folder with no registry record. The rename answered 200, convergence adopted the folder, and the owner could read the folder's existing file `old.txt`. That is a takeover by rename. **POSIX:** the same rename answers 200, but convergence cannot move into the non-empty folder. The space is left named `Stray` while its backend stays `Tiny`. There is no file access, but the state is broken. **Folders that already have a registry record** (like `Orphan`): main already refuses the rename with 409. fix-923 refuses a rename onto any existing folder (R7), for everyone. This issue stays open for the convergence sweep's own adoption rule.
Author
Owner

Deep research (2026-10-18)

Full write-up: ~/cairn-work/scratch/b7e/backlog/research-931.md.

There are two adoption paths, not one.

  • The missing-folder branch (spacerename.go around lines 229-235) adopts an existing folder when the old one is missing. Any Stat error counts as "missing" here, so a transient S3 timeout is enough to trigger it.
  • On S3, the normal move (lines 237-241) also takes over a folder. The S3 driver's Rename copies into an existing folder without checking and merges the files. On POSIX the same move fails with ENOTEMPTY.

Ways in that #927's refusal still allows:

  • A folder that appears under the new name after the rename was accepted, for example from backend tools, flat mode or a backup restore.
  • Spaces renamed before v0.6.346.

Other products. None of the products I checked adopts storage by name:

  • Nextcloud Team folders, OpenCloud, Seafile, Google shared drives and Box key storage by id.
  • Nextcloud removed name-based adoption of user folders as a security fix (PR #14652, #18130).

Option (a) alone breaks S3 crash recovery. After a crash in the middle of a copy, both folders exist, so the space would never converge.

Recommendation: (d) plus (c).

  • (d): record the target folder in the registry (MovingTo) just before moving. Resume or finish only when that record matches. Never move into, or adopt, a folder the rename did not start. This fits the multi-instance rule: no shared lock and no new shared file.
  • (c): an audited, session-admin Finish rename action in Administration > Spaces, with a "Rename not finished" badge and a dialog showing the folder's size, item count and last change. Being a visible action, it needs a mockup.
  • (b), an identity marker in the space folder: sound, but can wait as a follow-up.

What admins would see:

  • WARN spaces: rename not finished with a reason (folder-exists or folder-missing).
  • Audit entries space-converge-failed, and space-converge-adopted when an admin finishes a rename by hand.

Decisions needed (asked now):

  1. Automatic adoption of a folder someone converged by hand: never? (Recommended: never.)
  2. Add (c), a Finish rename admin action (mockup first)?

Separate issues filed:

  • Opening a space whose folder is missing recreates it empty.
  • The S3 driver's Rename merges into an existing destination for every caller.
## Deep research (2026-10-18) Full write-up: `~/cairn-work/scratch/b7e/backlog/research-931.md`. **There are two adoption paths, not one.** - **The missing-folder branch** (`spacerename.go` around lines 229-235) adopts an existing folder when the old one is missing. Any `Stat` error counts as "missing" here, so a transient S3 timeout is enough to trigger it. - **On S3, the normal move** (lines 237-241) also takes over a folder. The S3 driver's `Rename` copies into an existing folder without checking and merges the files. On POSIX the same move fails with ENOTEMPTY. **Ways in that #927's refusal still allows:** - A folder that appears under the new name after the rename was accepted, for example from backend tools, flat mode or a backup restore. - Spaces renamed before v0.6.346. **Other products.** None of the products I checked adopts storage by name: - Nextcloud Team folders, OpenCloud, Seafile, Google shared drives and Box key storage by id. - Nextcloud removed name-based adoption of user folders as a security fix (PR #14652, #18130). **Option (a) alone breaks S3 crash recovery.** After a crash in the middle of a copy, both folders exist, so the space would never converge. **Recommendation: (d) plus (c).** - **(d):** record the target folder in the registry (`MovingTo`) just before moving. Resume or finish only when that record matches. Never move into, or adopt, a folder the rename did not start. This fits the multi-instance rule: no shared lock and no new shared file. - **(c):** an audited, session-admin **Finish rename** action in Administration > Spaces, with a "Rename not finished" badge and a dialog showing the folder's size, item count and last change. Being a visible action, it needs a mockup. - **(b), an identity marker in the space folder:** sound, but can wait as a follow-up. **What admins would see:** - WARN `spaces: rename not finished` with a reason (`folder-exists` or `folder-missing`). - Audit entries `space-converge-failed`, and `space-converge-adopted` when an admin finishes a rename by hand. **Decisions needed (asked now):** 1. Automatic adoption of a folder someone converged by hand: never? (Recommended: never.) 2. Add (c), a Finish rename admin action (mockup first)? **Separate issues filed:** - Opening a space whose folder is missing recreates it empty. - The S3 driver's `Rename` merges into an existing destination for every caller.
Author
Owner

Decision (Nikola, 2026-10-18):

  • Never adopt automatically. The rename records MovingTo in the registry before it moves anything, and convergence only resumes a move it started itself. In every other case it logs WARN spaces: rename not finished (with a reason) and writes the audit entry space-converge-failed.
  • Admin action: Administration > Spaces gets a "Finish rename" action and a "Rename not finished" badge. The action is audited (space-converge-adopted) and only available to session admins. The mockup comes first, then the UI code; the backend part can start now.
**Decision (Nikola, 2026-10-18):** - **Never adopt automatically.** The rename records `MovingTo` in the registry before it moves anything, and convergence only resumes a move it started itself. In every other case it logs WARN `spaces: rename not finished` (with a reason) and writes the audit entry `space-converge-failed`. - **Admin action:** Administration > Spaces gets a "Finish rename" action and a "Rename not finished" badge. The action is audited (`space-converge-adopted`) and only available to session admins. The mockup comes first, then the UI code; the backend part can start now.
Author
Owner

Mockup approved by Nikola (2026-10-19), as drawn (batch3-mockups.html, scenes 6-7d).

"Finish rename…" and "Retry now" appear in two places: as links on the row's reason line, and as items in the row's ··· menu. The legal-hold row offers only Retry now. The inventory row shows the last failure reason, which is persisted on the registry record.

**Mockup approved by Nikola (2026-10-19), as drawn** (batch3-mockups.html, scenes 6-7d). "Finish rename…" and "Retry now" appear in two places: as links on the row's reason line, and as items in the row's ··· menu. The legal-hold row offers only Retry now. The inventory row shows the last failure reason, which is persisted on the registry record.
Author
Owner

Shipped in v0.6.350 (PR #970). Both dogfoods run it.

What changed:

  • Convergence records MovingTo and only finishes a move it started itself.
  • A Stat error is never treated as a missing folder.
  • On S3 it never merges into a folder the rename did not move (#960).
  • Admin rows show "Rename not finished" with the reason, plus Finish rename… (audited, shows the folder's facts) and Retry now.
  • The space keeps one encryption key across the folder move (found while fixing this).

Live, 2026-10-19:

  • Normal rename (files-bao): B3live became B3live2. The folder converged, and files written before and after the move read back correctly.
  • A rename blocked by a legal hold (#962 check): convergence was refused visibly with WARN spaces: rename not finished: the folder could not be moved; retried at the next start … reason=legal-hold. No folder was adopted or merged.
  • Admin inventory on both dogfoods after the upgrade: no space shows "Rename not finished", so no space renamed earlier was left in an adopted or half-moved state.

Not exercised live: the folder-exists, folder-missing and copies-left reasons, and the Finish rename and Retry now actions. They need a folder planted on the backend. They are covered by tests on posix and S3, including two instances and crashes mid-copy. If you want them seen live, I can prepare a planting script like the #934 one, for you to run with a temporary Garage key.

**Shipped in v0.6.350 (PR #970). Both dogfoods run it.** **What changed:** - Convergence records `MovingTo` and only finishes a move it started itself. - A Stat error is never treated as a missing folder. - On S3 it never merges into a folder the rename did not move (#960). - Admin rows show "Rename not finished" with the reason, plus **Finish rename…** (audited, shows the folder's facts) and **Retry now**. - The space keeps one encryption key across the folder move (found while fixing this). **Live, 2026-10-19:** - **Normal rename (files-bao):** B3live became B3live2. The folder converged, and files written before and after the move read back correctly. - **A rename blocked by a legal hold (#962 check):** convergence was refused visibly with WARN `spaces: rename not finished: the folder could not be moved; retried at the next start … reason=legal-hold`. No folder was adopted or merged. - **Admin inventory on both dogfoods after the upgrade:** no space shows "Rename not finished", so no space renamed earlier was left in an adopted or half-moved state. **Not exercised live:** the folder-exists, folder-missing and copies-left reasons, and the Finish rename and Retry now actions. They need a folder planted on the backend. They are covered by tests on posix and S3, including two instances and crashes mid-copy. If you want them seen live, I can prepare a planting script like the #934 one, for you to run with a temporary Garage key.
Cordy closed this issue 2026-10-19 20:13:04 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#931
No description provided.