Repository navigation
feat(relay): let plugins keep NIP-AR community-scoped artifacts - #3838
LordMelkor wants to merge 14 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
🤖 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
#typeand no#h. - Capability detection requires
nip-arandcommunity_scopev1, and the generic sign and HTTP paths still refuse 9034.
P2s, inline:
typePolicy.setis 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. typePolicyisn't tied to the session lifecycle.readandsetkeep working after close or access revocation.
Smaller notes:
sync({scope: "community"})doesn't checkcommunityId, so on a relay without community scope it sends an unknownscope.- 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
communitytag, or the absence of anhtag, on the events it keeps. - The native path has no negative tests showing
invokeis never reached for a wrong community.
| async read(type, signal) { | ||
| return parseTypePolicy(await read(type, signal)); | ||
| }, | ||
| async set(change, signal) { |
There was a problem hiding this comment.
🤖 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.
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>
|
🤖 Thanks for the review. Here is what changed at P2: the broker's 403 (
P2:
P2: a per-plugin gate on
Smaller notes
Checks at |
joahg
left a comment
There was a problem hiding this comment.
🤖 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:andblocked:.auth-required:and every other route are unsent and retryable again, as on main. typePolicylifetime: 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 throughAbortSignal.any.- Community sync on an unsupported relay:
sync({scope: "community"})now reportsunsupportedwhen 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.
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>
## 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>
|
🤖 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. |
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_scopeversion 1 keeps kind-45010 revisions that carry acommunitytag and noh. It also keeps a per-type write policy, set with kind 9034. Today a plugin can't do either:session.artifacts.syncthrows on a filter without#h.The app gains three things:
session.artifacts.sync({ artifact: "current", scope: "community", "#type": [type] })takes exactly one#typeand no#h. It has the same statuses as a channel sync.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.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.
configArtifactWriteralready signs anh-less 45010, andsnapshotReadalready 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.
artifact-community.ts(new): wire helpers for community id, type name grammar, 9034 template and validation, policy filter and parserartifact-sync-filter.ts.artifact-sync-filter.ts: acceptscope: "community"with one#type#hon both hosts (artifact-sync.ts,relay-broker.mjs).native.ts,transport.ts,relay-broker.mjs: readartifacts.community_scopeat connecttransport.scopeis the relay origin, not the community UUID.artifact-type-policy.ts(new) plus one route each innative.ts,transport.tsandrelay-broker.mjs: a typed 9034 sign, publish and policy readconfigArtifactsrefuses any kind but 45010, andrelay_signrefuses 9034. The broker's/signdoesn't handle it. The policy answer is a JSON object, whichparseEventsrefuses.channel_writes.rs,relay.rs: the native shape check for the 9034 route, and 9034 added to the/eventsrefusal listrelay_signkeeps refusing 9034.socket-requests.ts: treat a 9034conflict:like the existing 40100 and 45010 compare-and-set refusalsprevis reported as an unconfirmed publish instead of the relay's refusal.session.ts:communityIdandtypePolicyonsession.artifactsmatch(observation, context)gets onlycontext.session, so the community gate has to live there.typePolicyis 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 reportsunsupported.docs/artifact-sync.md: one sectionBoundary.
typePolicyacts 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) at0418421e0, withgit diff. Rust test modules count as tests.The two largest pieces are
artifact-community.ts(+134, the shared NIP-AR wire helpers) andartifact-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-boundtypePolicy, its cancel on an access change, the spread of the two fields, and the community sync check. The bounds themselves live inartifact-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 inartifact-community.tsinfer their return types.artifactTypePolicyAccessnow checks its object withsatisfies ArtifactTypePolicyAccess, which keeps the methods' parameter types. Two edits this PR makes tomain's comments stay, becausemain's text would no longer be true: theartifact-sync-filter.tsheader (the file now imports another wire contract) and therestrictedstatus doc (a community sync has no#h). The test doubles stay. They stand in for the relay writer and read, Tauriinvokeandfetch, asmain's relay tests do in the same files. The one polling finding was fixed ine4b32aa3b. An independent review found no behavior or type change.All runs were on a separate Linux machine. Biome's format check is also clean.
0418421e0e4b32aa3b96138f4395a20a5cd00bin/node scripts/check-push.mjs(types and related tests)tscpass; 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.check-push.mjs --designcheck-push.mjs --clippy96138f4395cargo test relay::a20a5cd00vitest run src/features/relayartifact-type-policy.test.ts, 20 runsNew tests cover:
prevandcreated_atbounds.setoutcomes (accepted, rejected with the relay's reason, not sent, unconfirmed).readrefusing a malformed relay answer.restricted:andblocked:to it, and every other publish route still answers 503 withsent: false.typePolicy's session bounds: frozen, refused after close and at the cap, and aborted on dispose and on an access change.Known limits:
typePolicy.setneeds 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:
0b8949f5e, with community artifacts on, and a second relay with them off;main(46a09dbfd) with feat(composer): let completion providers add rows beside the caret owner #3836, feat(composer): one chip for several recipients, sent as @label #3837 and this PR atb2f6be14fmerged in.a20a5cd00changes only tests.e286e0e360answers review (the broker's refusal mapping, the policy calls' lifetime, the community sync check).96138f4395moves the policy calls' session bounds out ofsession.tsintoartifact-type-policy.ts, with no behavior change and no test changes; the tests above cover it.e4b32aa3bchanges one test only: the abort case waits on a promise that the scripted publish resolves instead of polling the publish spy (from a pass with the landmines lint rules).0418421e0removes comments and return types only;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 at1ac9b9aeb(which contains #3836 at702432464) and #3838 at0418421e0merged 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 aptag), and the step with a default channel the saver hasn't joined passed too. Only the test scripts changed, formain'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 groupptags.typePolicy.read: a new community reads{"policy":"everyone","revision":null}.typePolicy.set:previs that revision.restricted: community artifact access denied, and the record didn't change.communitytag and noh.Merge order
This PR shares no files with #3836 or #3837. #3836 must ship no later than this PR: a plugin that offers
@rows oncecommunityIdis 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