Files
buzz/crates/buzz-admin/src
Will Pfleger b769d5bee8 fix(relay): remove an owner's agents with the owner (#9575)
## What this changes

When someone is removed from a community, their agents' live sessions
already closed, but the agents kept their own membership rows and could
reconnect as members. This PR removes those agents with their owner.

- **Cascade.** `delete_member_with_acceptances` locks and deletes the
target, then locks and deletes the `join_policy_acceptances` and
`relay_members` rows of every member of the same community whose
`users.agent_owner_pubkey` is the target and whose role is not `owner`.
All of it runs in the same transaction, before the roster snapshot is
written. Admin removal (kind 9031), self-leave and `buzz-admin
remove-member` all go through it. An agent goes with its owner whatever
its role, so an admin who removes a member also removes that member's
admin-role agent. A direct 9031 target is still limited to `member` for
admins.
- **Owner recording.** The relay records a verified NIP-OA owner on
every admitted sign-in, whatever the relay mode or `allow_nip_oa_auth`:
on WebSocket AUTH, and for HTTP in the shared admission step after the
denial checks, so `/events`, `/query`, `/count` and member POSTs all
record it in one place. Before, it recorded only on open relays, so on
closed relays the cascade and owner bans missed agents added directly. A
request refused before recording writes nothing. Once the owner-signed
tag is verified and the first admission checks pass, the relay may
record the owner even if a final check, a cancellation or a token
revocation then refuses the sign-in. The record still can't be changed.
Over HTTP, a different stored owner refuses the request with 403 (invite
creation keeps its `invite_owner_mismatch` code), and storage trouble
refuses it with 503. A recorded owner can also manage the agent (channel
management, channel-add policy, invites).
- **CLI.** `buzz-admin remove-member` publishes clusterwide disconnects
(`ConnControl::DisconnectPubkey`) for the target and its recorded agents
on every run, including when the member is already gone. If publication
fails or no relay server is subscribed, it exits 6 after the removal
commits. Rerunning the same command retries the disconnect.
- **Spec.** NIP-FI states the rule.

## Rollout limit

An agent is covered only if its owner was recorded before the owner is
removed. An agent whose owner was removed before the agent signed in
with a NIP-OA tag after deploy, or an agent that never signs in with
one, stays a member and needs a manual removal. The relay holds no proof
of ownership for those agents, so there is nothing to backfill.

Supersedes #6098 and #6078.

---------

Signed-off-by: Will Pfleger <wpfleger@block.xyz>
Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
2026-11-17 20:35:33 -05:00
..