Files
buzz/docs/solo-mobile-contract.md
Taylor Ho db40da87b4 feat(relay): add conditional Solo member role updates (#9667)
**Category:** improvement
**User Impact:** Solo chat owners can lower the access of any current
non-owner, including people and agents.

**Problem:** Using invitations to change Solo chat access can restore a
removed member, reject a downgrade because of the target’s invitation
policy, or show a join notice for a role change.

**Solution:** Add signed role updates that require an active member at
the expected role when the relay commits the change. A Solo owner can
downgrade any current non-owner. Moving a viewer to Participating
requires a verified agent, and granting Admin requires ownership of that
agent. The relay refreshes signed group state without emitting a join
notice.

Companion to
[block/buzz-app#3704](https://github.com/block/buzz-app/pull/3704). The
[app
review](https://github.com/block/buzz-app/pull/3704#pullrequestreview-5962147206)
identified the need for conditional writes, verified agent identity and
live relay validation. [#9592](https://github.com/block/buzz/pull/9592)
introduced the atomic removal that uses the same membership lock.

<details>
<summary>File changes</summary>

**crates/buzz-core/src/kind.rs**

Register signed Solo role updates as kind 9050.

**crates/buzz-db/src/store/channel_members.rs**

Authorize the transition under the channel membership lock and commit
the active row update and signed event together.

**crates/buzz-relay/src/handlers/event.rs**

Give the new command a bounded metrics label.

**crates/buzz-relay/src/handlers/ingest.rs**

Use the shared signed ingest path and require the channel administration
scope.

**crates/buzz-relay/src/handlers/mod.rs**

Register the command handler and its PostgreSQL test.

**crates/buzz-relay/src/handlers/solo_member_role.rs**

Parse the command, route it to the conditional write, and refresh signed
group state after commit.

**crates/buzz-relay/src/handlers/solo_member_role_postgres_tests.rs**

Exercise human and agent changes, restrictive invitation policy,
promotion authorization, stale and removed membership, duplicate
receipt, and signed roster updates through the relay’s production ingest
path.

**docs/solo-mobile-contract.md**

Describe the wire format, permitted transitions, and handling when an
older relay rejects the command.

</details>

### Try it

1. Run the updated relay and the companion app against a disposable Solo
chat with a current human and agent. Open **Chat access** as the owner.
2. Lower the human to **Viewing only**. Reopen **Chat access** and
confirm the saved role. A role change should produce no join notice.
3. Downgrade an agent with a restrictive invitation policy. Confirm its
role changes. Check that **Admin** can be granted only to your own
verified agent.
4. Run `solo_owner_edits_active_members_and_publishes_the_new_roster`
with PostgreSQL to check that a pending change for a removed member is
refused and the signed roster stays clear of that member.

### Validation

- The PostgreSQL regression passes at relay commit `405f7d1da`. It
covers role and invite-policy enforcement, signed roster refresh,
duplicate receipts, and rejection after removal.
- The companion app at `a470947dc6` passes 138 administration tests. Its
production command builder, validator, and signed roster reader also
passed over WebSocket against a local relay backed by PostgreSQL and
Redis. A human moved from Admin to Participating to Viewing only, then
was removed. The app preflight and relay both refused a further role
edit, and the signed roster still excluded the member.
- The live check exercised the app’s relay code headlessly. The UI
walkthrough is pending.

---------

Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
2026-11-18 17:16:25 -08:00

74 lines
4.2 KiB
Markdown

# Solo desktop/mobile contract
The current Solo producer is **[block/buzz-app](https://github.com/block/buzz-app)**,
not the older `desktop/` client retained in this repository.
The captured producer revision is
[`64726576ed3b082daa5786e5e7ca6b5a018663a1`](https://github.com/block/buzz-app/commit/64726576ed3b082daa5786e5e7ca6b5a018663a1):
- [`SoloDraft.tsx`](https://github.com/block/buzz-app/blob/64726576ed3b082daa5786e5e7ca6b5a018663a1/src/features/solo/SoloDraft.tsx) calls `session.channelWrites.create`.
- [`channel-writes.ts`](https://github.com/block/buzz-app/blob/64726576ed3b082daa5786e5e7ca6b5a018663a1/src/features/relay/channel-writes.ts) emits kind 9007 with `channel_type=stream`, `visibility=private`, and `t=buzz.solo`. Its existing production-service test is “creates a Solo chat in its single durable outbox command” in `channel-writes.test.ts`.
- [`model.ts`](https://github.com/block/buzz-app/blob/64726576ed3b082daa5786e5e7ca6b5a018663a1/src/features/channel-templates/model.ts) retains project assignments but drops the legacy `groups.channels` discovery list.
The desktop does **not** author `P`. The relay derives the creator from the
signed creation event. In this repository, `channel_labels_from_tags` in
`crates/buzz-relay/src/handlers/side_effects.rs` parses creation labels;
`group_state_identity_tags` in `crates/buzz-core/src/channel.rs` emits the
leading type `t`, subsequent label `t` tags, and uppercase creator `P`.
`emit_group_discovery_events` uses that builder for relay metadata. Mobile reads those
facts through `ChannelData.fromEvent` and its channel providers.
## Reproducible contract coverage
`test-fixtures/solo-creation.json` contains an **actual captured production
create command**, plus expected relay identity tags using a synthetic creator.
To recapture it from a checkout of the pinned desktop revision:
```sh
node --experimental-transform-types scripts/contracts/capture-solo-creation.mjs /path/to/buzz-app > test-fixtures/solo-creation.json
```
The script invokes `createChannelWrites(...).create(...)` and captures its
outbox command without publishing anything. The core test
`desktop_solo_creation_preserves_mobile_identity_contract` feeds those command
labels through the production parser and relay identity builder. The mobile
regression “refresh replaces stale Solo details before opening and sending”
consumes the same identity tags through the real list/detail providers, primes
old details, refreshes, opens Solo, and sends through the personal sender with
an empty legacy chat list. Existing widget coverage checks project and unfiled
placement and shared-chat ordinary sending.
These are compositional contract tests, not a live desktop/relay/device E2E
run. Physical-device installation and launch alone do not prove that journey.
## Changing an existing member's access
A Solo chat owner changes an existing member's access with a signed Buzz
kind:9050 event with `admin:channels` scope. The content is empty. Each
required tag appears once.
Relays advertise `buzz-solo-member-role` in NIP-11 `supported_extensions`.
Clients offer role changes only when the relay advertises this extension.
| Tag | Value |
| --- | --- |
| `h` | Solo channel UUID |
| `p` | Target member's hex public key |
| `expected_role` | Exact active role from the relay-signed roster: `admin`, `bot`, `member`, or `guest` |
| `role` | `admin`, `member` (Participating), or `guest` (Viewing only) |
A chat owner may lower any active non-owner to Viewing only, or lower an
Admin to Participating. A move from Viewing only to Participating requires
a verified agent. An Admin grant requires a verified agent owned by the
signer. The relay stores Participating as `bot` for verified agents and
`member` for people. Role changes bypass invitation policy.
The relay requires a private Solo stream and checks the current chat and
membership under the membership lock. It commits the command, role, signed
admin list, and signed member roster together. It emits no admission notices.
Refresh the roster after a role mismatch. Resending the same accepted event
confirms its receipt without applying another change. Relays that lack
kind:9050 support reject it. Clients must never fall back to kind:9000 for
this action.