Skip to content

feat(relay): let plugins keep NIP-AR community-scoped artifacts - #3838

Closed
LordMelkor wants to merge 14 commits into
mainfrom
clod/community-artifacts
Closed

LordMelkor wants to merge 14 commits into
mainfrom
clod/community-artifacts

Conversation

@LordMelkor

@LordMelkor LordMelkor commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Moved from #3827, so that the branch is in this repository.

Summary

This lets a plugin keep community-wide artifacts under NIP-AR community scope (spec; relay: block/buzz#9650). A relay that advertises NIP-11 artifacts.community_scope version 1 keeps kind-45010 revisions that carry a community tag and no h. It also keeps a per-type write policy, set with kind 9034. Today a plugin can't do either:

  • session.artifacts.sync throws on a filter without #h.
  • Nothing a plugin can reach carries the community id.
  • No route signs kind 9034, which the spec keeps off the artifact writer.

The app gains three things:

  1. A community sync. session.artifacts.sync({ artifact: "current", scope: "community", "#type": [type] }) takes exactly one #type and no #h. It has the same statuses as a channel sync.
  2. session.artifacts.communityId. It is present only when the relay advertises community scope, so a plugin can check it synchronously before it shows anything that needs community artifacts.
  3. session.artifacts.typePolicy. It is { read, set } for this community:
    • read(type, signal) returns { policy, revision }.
    • set({ type, policy, prev }, signal) signs one kind-9034 command as the viewer and publishes it once. It resolves { id, ok, message }, with the relay's answer when the host keeps it.

Kind-45010 community records need no new writer. configArtifactWriter already signs an h-less 45010, and snapshotRead already reads a head.

A plugin owns every feature built on this. A shared mention-groups plugin, in a separate repository, is the first consumer.

Why each change is in core, and why it is this small

The rule for each row: a change belongs in the app only if no plugin can do it with today's API, and then only in the smallest general form, one that names NIP-AR concepts and no feature.

Change Necessity: why a plugin can't do it today Minimality
artifact-community.ts (new): wire helpers for community id, type name grammar, 9034 template and validation, policy filter and parser Both hosts and the broker need the same NIP-AR checks. Without a shared module each one would carry a copy. NIP-AR names only, with no dependencies, so the broker imports it the way it already imports artifact-sync-filter.ts.
artifact-sync-filter.ts: accept scope: "community" with one #type The filter refuses any sync without #h on both hosts (artifact-sync.ts, relay-broker.mjs). One branch on a NIP-AR key. The existing limits apply to both forms.
native.ts, transport.ts, relay-broker.mjs: read artifacts.community_scope at connect The session carries no NIP-11 data. transport.scope is the relay origin, not the community UUID. One string, parsed the way the read-state community already is.
artifact-type-policy.ts (new) plus one route each in native.ts, transport.ts and relay-broker.mjs: a typed 9034 sign, publish and policy read configArtifacts refuses any kind but 45010, and relay_sign refuses 9034. The broker's /sign doesn't handle it. The policy answer is a JSON object, which parseEvents refuses. One NIP-AR operation through the existing typed-route mechanism that the community-wide 9035/9036 archive already uses. The sign, publish and outcome mapping live once, shared by both hosts.
channel_writes.rs, relay.rs: the native shape check for the 9034 route, and 9034 added to the /events refusal list The desktop host signs only shapes it validates itself. One match arm and one kind in an existing list. relay_sign keeps refusing 9034.
socket-requests.ts: treat a 9034 conflict: like the existing 40100 and 45010 compare-and-set refusals Without it, a stale prev is reported as an unconfirmed publish instead of the relay's refusal. One kind added to an existing list.
session.ts: communityId and typePolicy on session.artifacts A plugin's synchronous match(observation, context) gets only context.session, so the community gate has to live there. Two optional fields on an existing object, present only together. typePolicy is bound to the session like its other administrative writers: refused after close and while 4 calls run, and aborted on dispose and on an access change. A community sync on a relay without community scope reports unsupported.
docs/artifact-sync.md: one section Documents the contract and its boundary. One section in the existing artifact-sync doc.

Boundary. typePolicy acts with the viewer's authority, like the session's other administrative writers (memberAdministration, channelLifecycle): any plugin in an admin's session can change any type's write policy. The relay accepts the command only from a direct owner or admin. A per-plugin gated service would add a new service, a registration and a naming rule. That rule would block any plugin that governs several types, for no protection beyond what the relay already enforces.

Size

Measured against main (46a09dbfd) at 0418421e0, with git diff. Rust test modules count as tests.

Added Removed
Production (TypeScript, broker, Rust outside its test modules) 430 22
Tests 949 3
Docs 10 0

The two largest pieces are artifact-community.ts (+134, the shared NIP-AR wire helpers) and artifact-type-policy.ts (+95, the typed route and its session bounds).

FOUNDATION files touched: src/features/relay/session.ts, +16/-4: one call that builds the session-bound typePolicy, its cancel on an access change, the spread of the two fields, and the community sync check. The bounds themselves live in artifact-type-policy.ts. No other edited file carries the marker.

Testing

Lint cleanup at 0418421e0: two commits from a pass with the landmines lint rules, with no behavior change. They remove the prose comments this PR added (27 lines, 10 of them in the browser broker and its tests), and they let the helpers in artifact-community.ts infer their return types. artifactTypePolicyAccess now checks its object with satisfies ArtifactTypePolicyAccess, which keeps the methods' parameter types. Two edits this PR makes to main's comments stay, because main's text would no longer be true: the artifact-sync-filter.ts header (the file now imports another wire contract) and the restricted status doc (a community sync has no #h). The test doubles stay. They stand in for the relay writer and read, Tauri invoke and fetch, as main's relay tests do in the same files. The one polling finding was fixed in e4b32aa3b. An independent review found no behavior or type change.

All runs were on a separate Linux machine. Biome's format check is also clean.

Check At 0418421e0 At e4b32aa3b At 96138f4395 At a20a5cd00
bin/node scripts/check-push.mjs (types and related tests) tsc pass; 11 of 428 related test files failed while two other branches' test runs shared the machine, and all 11 passed when rerun with nothing else running (2,419 tests, 1 skipped). This PR changes none of them. pass: 427 files, 12,915 tests (6 skipped) pass: 427 files, 12,915 tests (6 skipped) pass: 427 files, 12,910 tests
check-push.mjs --design pass pass pass pass
check-push.mjs --clippy not rerun: no Rust change not rerun: no Rust change since 96138f4395 pass pass
cargo test relay:: not rerun not rerun not rerun: no Rust change since a20a5cd00 pass: 240 tests
vitest run src/features/relay pass: 151 files, 3,871 tests
artifact-type-policy.test.ts, 20 runs 20/20

New tests cover:

  • Every byte class of the type-name grammar, in TypeScript and Rust.
  • The 9034 template and validation, including community mismatch, nil UUID, prev and created_at bounds.
  • The community sync filter.
  • The broker's sign, publish and read routes, with their refusal mapping.
  • The native and browser set outcomes (accepted, rejected with the relay's reason, not sent, unconfirmed).
  • read refusing a malformed relay answer.
  • The broker's 403: only the type policy routes map restricted: and blocked: to it, and every other publish route still answers 503 with sent: false.
  • typePolicy's session bounds: frozen, refused after close and at the cap, and aborted on dispose and on an access change.
  • A community sync on a relay without community scope.

Known limits:

  • An access change aborts every open type policy call in the session, not only calls for the changed channel.
  • The cap of 4 concurrent calls is shared by every plugin in the session.
  • A disabled plugin that kept a reference: its calls end only with the signal it passed, because the session has no per-plugin identity.
  • Whether typePolicy.set needs a per-plugin gate is open for a maintainer (see the Boundary paragraph above).

End-user test (AGENTS.md step 3)

An end-user test by the PR author's agent on a separate Linux machine. It used:

Every step was scripted and has screenshots. Run 1, with both users on browser hosts, passed all 15 steps. Run 2, with one user in the desktop app (the plugin installed from a folder), passed the 7 steps it covers. A rerun with the plugin's final commit passed all 15 steps again.

Rerun at the final heads, all passed: relay block/buzz#9650 at 3cc3b3f8, rolled out as its rollout guide says; main (7ab400514) with #3837 at 1ac9b9aeb (which contains #3836 at 702432464) and #3838 at 0418421e0 merged in; and the plugin's final commit. Run 1 passed all 15 steps (step 15 also checked that none of the plugin's 8 revisions carries a p tag), and the step with a default channel the saver hasn't joined passed too. Only the test scripts changed, for main's new sidebar (one Create channel button per section, and the "Team" heading). No assertion changed.

What it shows for this PR:

  • communityId: on the relay without community scope, the plugin says "This community's relay doesn't support shared groups." and adds no @ rows. A message there that names a group carries no group p tags.
  • Community sync: a group one user saved appeared in the other user's open Settings 0.2 s later, without a reload, and left it 0.3 s after it was deleted.
  • typePolicy.read: a new community reads {"policy":"everyone","revision":null}.
  • typePolicy.set:
    • An admin's change to owners and admins returned a revision equal to that 9034's id in the relay's audit log.
    • The change back sent a 9034 whose prev is that revision.
    • In between, a member's write was refused with restricted: community artifact access denied, and the record didn't change.
  • Records: all 8 kind-45010 revisions the plugin wrote carry a community tag and no h.
Another user's save, live in Settings A member's view under "Owners and admins"
The second user's Mention groups settings list @Design Team, 2 people, 1 agent, 1 default channel A member's Mention groups settings list Design Ops and Design Team with no Edit or Delete, and say Only community owners and admins can manage groups.
A relay without community scope
The Mention groups settings say This community's relay doesn't support shared groups.

Merge order

This PR shares no files with #3836 or #3837. #3836 must ship no later than this PR: a plugin that offers @ rows once communityId is set would otherwise replace the people rows. No other order is needed. Community artifacts stay off until the relay advertises community scope.

🤖 Generated with Claude Code

LordMelkor and others added 9 commits November 18, 2026 06:32
Add the dependency-free NIP-AR community-scope helpers that the desktop
host, the browser broker and the session share: NIP-11
`artifacts.community_scope` discovery, the exact kind-9034 type policy
command and its validator, the policy read filter and response parser,
and the relay's artifact type grammar.

Artifact sync now accepts a community filter (`"scope": "community"`
with exactly one `#type` and no `#h`); channel filters are unchanged.
A socket `conflict:` refusal of a 9034 command counts as proven
non-delivery, like other compare-and-set refusals.

The browser transport exposes `artifactCommunity` and
`artifactTypePolicy` when the broker reports a canonical community id:
the read posts `{type}` to `artifact-type-policy`, and the writer uses
the `artifact-type-policy-sign` and `-publish` routes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The desktop transport reads NIP-11 `artifacts.community_scope` (only
when the relay lists `nip-ar`) and, for such a relay, offers
`artifactCommunity` with `artifactTypePolicy`: a signed `/query` read of
the community's per-type write policy, and a writer for the kind-9034
command bound to this community.

Kind 9034 goes only through the purpose-bound `relay_channel_sign` and
`relay_channel_publish` route `artifact-type-policy`, which accepts
exactly the four tags in order (a canonical non-nil community, the
relay's namespaced type grammar, `everyone` or `admins`, and `prev` of
"0" or a lowercase event id) with empty content. The generic `relay_sign`
keeps refusing 9034, so the artifact signer cannot set a policy, and raw
`/events` posts now refuse it like the other typed-route kinds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The browser host's relay broker now reads NIP-11
`artifacts.community_scope` (only with `nip-ar` listed) and reports the
community as `artifactCommunity` in the session, so the browser
transport can offer community-scoped artifacts.

Kind-9034 type policy commands get their own `artifact-type-policy-sign`
and `-publish` routes, like identity archive requests: each accepts only
the exact command for the relay's advertised community, and the generic
sign and publish routes still refuse it. The `artifact-type-policy` read
accepts exactly `{type}` and sends the relay its own policy filter.

A socket publication refused with `restricted:`, `blocked:` or
`auth-required:` is now answered 403 with the relay's text, as the
relay's HTTP API does, instead of 503 unsent, so writers show it as a
refusal. Community artifact sync passes through the broker unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
…ession

`session.artifacts.communityId` is the community id the relay advertises
in NIP-11 `artifacts.community_scope`, and `session.artifacts.typePolicy`
reads and sets a type's write policy (NIP-AR kind 9034). Both are present
only when the transport provides the community and its policy route, so a
plugin can detect community artifacts synchronously.

`typePolicy.set` builds the exact 9034 command for the session's own
community, signs it once as the viewer and publishes it once. It resolves
with the command id and the relay's answer: the relay's refusal text when
the host keeps it, or an empty message after a transport failure. It
rejects only on a malformed change, a signing failure or an aborted signal.

The artifact sync guide describes the community sync filter, both fields
and their boundary: the policy capability acts with the viewer's
authority, like the session's other administrative writers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
A community sync filter with one `#type` outside the NIP-AR type
grammar passed `artifactSyncFilter` and reached the relay, which
closes the REQ as `invalid:`. The view then ended in status `error`
instead of the call throwing, while the policy helpers refused the
same type at the call site.

The community branch now checks the value with `artifactTypeName`,
the grammar the policy helpers already share, so every host refuses
it before the REQ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The desktop type policy route was tested with types made only of
lowercase letters, and its refusals all failed on a segment's first
character. Dropping the digit, `_` or `-` arm of the per-byte check,
or widening it to accept uppercase inside a segment, still passed.

The test now accepts types with digits, `_` and `-` (including a
hyphenated middle segment) and refuses uppercase or punctuation
inside a segment and a leading or trailing dot, matching the shared
TypeScript grammar's table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The broker answers a proven socket refusal starting with
`restricted:`, `blocked:` or `auth-required:` with 403, so the writer
sees the relay's refusal instead of an unconfirmed publication. Only
the first two prefixes were tested, so dropping `auth-required` from
the mapping still passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
Make the transport's artifactTypePolicy the plugin-facing read/set access
and build it in one helper shared by the native and broker transports, so
the session only passes it through. Move the set behavior tests to the
helper's own test file. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The Rust shape test named a feature in its sample type; it now uses
com.example.settings.item, as the other tests do.

Two refusal cases repeated checks that have one owner elsewhere:
- The broker route test sent three malformed policy commands. Wrong tag
  order and an extra tag are covered by artifact-community.test.ts and
  the Rust shape test, so it keeps only the other-community command,
  which proves the route binds to its relay's community.
- The access test rejected three malformed relay reads. The parser's
  own table covers them, so one row is kept to prove read uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This is a comment, not an approval. A human core-team maintainer needs to review this PR: it comes from outside the core maintainer group and adds a new plugin-facing signing capability.

No blocking issues.

  • The kind-9034 template is validated to the same exact shape in TypeScript, in Rust and in the browser broker.
  • The community sync filter requires exactly one #type and no #h.
  • Capability detection requires nip-ar and community_scope v1, and the generic sign and HTTP paths still refuse 9034.

P2s, inline:

  • typePolicy.set is open to every plugin, with no capability and no link between the type and the calling plugin. Any plugin in an admin's session can change another plugin's write policy. A maintainer should decide whether that is acceptable or whether it needs a gate.
  • The browser host's new 403 mapping sits in the shared publish path. Every route now treats a refusal with auth-required: as permanent, where it used to stay unsent and retryable.
  • typePolicy isn't tied to the session lifecycle. read and set keep working after close or access revocation.

Smaller notes:

  • sync({scope: "community"}) doesn't check communityId, so on a relay without community scope it sends an unknown scope.
  • The Rust route doesn't check that the community is this relay's. Only the TypeScript closure does.
  • A community view doesn't require a community tag, or the absence of an h tag, on the events it keeps.
  • The native path has no negative tests showing invoke is never reached for a wrong community.

async read(type, signal) {
return parseTypePolicy(await read(type, signal));
},
async set(change, signal) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P2: set signs and publishes a 9034 as the viewer for any type the caller names. Nothing ties the type to the calling plugin, and nothing checks a permission. Every plugin that receives session.artifacts gets this when the relay advertises community scope. Any plugin running in an owner's or admin's session can therefore flip another plugin's type from admins to everyone (or the reverse), with no consent or gate. The PR documents this boundary and compares it to memberAdministration. But that writer is exposed through a capability and per-writer validators, whereas this one is a bare pass-through with a free-form type. Please gate it per plugin, for example by requiring the type to carry a prefix the plugin owns or by requiring a manifest capability. Otherwise record explicitly that the change is accepted as-is. Note that prev only guards against stale writes, not against a malicious one.

Comment thread browser-host/relay-broker.mjs Resolved
Comment thread src/features/relay/session.ts Resolved
The browser host's 403 for a proven authorization refusal now applies
only to the type policy route, and `auth-required:` stays unsent and
retryable there too, so other publish routes keep their earlier
behavior.

`session.artifacts.typePolicy` is now frozen, refused once the session
closes or four calls are running, and each call aborts on dispose and on
an access change, as the other administrative writers do. A community
sync on a relay without community artifacts reports unsupported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor

Copy link
Copy Markdown
Contributor Author

🤖 Thanks for the review. Here is what changed at e286e0e360, in the order of your notes.

P2: the broker's 403 (browser-host/relay-broker.mjs). Fixed.

  • The 403 now applies only to the two type policy command routes, and only for restricted: and blocked:.
  • On those routes, auth-required: stays unsent and retryable.
  • Every other publish route is back to 503 with sent:false, as on main.
  • Tests: the live-broker refusal table again expects that on a non-policy route. A new test covers both outcomes on the policy route. Against the previous head, the three authorization rows and the policy route's auth-required: case fail.

P2: typePolicy and the session lifecycle (session.ts). Fixed.

  • session.artifacts and its typePolicy are frozen.
  • Both methods are refused once the session closes, and while 4 calls are running.
  • Each call aborts on dispose and on an access change, the same points where memberAdministration is cleared.
  • The wrapper is in artifact-type-policy.ts, so session.ts gains only the wiring.
  • Tests cover the frozen objects, the cap, dispose and an access change.
  • Not covered: a disabled plugin that kept a reference. The session has no per-plugin identity, so those calls end only with the signal the plugin passed.

P2: a per-plugin gate on typePolicy.set. I left this for a core maintainer to decide, as you suggested. For their decision:

  • session.configArtifactWriter (session.ts:2513) already gives every plugin the transport's artifact writer for any type. It has no per-plugin binding either, so typePolicy.set sits inside the same trust boundary.
  • The relay accepts a 9034 only from a direct owner or admin of the community.
  • A per-plugin type gate would need a model of which plugin owns which type, and core has none today. It would also have to cover both writers.

Smaller notes

  1. sync({scope: "community"}) without community scope: fixed. It now reports unsupported and opens nothing. A test covers both relays.
  2. The Rust route's community check: the relay makes the same check itself. It refuses a 9034 whose community isn't the request's own community (feat(relay): support community-scoped NIP-AR artifacts buzz#9650, crates/buzz-relay/src/handlers/community_artifact.rs:132-133). It does the same for a community-tagged 45010 (:123-124).
  3. Tag checks in the community view: the relay's community query returns only community-scoped heads (crates/buzz-db/src/store/community_artifact.rs:429-436). A plugin also checks each record's shape before it uses it. I didn't add a third check on the client.
  4. Native negative tests: the native set takes no community argument. It signs for the community the relay advertises, and the command writer checks the signed event against that community before invoke (native.ts:989-1006). So a plugin has no input that could name another community.

Checks at e286e0e360, run on a separate Linux machine: the pre-push types and related-tests lane passes (427 files, 12,915 tests), and so does the design lane. The commit changes no Rust, so I didn't rerun clippy or cargo test relay::. The PR body has the new sizes and the known limits.

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This is a comment, not an approval. A core-team maintainer still needs to review this PR, because it comes from outside the core maintainer group and adds a plugin signing capability.

Follow-up on e286e0e36. The two P2s I raised in code are fixed:

  • Broker 403: the 403 is now limited to the type-policy command routes and to restricted: and blocked:. auth-required: and every other route are unsent and retryable again, as on main.
  • typePolicy lifetime: the session hands out a frozen wrapper. It refuses calls once the session closes or when 4 are already running, and every call aborts on dispose or on an access change through AbortSignal.any.
  • Community sync on an unsupported relay: sync({scope: "community"}) now reports unsupported when the relay doesn't advertise community scope.

I accept the reasoning on the smaller notes. The relay checks the community on 9034 and on community 45010 itself, and native set takes no community argument.

The per-plugin gate on typePolicy.set is still a decision for a core maintainer. configArtifactWriter already has the same trust boundary, so if a gate is added it should cover both writers.

@LordMelkor
LordMelkor marked this pull request as draft November 18, 2026 16:33
LordMelkor and others added 4 commits November 18, 2026 11:58
Core-size cut, no behavior change. sessionTypePolicy now owns the
per-access-change abort, the call cap and the open check, and returns the
plugin-facing `communityId`/`typePolicy` fields with a `cancel()` for
revokeAccess. session.ts keeps three call sites: +34/-4 becomes +17/-4.

Also: one-expression community check in artifacts.sync, the literal 9034 in
socket-requests.ts as its neighbours use, and no explicit return type on
typePolicyFilter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The abort case now resolves a promise from the scripted publish and
awaits it, then asserts the single publish call, instead of retrying the
assertion on the publish spy until a deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
@LordMelkor
LordMelkor marked this pull request as ready for review November 18, 2026 23:12
@LordMelkor
LordMelkor requested a review from a team November 18, 2026 23:16
LordMelkor added a commit to block/buzz that referenced this pull request Nov 18, 2026
## Summary

NIP-AR clients can store community-scoped artifacts and subscribe to
live changes for one exact artifact type. Community and channel
artifacts share revision and retry semantics and use separate identity
scopes. Community owners and admins can choose whether a type accepts
edits from all admitted members or only administrators. This PR combines
the protocol from #9638 with the relay implementation.
[Protocol](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/docs/nips/NIP-AR.md#community-scoped-artifacts-proposed-extension)

- Kind `45010` binds community writes to a signed tenant UUID. Explicit
community filters select signed HTTP reads and WebSocket sync. NIP-11
advertises capability after the schema transition.
- Kind `9034` sets per-type policy using compare-and-set. The relay
commits the policy update and audit entry together. Readers fetch the
current policy and its revision through the explicit policy view.
- Kind `9005` redacts a community revision. Relay peers send
tenant-scoped change metadata and re-read the authorized head for
delivery. This reuses the existing snapshot, bounded buffering, and
resync semantics.

## Rollout

Migration `0097` expands storage and retains the existing channel write
key. Deploy compatible serving backends, deletion executors and operator
tools with community scope disabled. Then run the guarded key transition
and enable the capability. The resulting rollback floor is the first
compatible relay version. [Rollout
guide](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/docs/community-artifact-rollout.md)

## Why each change belongs in the relay or protocol

| Change | Necessity | Minimality |
| --- | --- | --- |
| NIP-AR community scope | The current protocol gives every artifact a
home channel and defines channel-based access. Clients need a shared
contract for community identity, admission, reads and moderation to
interoperate.
[NIP-AR.md:9](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/docs/nips/NIP-AR.md#L9)
[NIP-AR.md:65](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/docs/nips/NIP-AR.md#L65)
| An optional version-1 section reuses the artifact envelope version and
revision operations. The channel sections state where their existing
rules apply.
[NIP-AR.md:242](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/docs/nips/NIP-AR.md#L242)
|
| Signed community revisions | The validator requires an `h` tag, and
the write path stores an event and mentions for that channel. A
client-defined tag cannot establish a different audience on the relay.
[artifact.rs:122](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-core/src/artifact.rs#L122)
[artifact.rs:196](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/artifact.rs#L196)
| The existing event kind accepts a mutually exclusive, signed community
UUID. HTTP and WebSocket bind it to the resolved tenant at ingest and
reuse the revision authentication checks.
[community_artifact.rs:120](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/community_artifact.rs#L120)
[community_artifact.rs:174](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/community_artifact.rs#L174)
|
| Scoped heads and revisions | The database key places every artifact in
one identity space per community. Only the relay can advance an accepted
head atomically across clients.
[artifact_heads.sql:2](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/schema/tables/public/artifact_heads.sql#L2)
[artifact.rs:187](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/artifact.rs#L187)
| The head and revision ledger gain a scope discriminator. Community
revisions keep their signed payload in the ledger and reuse the
compare-and-set, replay and tombstone rules.
[community_artifact.rs:350](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/community_artifact.rs#L350)
|
| Community admission | Channel reads check channel visibility and
membership. A client can filter its own view but cannot enforce
admission for other readers or synchronize delivery with a revocation.
[artifact_query.rs:65](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/artifact_query.rs#L65)
| Explicit community reads and writes share an admission check against
current membership, verified delegation and bans. Administrative
authority requires a direct role.
[community_artifact.rs:36](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/community_artifact.rs#L36)
|
| Per-type write policy | The administrative scope dispatch has no
artifact-policy command. A client preference cannot enforce an edit rule
against another client or a concurrent write.
[ingest.rs:650](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-relay/src/handlers/ingest.rs#L650)
| One signed admin command sets policy for one exact type using
compare-and-set. A bounded map on the existing community row records the
policy and revision. A shared lock orders policy changes with writes,
and the existing audit chain commits in the same transaction.
[community_artifact.rs:183](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/community_artifact.rs#L183)
[community_artifact.rs:365](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/community_artifact.rs#L365)
[community_artifact.rs:189](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/community_artifact.rs#L189)
|
| Signed HTTP reads | The artifact endpoint dispatches to the channel
store. It cannot return a community head, its history or the
authoritative write policy.
[artifact.rs:70](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-relay/src/api/artifact.rs#L70)
[artifact_query.rs:65](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/artifact_query.rs#L65)
| One scope selector on the existing signed endpoint extends the
current, history and head views and adds an exact-type policy lookup.
Counts and HTTP incremental tokens stay channel-only.
[artifact.rs:73](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/api/artifact.rs#L73)
[artifact_sync.rs:154](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/api/artifact_sync.rs#L154)
|
| Community WebSocket sync | The relay requires channel IDs and confirms
live interest on those channels. A client cannot register community
interest through the existing filter.
[artifact_sync.rs:51](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-core/src/artifact_sync.rs#L51)
[artifact_sync.rs:440](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-relay/src/handlers/artifact_sync.rs#L440)
| One exact type selects the community set. The relay reuses
subscription ownership, snapshot paging, bounded buffering, EOSE and
resync, with a current admission check before delivery.
[artifact_sync.rs:683](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/artifact_sync.rs#L683)
[artifact_sync.rs:755](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/artifact_sync.rs#L755)
[artifact_sync.rs:934](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/artifact_sync.rs#L934)
|
| Cross-node delivery | Redis routes channel and ordinary global events.
A connected client cannot coordinate when peers reread an authorized
head.
[topic.rs:15](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-pubsub/src/topic.rs#L15)
| One tenant-scoped topic carries the identity, exact type and change
cause. Each relay filters its own subscriptions and rereads the
authorized head or signals resync.
[artifact_sync.rs:211](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/artifact_sync.rs#L211)
[artifact_sync.rs:1039](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/artifact_sync.rs#L1039)
|
| Ordinary event audience | Generic queries and search apply event-store
rules. A client cannot enforce who else receives a response from those
paths, including on a relay with community writes disabled.
[event.rs:785](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/event.rs#L785)
[query.rs:329](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-search/src/query.rs#L329)
| Community payloads stay in the ledger. Ordinary reads and fan-out
enforce the channel boundary, including for rows from older paths.
Explicit artifact views enforce community admission.
[event.rs:7267](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/event.rs#L7267)
[event.rs:153](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/event.rs#L153)
|
| Community redaction | The moderation path requires a channel in `h`. A
client delete cannot apply relay moderation to a stored community
revision.
[side_effects.rs:671](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-relay/src/handlers/side_effects.rs#L671)
| The existing moderation kind gains one community-scoped target form
for direct owners and admins. Redaction preserves the accepted revision
ID and sends affected syncs through the existing resync path.
[community_artifact.rs:214](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/community_artifact.rs#L214)
[community_artifact.rs:609](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/community_artifact.rs#L609)
|
| Community purge | The deletion executor retains the community row as a
tombstone. Client-side removal cannot clear authoritative policy on that
row or prove it was erased.
[deletion.rs:2448](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/deletion.rs#L2448)
[deletion.rs:3488](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/deletion.rs#L3488)
| The existing purge covers both ledger tables. The tombstone
transaction clears the policy map when the column exists, and the
absence check verifies it.
[deletion.rs:2451](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/deletion.rs#L2451)
[deletion.rs:3489](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-db/src/store/deletion.rs#L3489)
|
| Schema rollout | Older writers use the existing two-column conflict
target. Clients cannot preserve that write contract during a key change
or attest which relay binaries are serving.
[artifact.rs:196](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-db/src/store/artifact.rs#L196)
| Migration 0097 adds columns and indexes without a backfill and
preserves the old key. A separate guarded SQL operation installs the
scoped key after the compatible fleet is in place. The rollout guide
documents the sequence and rollback boundary.
[0097_community_artifact_expand.sql:7](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/migrations/0097_community_artifact_expand.sql#L7)
[community-artifact-contract.sql:13](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/scripts/maintenance/community-artifact-contract.sql#L13)
[community-artifact-rollout.md:38](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/docs/community-artifact-rollout.md#L38)
|
| NIP-11 and enablement | The baseline artifact descriptor supplies
neither the tenant UUID nor a signal that the scoped schema is active.
Clients cannot infer activation across mixed-version deployments.
[nip11.rs:478](https://github.com/block/buzz/blob/493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474/crates/buzz-relay/src/nip11.rs#L478)
| One optional discovery object advertises the version, canonical tenant
UUID and policy limit. The handlers and NIP-11 share the configuration
and schema-readiness gate.
[nip11.rs:482](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/nip11.rs#L482)
[community_artifact.rs:51](https://github.com/block/buzz/blob/0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb/crates/buzz-relay/src/handlers/community_artifact.rs#L51)
|

## Size

Measured with `git diff` from `493cb4cc1` to `0b8949f5e`. Dedicated test
files and changed lines inside Rust `#[cfg(test)]` items count as tests.
Each side of a mixed hunk is classified against its own revision.

| | Added | Removed |
| --- | ---: | ---: |
| Production, including schema and rollout SQL | 2,249 | 117 |
| Tests | 1,897 | 53 |
| Docs | 180 | 8 |
| Standalone runtime probe | 397 | 0 |
| **Total** | **4,723** | **178** |

The total includes
`crates/buzz-relay/examples/community_artifact_probe.rs`. The production
and test rows exclude it. The probe supports manual mixed-version and
feature-disabled checks against a running relay.

## Validation

Validated at `0b8949f5e29f5ccf51ec5e2d487f09e2f49bffeb` against
`493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474`.

- The signed HTTP and WebSocket workflow exercised the old and new
channel writers on the expanded schema, the guarded key transition,
community snapshot and live sync, policy compare-and-set and replay,
tenant binding, scope isolation, and redaction followed by resync.
Restarting the relay with community scope disabled after the transition
withheld capability advertisement and preserved channel artifact
operations.
- The normal `buzz-db` suite passed 268 tests, including doctests. All
860 `buzz-db` PostgreSQL tests passed, including the wide `#e` read
regression from #9591.
- The full eight-package PostgreSQL run passed 1,695 of 1,696 tests.
`handlers::ingest::postgres_tests::reaction_and_deletion_h_must_name_the_target_channel`
failed while setting up its private-channel fixture. The same fixture
failed on the protocol base `27a4c8a86e9e9795bfaf5fe59f35164a6389a9ed`.
- The hosted PostgreSQL run at `686b8445` passed 1,698 of 1,699 tests.
The same test was the sole failure on the PR and on `main` at
`493cb4cc13`. In both runs, fixture setup returned `restricted: not a
channel member` while storing the private target. #9640 fixes the
fixture by invalidating the author's membership cache after creating the
private channel. Its PostgreSQL run passes the test. [PR run
44325182932](https://github.com/block/buzz/actions/runs/44325182932/job/134884438543)
· [Main run
44254013047](https://github.com/block/buzz/actions/runs/44254013047/job/134638066441)
· [Fix #9640](#9640) · [Passing test
on
#9640](https://github.com/block/buzz/actions/runs/44248427229/job/134618695910)
- `just test-unit` and `just test` passed on Linux in separate runs. The
commands recorded 6,611 and 7,243 passing test executions, respectively,
with overlap between the suites. These runs passed the CLI socket
ownership tests and push-gateway fixture that failed during the earlier
parallel hook run. Both Tauri Clippy configurations and 3,560 Tauri test
executions also passed at this commit.
- `just ci` passed Rust formatting, workspace Clippy, and desktop,
Tauri, and web checks. It stopped at mobile formatting after the Linux
environment failed to resolve `pub.dev` for the Flutter dependencies.


## End-user test

The PR author’s agent ran the app and plugin end to end on Linux against
a local relay built at `0b8949f5e`. The final browser rerun passed all
15 steps plus the public default-channel case. The native desktop run
passed all seven steps it covered.

- A group saved by the owner appeared in a member’s open Settings
without a reload.
- Changing the write policy to owners and admins made the member’s
editor read-only. The relay refused a signed write by that member and
preserved the current record.
- The audit log identified the policy revision as the accepted
kind-`9034` event ID. The policy change back to everyone used that ID as
`prev`.
- A second relay with community artifacts disabled advertised no
community scope, and the app withheld shared group actions.

[End-user test
evidence](block/buzz-app#3838 (comment))

Supersedes #9646. The reviewed commit is now on an upstream branch.

---------

Signed-off-by: Krish Ray <kray@block.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Codex <codex@openai.com>
@LordMelkor

Copy link
Copy Markdown
Contributor Author

🤖 Closing this. Mention Groups no longer needs community-scoped artifacts: it now keeps its groups as ordinary NIP-AR artifacts in one open system channel per community, which Buzz 1.0.5 and the current relay already support. So this core change fails the necessity test, and the relay side, block/buzz#9650, is being reverted in block/buzz#9689.

@LordMelkor LordMelkor closed this Nov 19, 2026
@LordMelkor
LordMelkor deleted the clod/community-artifacts branch November 19, 2026 02:10
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.

2 participants