Repository navigation
feat(relay): support community-scoped NIP-AR artifacts - #9650
Conversation
Add a proposed extension to NIP-AR for kind 45010 artifacts scoped to a whole community instead of a home channel: a signed community tag, an explicit query scope, a separate identity space, and a per-type write policy set by community owners and admins through a relay-admin command. Documentation only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Krish Ray <kray@block.xyz>
…nity Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Krish Ray <kray@block.xyz>
Bind community-scoped artifacts and type policies to the signed tenant. Reuse NIP-AR revision receipts and exact sync with scoped notifications, current community admission, and an explicit shape for policy reads. Expand the head key while preserving old channel writers, then require an operator step before advertising the new scope. Exercise signed HTTP and WebSocket behavior, cluster delivery, and both rollout stages. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Krish Ray <kray@block.xyz>
…p-ar-community-relay * commit '493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474': perf(db): stop per-id planning of wide #e reads (#9591) Signed-off-by: Krish Ray <kray@block.xyz>
joahg
left a comment
There was a problem hiding this comment.
🤖 Requesting changes for one P1. A human core-team maintainer also needs to review this PR, because it comes from outside the core maintainer group.
What I checked
- The authorization model holds. Every read, write and 9034/9005 path binds the signed community UUID to the request tenant, admission is rechecked under locks, and owner/admin authority requires a direct role.
- The ordinary event, search and fan-out paths exclude community payloads.
- Migration 0097 follows the expand-only rules.
- I found no auth bypass and no cross-community leak.
P1 (inline): send_initial_set maps every open_community_artifact_snapshot error to restricted:. That includes snapshot-permit timeouts and pool or statement timeouts. A rolling deploy that makes every client re-sync at once would tell most of them that they lost access, and NIP-AR tells a client to discard its active set for the community when that happens. Only a real admission denial should close as restricted. Capacity and timeout errors should close as read-failed, like the channel branch right below.
P2 (inline):
schema/tables/public/artifact_heads.sqlstill declares the legacy primary key. After the contract step, production no longer matches the desired-state source, and a routine reconcile would try to restore that key.- Kind 9034 skips the relay-admin write-restriction gate, so a timed-out admin can still change write policy. The comment says this matches the shared gate, but that gate blocks 9030–9033.
P2: history reads don't push #d down to artifact_id. A single-artifact history read therefore scans the JSON of every revision in the community, and the new scoped-identity index goes unused.
P3:
- Writers take the per-type policy lock exclusively, so all writes to one type serialize community-wide. A shared lock for writers, with the exclusive lock kept for policy commands, would keep the ordering.
- Redacting the current head strands the artifact identity:
createreports the identity as taken, andupdateneeds aprevno one else can see. The spec doesn't describe how a client recovers.
Distinguish admission denial from a transient sync read failure, use the shared administrative write restriction for policy commands, reconcile the desired schema with the contracted key, and constrain history scans by artifact identity. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Krish Ray <kray@block.xyz>
|
🤖 The review follow-up is in
All five regression checks failed on the previous head with only the tests applied. All seven focused checks passed on the follow-up. The full PostgreSQL lane passed 1,698 of 1,699 tests. The sole failure,
Writes to the same artifact type serialize on the type lock. Redacting the current head keeps the identity reserved, so a client that lacks the current revision ID cannot supply Follow-up to brow’s reviewThe fixes are in
All five regression tests failed for the reported behavior on On Blox, I measured writer-pool load using real PostgreSQL and Redis, a 10-slot writer pool, and 30 sequential writes per subscriber count. The Delivery design and sharing follow-up
The draft branch includes main at The delivery change checks community admission and the stored FI policy within the primary-backed snapshot and each live head read. Denied live admission closes with
These counts come from tracing the connection acquisition paths. The two-checkout benchmark above describes the earlier revision. Community reads · Channel reads The sharing commit reuses snapshot setup, paging and finish, scoped receipt SQL, revision checks, outcome handling, and limits. The channel write keeps its deployed lock key and authorizes the source before comparing Test changes
Validation on
|
joahg
left a comment
There was a problem hiding this comment.
🤖 Re-reviewed at 686b844. The fixes for every point in my last review hold up:
- P1, snapshot errors:
send_initial_setnow closes withrestricted:only onDbError::AccessDenied. Other errors are logged by kind and close withREAD_FAILED, the same as the channel branch. - Desired-state key:
artifact_heads.sqlnow declaresPRIMARY KEY (community_id, scope, artifact_id). The new migration test runs the guarded contract script and asserts that pgschema plans noartifact_headschanges afterwards. - Kind 9034: the handler calls
enforce_write_restriction, and the store refusestimed_outunder the admission locks, exact retries included. - History
#d: the filter now uses the indexedr.artifact_idwith canonical UUIDs only, so non-canonical spellings still can't match. The EXPLAIN test covers it.
On the P3s, keeping writes serialized on the type lock and reserving the identity after redaction are reasonable maintainer calls, and I'm not pushing on them.
This is a comment, not an approval. The PR comes from outside the core maintainer group, so a human maintainer needs to review it before it merges. I'm dismissing my earlier change request because its blocking point is fixed.
🤖 The blocking point (snapshot errors closing as restricted) is fixed in 686b844; see the follow-up review.
brow
left a comment
There was a problem hiding this comment.
🤖 The pre-review recommends rework. Three problems reach existing behavior:
- The new
tags @> '[["community"]]'exclusions match any tag whose value iscommunity, not only a tag namedcommunity. A channel artifact with, for example, the titlecommunitytherefore disappears from artifact reads, REQ, count, by-id, search and moderation previews, even with community artifacts disabled. - Community admission takes
relay_membersrowsFOR SHAREbefore thecommunitiesrow, and an agent's row before its owner's. That is the reverse of ownership transfer and cascading member removal, so with the feature enabled those operations can deadlock with artifact reads and writes and be aborted. - The community-signal consumer handles a lagged receiver with
resync_all, which also closes every channel-scope artifact sync on the node and forces full snapshot downloads.
To resolve them: check the tag name positionally at every new exclusion (keeping the containment test as a prefilter), with a test for a channel artifact carrying that value. Align the admission lock order with the existing membership writers. Resync only community-interest syncs on signal lag.
Share the positional tag exclusion, take admission locks in membership writer order, scope signal-lag recovery, resync on live admission loss, and erase account-owned community revision payloads while preserving their acceptance receipts. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Krish Ray <kray@block.xyz>
Keep the manual probe on a local branch and remove an unused ArtifactScope accessor. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Krish Ray <kray@block.xyz>
Remove the database enqueue check and artifact-specific idle sweep. Preserve socket credential checks and retire local syncs on host policy invalidation. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Krish Ray <kray@block.xyz>
Keep channel source authorization and lock identity. Use the stored deletion state for community live reads, and serialize policy updates on the community row. Only the roster row supplying authority needs a member lock. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Krish Ray <kray@block.xyz>
* commit '7cf19b713c506b6ce2af72897d23ec1c5c147390': perf(db): bound deep keyset history pages by the cursor timestamp (#9549) feat(cli)!: consistent channels list/get/search output (type, visibility, labels, real created_at) (#9617) ci(docker): publish the push gateway only when its inputs change (#9658) feat(mobile): reply to a message from its iOS notification (#9439) fix(mobile): stop reporting saved images as failed on iOS (#9599) Signed-off-by: Krish Ray <kray@block.xyz>
This reverts commit eebf62b. Community scope adds a relay access gate outside channel membership and needs relay maintainer review before it ships. Reverting before migration 0097 reaches a deployed database keeps the revert free of a schema recovery step. Co-authored-by: Paul <4a1bfa0013bc6d14a8d600d8bf6392efefbd2a26ac3c96c9b2a106b0d12297ca@buzz.block.builderlab.xyz> Signed-off-by: Will Pfleger <wpfleger@block.xyz>
Reverts #9650 (squash commit `eebf62b6`), except for migration `0097` and the channel artifact sync fences it added. Community scope adds a relay access gate based on community admission rather than channel membership, a new relay-admin command kind (`9034`) and an operator-run key transition. Its design and NIP-AR text need relay maintainer review before they ship. Two integration gaps also remain: - Media download authorization looks up references only in `events`, so an attachment referenced only by a community artifact is unreadable when media-read enforcement is on. - User erasure retires a community head in the database without signaling live syncs, so members who are already syncing keep the erased copy. The feature can return as a new PR once those are resolved. ## Kept from #9650 - **Migration `0097`, byte for byte.** Published images already include it, and databases that auto-migrated have recorded it. Dropping it would stop those relays from starting. It only adds columns and indexes that the channel code ignores. The declared schema matches that expanded shape and keeps the `(community_id, artifact_id)` primary key, so the operator key transition no longer exists. - **Channel artifact sync fences.** Snapshot and live sends check for a pending resync and for connection cancellation under the queue lock. A reader who loses access, or whose content is redacted, while a frame is in flight therefore receives no further payload. Handler-backed tests cover a resync recorded while a snapshot payload waits for queue room and one recorded after a live head read. ## Compatibility This revert supports databases that applied only migration `0097`, which is all that auto-migration runs. A database that ran #9650's operator contract script, or was bootstrapped from #9650's declared schema, has no `(community_id, artifact_id)` key, so channel artifact writes fail there. Before deploying to such a database, check that `artifact_heads_pkey` is on `(community_id, artifact_id)` and that `artifact_heads` has no rows with `scope = 'community'`; if either check fails, it needs a separate recovery step. --------- Signed-off-by: Will Pfleger <wpfleger@block.xyz> Co-authored-by: Paul <4a1bfa0013bc6d14a8d600d8bf6392efefbd2a26ac3c96c9b2a106b0d12297ca@buzz.block.builderlab.xyz>
Review found that SET NOT NULL scanned artifact_heads under ACCESS EXCLUSIVE. docs/database.md requires three steps instead: - 0098 adds a NOT VALID check; - 0099 validates it under SHARE UPDATE EXCLUSIVE, so writes continue; - 0100 sets NOT NULL from the validated check and drops 0097's indexes and columns. 0098 also refuses a database whose artifact head key is the scoped key from the removed operator contract, before any cleanup runs. The migrations name #9689 as a required stop, because relays built from #9650 read the dropped column. Tests now bind the surviving head's exact channel and event, and check its revision. New tests check that 0099 runs beside an open head writer and that 0098 refuses the scoped key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Relay images built from #9650 up to, but not including, #9689 read the columns 0100 drops. The chart's upgrade notes now tell operators to move every pod, job and rollback target to sha-a406191 or later first, and how to roll back after 0100. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
…ction-p * origin/main: (200 commits) fix(mobile): keep open shared sessions in Solo (#9704) fix(mobile): align channel indicators and Duo section menus (#9703) fix(mobile): allow person mentions in Solo chats (#9705) fix(mobile): let code scroll under the code block copy button (#9612) Transcribe Bestie hold recordings into text on device (#9645) feat(cli): show and search verified identity in users get (#9647) fix(mobile): keep agent poster up until the iOS video draws (#9688) test(relay): stop bridge cancel_fixture tests timing out on the first replica connect (#9691) Revert "feat(relay): support community-scoped NIP-AR artifacts" (#9689) feat(relay): add conditional Solo member role updates (#9667) feat(mobile): add saved channel section filters (#8479) feat(relay): support community-scoped NIP-AR artifacts (#9650) feat(mobile): add a diagnostics test report and test crash to Settings (#9676) fix(pubsub): round the rate-limit retry hint up from PTTL (#9552) feat(mobile): add diagnostic reporting module with crash capture (#9613) fix(mobile): recover stuck read-state updates and stale Mark Read (#9492) test(relay): refresh the author's membership cache after the stray-h private channel insert (#9640) fix(mobile): name the cause of account-unavailable sign-in errors (#9628) perf(db): bound deep keyset history pages by the cursor timestamp (#9549) feat(cli)!: consistent channels list/get/search output (type, visibility, labels, real created_at) (#9617) ... Signed-off-by: Matthew Boston <mboston@squareup.com>
…eaction-recipients * origin/main: (72 commits) fix(mobile): keep open shared sessions in Solo (#9704) fix(mobile): align channel indicators and Duo section menus (#9703) fix(mobile): allow person mentions in Solo chats (#9705) fix(mobile): let code scroll under the code block copy button (#9612) Transcribe Bestie hold recordings into text on device (#9645) feat(cli): show and search verified identity in users get (#9647) fix(mobile): keep agent poster up until the iOS video draws (#9688) test(relay): stop bridge cancel_fixture tests timing out on the first replica connect (#9691) Revert "feat(relay): support community-scoped NIP-AR artifacts" (#9689) feat(relay): add conditional Solo member role updates (#9667) feat(mobile): add saved channel section filters (#8479) feat(relay): support community-scoped NIP-AR artifacts (#9650) feat(mobile): add a diagnostics test report and test crash to Settings (#9676) fix(pubsub): round the rate-limit retry hint up from PTTL (#9552) feat(mobile): add diagnostic reporting module with crash capture (#9613) fix(mobile): recover stuck read-state updates and stale Mark Read (#9492) test(relay): refresh the author's membership cache after the stray-h private channel insert (#9640) fix(mobile): name the cause of account-unavailable sign-in errors (#9628) perf(db): bound deep keyset history pages by the cursor timestamp (#9549) feat(cli)!: consistent channels list/get/search output (type, visibility, labels, real created_at) (#9617) ... Signed-off-by: Matthew Boston <mboston@squareup.com>
## What Migrations `0098`–`0100` undo migration `0097` (community artifact expand). The declared schema goes back to its shape before #9650. #9650 added `0097`. The revert, #9689, removed the feature but kept `0097` byte for byte, because databases that auto-migrated recorded its checksum. No code on `main` reads or writes what `0097` added. This PR removes it with forward migrations, as `docs/database.md` requires ("Never edit a merged migration. Fix forward."). `artifact_heads.channel_id` gets `NOT NULL` back in the three steps from *Adding `NOT NULL` to a populated table*: - `0098` checks that the artifact head key is `(community_id, artifact_id)`, then adds `CHECK (channel_id IS NOT NULL) NOT VALID`. - `0099` validates the check under `SHARE UPDATE EXCLUSIVE`, so channel artifact reads and writes continue. - `0100` sets `NOT NULL` from the validated check (no scan), drops the check, drops `artifact_heads_live_type`, `artifact_heads_scoped_identity` and `artifact_revisions_scoped_identity`, and drops `artifact_heads.scope`, `artifact_revisions.scope`, `artifact_revisions.community_event`, `artifact_revisions.redacted` and `communities.artifact_type_policies`. The primary keys don't change. `0097` never changed them. ## Review checklist (docs/database.md) - **Phase:** contract. It follows the expand in #9650 (`0097`) and the code revert in #9689. - **Required stop:** every relay pod, job and rollback target must run #9689 (`sha-a406191`) or later before `0100` runs. The chart's upgrade notes (`deploy/charts/buzz/README.md`) say this, along with how to roll back with auto-migration off. No tagged relay release contains #9650. Only rolling images from `eebf62b6` up to, but not including, `a4061916` are affected. Relays built from #9650 itself read `artifact_heads.scope` and write with `ON CONFLICT` on `artifact_heads_scoped_identity`. Releases before #9650 never read these objects. - **Fails closed:** `0098` refuses a database whose artifact head key is the scoped key from #9650's removed operator contract script or declared schema. That database needs the recovery in #9689's Compatibility section. `0099` fails if any head has a null `channel_id`. Both stop before any cleanup. - No trigger, function, procedure, rule or foreign key is added. No migration changes existing rows. - Every schema location in Rule 4 is updated: `migrations/` and `schema/tables/public/` (`artifact_heads.sql`, `artifact_revisions.sql`, `communities.sql`). No reconcile-script or gateway change applies. - **Currently deployed relay:** a relay from #9689 or later doesn't use these objects, and neither does a relay from before #9650. The populated-table test runs every migration over channel artifact data. - **Locks:** each migration sets `lock_timeout = '5s'` and `statement_timeout = '30s'`. No index is built. ## Tests - `admin_schema_parity_between_desired_state_and_migrations` compares `artifact_heads`, `artifact_revisions` and `communities` across the desired-state and migrated paths. It fails without `0100`. - `populated_artifact_tables_auto_migrate_through_every_migration` checks that a channel head and revision written before `0097` survive with the same channel and event. - `artifact_unexpand_validates_while_channel_heads_are_written`: `0099` completes while a channel head write is still open. It fails if `0099` sets `NOT NULL` directly. - `artifact_unexpand_refuses_scoped_head_key`: `0098` stops on the scoped key and leaves `0097`'s columns in place. ## What got simpler The schema loses 5 unused columns and 3 unused indexes. `artifact_heads.channel_id` is required again, as the channel code assumes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Luke Tornquist <tornquist@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…c-spec-mobile * origin/main: fix(mobile): keep glass controls mounted and the wide thread push parallax (#9726) fix(mobile): stabilize Duo chat switching and sheet layering (#9717) Require relay schema owner review for migrations and schema (#9708) fix(relay): resurface a hidden DM when someone else messages it (#9678) fix(deploy): pin self-host installs to relay 0.3.0 (#9714) fix(mobile): keep open shared sessions in Solo (#9704) fix(mobile): align channel indicators and Duo section menus (#9703) fix(mobile): allow person mentions in Solo chats (#9705) fix(mobile): let code scroll under the code block copy button (#9612) Transcribe Bestie hold recordings into text on device (#9645) feat(cli): show and search verified identity in users get (#9647) fix(mobile): keep agent poster up until the iOS video draws (#9688) test(relay): stop bridge cancel_fixture tests timing out on the first replica connect (#9691) Revert "feat(relay): support community-scoped NIP-AR artifacts" (#9689) feat(relay): add conditional Solo member role updates (#9667) feat(mobile): add saved channel section filters (#8479) feat(relay): support community-scoped NIP-AR artifacts (#9650) feat(mobile): add a diagnostics test report and test crash to Settings (#9676) fix(pubsub): round the rate-limit retry hint up from PTTL (#9552) feat(mobile): add diagnostic reporting module with crash capture (#9613) Signed-off-by: Will Pfleger <wpfleger@block.xyz> # Conflicts: # mobile/test/features/activity/activity_page_test.dart
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
45010binds 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.9034sets 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.9005redacts 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
0097expands 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 guideWhy each change belongs in the relay or protocol
htag, 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 artifact.rs:196h. A client delete cannot apply relay moderation to a stored community revision. side_effects.rs:671Size
Measured with
git difffrom493cb4cc1to0b8949f5e. 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.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
0b8949f5e29f5ccf51ec5e2d487f09e2f49bffebagainst493cb4cc1369ff9fdb44ae6c50f18c66d1fb6474.buzz-dbsuite passed 268 tests, including doctests. All 860buzz-dbPostgreSQL tests passed, including the wide#eread regression from perf(db): stop per-id planning of wide #e reads #9591.handlers::ingest::postgres_tests::reaction_and_deletion_h_must_name_the_target_channelfailed while setting up its private-channel fixture. The same fixture failed on the protocol base27a4c8a86e9e9795bfaf5fe59f35164a6389a9ed.686b8445passed 1,698 of 1,699 tests. The same test was the sole failure on the PR and onmainat493cb4cc13. In both runs, fixture setup returnedrestricted: not a channel memberwhile storing the private target. test(relay): refresh the author's membership cache after the stray-h private channel insert #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 · Main run 44254013047 · Fix #9640 · Passing test on #9640just test-unitandjust testpassed 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 cipassed Rust formatting, workspace Clippy, and desktop, Tauri, and web checks. It stopped at mobile formatting after the Linux environment failed to resolvepub.devfor 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.9034event ID. The policy change back to everyone used that ID asprev.End-user test evidence
Supersedes #9646. The reviewed commit is now on an upstream branch.