~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Spaces, handles, deletes and invites are written whole or undone

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/whole-writes

What changes

A space is made whole or not at all. createSpace writes the access record and index entry in a new furnish step. If either write fails (an access record that is no record, say credentialScopes: [{"role": "admin", "scopes": 1.5}]), the host ends the space it just made, so the key is free again rather than lost to a space nobody can change or delete. updateSpace now looks up the index entry before it writes anything, so a change refused with SpaceNotFound leaves the access record as it was. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzjdeyx6g4qi

The host holds a handle before the directory names it. updateGroupHandle now sets the handle in the account row first, with no event, so the unique-handle constraint refuses a handle taken meanwhile before anything is published. Then it publishes the PLC update. If the directory refuses, the host puts the previous handle back. Only after the directory names the handle does the host sequence the #identity event for relays. So the directory never names a handle the host has refused. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzjdf2eqx3sr

A half-made group that cannot be removed says why. When set_up fails and the cleanup delete_account also fails, createGroup now logs a warning ("could not undo a group half made") and still answers the set_up error. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzjdf5bjd3xe

A group's DID is ended before its account is deleted. delete_account now publishes the tombstone first and deletes the store only after that. If the directory is unreachable or refuses, deleteGroup fails (500) and the group stays, so it can be deleted again. tombstoned: false now means only that the DID was left to a steward's recovery key. tombstone treats a DID whose last op is already a tombstone as ended (Ok(true)), so a retry after the store delete failed is safe. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzjdffcdytdi

Lapsed invites are taken back. When requestJoin finds a lapsed invite, it takes that invite back from the inbox and the host's list (waiting_invite). The hourly sweep in serve now also runs Host::sweep_invites, which takes back every invite lapsed by now (new Store::lapsed_invites). An invite whose group is switched off waits until the group is on again. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzjdderlug3o

A redeemed invite is taken back only after the membership is written. requestJoin writes the membership first, then takes the invite back. A join that fails leaves the invite waiting. An invite left over for a member does no harm, since requestJoin refuses members. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzjddg66ch5y

docs/design/groups.md, recovery.md and membership.md now describe the new order and the failure behaviour. The test PLC fake's refuse is now an AtomicBool that a test can switch, and a new refuse_ends switch refuses only tombstones.

How it was checked

  • group_spaces: an_admin_makes_a_space creates a space whose access record is not a valid record, checks that no space or head is left, then makes the same key again. an_admin_changes_a_space checks that a name-and-readers change to an unindexed space leaves its access record unchanged. Both failed before the fix.
  • lifecycle: four tests, all of which failed before the fix:
    • a_group_the_directory_would_not_end_is_deleted_again: the directory refuses, then a retry deletes the group.
    • a_did_ended_already_is_ended
    • a_did_the_directory_will_not_end_keeps_its_account: replaces the old test that expected Ok(false).
    • a_group_half_made_that_cannot_go_fails_as_it_did: takes the logged cleanup failure.
  • invites: a lapsed invite is gone from the inbox and the list after requestJoin. sweep_invites takes back a lapsed invite, then finds none. It leaves a switched-off group's invite alone.
  • group_handle: when the directory refuses, the host keeps the handle the directory names, the directory gets no op and relays hear nothing.
  • cargo fmt --check and clippy -D warnings pass. The tests of group_spaces, group_handle, lifecycle, invites, joining, groups and recovery pass locally. The full suite and the coverage gate are left to CI.

Shortcomings

  • No test reaches the two races the handle and join fixes close: a handle taken between the check and the write, and a membership write failing after the invite is found. Neither can be triggered on demand. The tests cover the new order and the restore path, not the race itself. The handle test also passed against the old code, since a directory refusal was already handled there.
  • While updateGroupHandle is publishing, the host's record (and getGroup) shows the new handle a moment before the directory does.
  • If a half-made group's DID cannot be ended, its account and handle now stay, logged. Before, the account was deleted and a live DID was left behind. The handle is held until someone deletes the account.

🤖 Generated with Claude Code

Approved

This pull makes spaces whole-or-undone, holds a handle in the host before the PLC op, ends the DID before the account delete, and takes lapsed invites back (on requestJoin and in an hourly sweep). I read every changed file and found no defect that blocks the merge. The orderings are right and the tests cover the new paths. I did not read the CI checks.

One edge is worth a follow-up, though not a blocker. In requestJoin, take_back now runs after put_membership and uses ?. If the take-back fails, the caller gets a 500 even though they are already a member. host.store.decide(group, &me) is then skipped, so any pending join request stays undecided. A retry answers AlreadyMember. The invite is harmless, as your body says, so a failed take-back there would be best-effort: log it and carry on to decide.

Smaller point: sweep_invites drops take_back errors without a log line. Only the count shows that some were skipped. A tracing::warn would help an operator see invites that stay stuck.

crates/group-host/src/group_join.rsline 69Outdated

These lines can no longer be read.

review.knotless.dev

A failing take_back here returns an error after the membership is written and before decide runs. The caller is a member but sees a 500, and the join request stays undecided. Treat it as best effort (log it) and continue to decide.

crates/group-host/src/group_invites.rsline 166Outdated

These lines can no longer be read.

review.knotless.dev

A failed take-back is dropped silently. Log it, so an invite that stays stuck can be seen.

Approved

The pull makes spaces whole-or-undone, holds a handle before the PLC op, ends the DID before the account delete, and takes lapsed invites back on requestJoin, on createInvite and in the hourly sweep. The only change since my last review is a merge of main plus createInvite now using waiting_invite. I found no new defect.

Neither of my two earlier points was done:

  • requestJoin still uses ? on take_back after put_membership. A failed take-back returns a 500 to someone who is now a member, and decide is skipped.
  • sweep_invites still drops take_back errors without a log line.

Both are minor and I'm still approving. A best-effort take-back with a tracing::warn, in both places, would close them.

The pull page reports a merge conflict with main in group_spaces.rs, tests/invites.rs and docs/design/groups.md. Rebase or merge main again before landing it.

crates/group-host/src/group_join.rsline 69Outdated

These lines can no longer be read.

review.knotless.dev

Still ?: a failed take-back gives a 500 after the membership is written, and decide is skipped. Log it and carry on.

crates/group-host/src/group_invites.rsline 166Outdated

These lines can no longer be read.

review.knotless.dev

A failed take-back is still dropped silently. Log it with tracing::warn.

Approved

The pull makes spaces whole-or-undone. It holds a handle before the PLC op, ends the DID before the account delete, and takes lapsed invites back on requestJoin, on createInvite and in the hourly sweep. Since my last review the only change is a merge of main into the branch. It also merges cleanly now (fast-forward), so the conflict I flagged is gone. I found no new defect.

Neither of my two earlier points was done, and I still approve. Both are minor:

  • requestJoin still uses ? on take_back after put_membership. A failed take-back returns a 500 to someone who is already a member, and decide is skipped.
  • sweep_invites still drops take_back errors without a log line.

Making both best-effort with a tracing::warn would close them. I won't repeat this again.

Merged as c86b23d