Skip to content

feat(relay): answer what a viewer may do in channels, and say when to ask again - #9582

Draft
morgmart wants to merge 13 commits into
morganm/task-conversationsfrom
morganm/channel-access
Draft

morgmart wants to merge 13 commits into
morganm/task-conversationsfrom
morganm/channel-access

Conversation

@morgmart

@morgmart morgmart commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Stacked on #9569. A client can ask what its signer may do in named channels, and gets told when to ask again. Task conversations, channels read through a project and open channels the signer hasn't joined all get the same answer. The tasks app uses it to show either a composer or a read-only view without joining anything.

  • Asking. A signed POST /query with exactly [{"access":"channels","ids":[...]}], naming 1 to 100 distinct lowercase channel IDs. The NIP-98 proof must carry a payload tag.
  • Listing. Without ids, [{"access":"channels"}] lists the channels the signer can reach, ordered by ID. That covers joined channels, listed open channels, and what their parents' grants reach below them. A picker can show only the places the signer may post. Conversations and unlisted channels stay out.
    • It is paged, so it never refuses. It takes an optional limit (1 to 100, default 100) and after, and returns {"channels":[...],"next":<id or null>}. To read the next page, send next as after. Walking every page lists each channel once.
  • Answer. One entry per readable channel, in request order: {"id","read":true,"post","joined","role","archived"}.
    • post means a message would be accepted now. It is false for a guest role, an archived channel, a conversation whose home is archived, and a community timeout. Timeouts use the same check a post meets, including an agent restricted through its owner. A banned person, or an agent whose owner is banned, is refused with 403 and the reason, as every request from them is.
    • While the signer is timed out, each entry also carries timed_out_until, so the client asks again when the timeout ends.
    • archived says whether the channel itself is archived, so a picker can leave it out without looking it up.
    • role is the viewer's own row, else an open channel's join_role, else what the parents give (capped at member).
    • Channels the viewer can't read are left out, whether private, deleted or missing.
    • If any channel can't be answered, or the answer takes longer than 8 seconds, the whole request fails with a retryable 503. A channel is only ever left out of a complete answer.
    • The answer reads the viewer's membership and restriction fresh, so a push can't race a stale cache on another node.
    • Channels are looked up four at a time, the same bound the REQ path uses, and the restriction is read once per request.
  • Ask again (kind:20004). Ephemeral, relay-signed, empty content, only ["h", <channel>].
    • Sent to the changed channel and to every private channel under it, conversations included, off the request path.
    • Sent when someone is added, removed, joins, leaves, is kicked or changes role. Also for visibility, join_role, archive, parent or parent_access changes; channel deletion; the TTL reaper; huddle auto-archive and auto-join; and a task's move, delete or restore.
    • Fan-out delivers it only to subscribers who can still read the channel. Those who can't are closed by the existing eviction.
    • It is relay-only: a client can't send it over HTTP or WebSocket.
    • It is best effort. Clients also ask again on reconnect and when a post is refused.
  • Ask again everywhere (kind:20005). Ephemeral, relay-signed, empty content, only ["p", <pubkey>]. It is sent whenever a person's community restriction changes (a timeout or ban starts or is lifted, or an agent's owner is recorded), to that person and each agent they own. Every route reaches it through one relay step, AppState::restrictions_changed, which also drops the cached restriction rows: the moderation commands, the admin API, and resolved reports. A future route that clears the cache can't skip the push. The kind is #p-gated in both REQ and fan-out, so nobody else learns of the timeout. A timeout that runs out sends nothing; timed_out_until covers it.
  • NIP-11 advertises buzz-channel-access. NOSTR.md has a new "Channel access" section and kind:20004 and kind:20005 rows.
  • The archived-home rule moved into closed_by_archive, so ingest and the answer share it.

Testing

  • New Postgres tests (channel_access_postgres_tests.rs). They go through the real /query route with payload-bound NIP-98, real ingest, and real Redis with multi-node fan-out:
    • Per-channel answer for each viewer. Covers the owner, a project member, a project guest and an outsider, across the project, its child, a task conversation, an open channel with guest join_role, and a missing ID. Each answer is checked against what a post actually gets. Archiving closes posting for the channel and its conversation. A proof without a payload tag is refused. A forged 20004 is refused over both HTTP and WebSocket.
    • Guest upgraded with the conversation open (Mongo's case). The guest is told to ask again in the project, the task's channel and the conversation. Their answer flips to post:true, and every subscription stays open. Other readers are told too. Removing the guest closes their subscriptions, notifies the remaining readers, and leaves the guest out of the answer.
    • Archive, unarchive and a task move each send the push. A description change doesn't.
    • Joining and leaving send the push.
    • Listing what a viewer can reach. A project member gets the project, its child, its archived grandchild (marked archived, no posting) and an open channel. A task conversation and a channel walled off with parent_access: none stay out. An outsider gets only the open channel.
    • Paging past 500. A viewer who can reach 523 channels walks every page, at the default size and at 37. They get each channel exactly once, in order, and the last page says there are no more.
    • Cost. A full page of 100 private grandchildren, each read through two levels of parents, answers in under 2 seconds in both forms. The deadline is 8 seconds.
    • Timeouts. A timed-out member and their agent get post:false and timed_out_until everywhere, and a post is refused. Each is pushed kind:20005 when the timeout starts and when it's lifted. A bystander's subscription to the kind, even without #p, gets nothing. After lifting, posting is back. A 3-second timeout lifts on its own, the answer follows, and no push fires at expiry. A ban is pushed to the person and their agent, and both are then refused with "you are banned", and can't post.
    • Dashboard route (in the admin API's Postgres tests). A timeout and a ban set through the admin API's direct routes (which resolve through the report path) push to the person and their agent, and not to a bystander.
  • Unit tests: request shape validation, and a failed lookup failing the whole request with a 503 and no entries.
  • Mutation checks. Each one turned a test red:
    • ignoring the archive state
    • reporting every channel as joined
    • ignoring join_role
    • skipping failed lookups
    • dropping descendants from the push
    • dropping the push from add, remove, metadata, conversation, join or leave
    • pushing on every metadata change
    • dropping the WebSocket relay-only check
    • dropping payload binding
    • listing only open channels
    • leaving the restriction out of post, or dropping timed_out_until
    • dropping the push from restrictions_changed, or skipping the owner's agents
    • delivering the push without the #p gate
    • starting a page at after inclusive
    • never setting archived
    • making each channel's lookup 100ms slower
  • An independent review found real gaps, now fixed: WebSocket forgery, missing pushes on delete and huddle paths, the push running on the request path, no deadline, and a role-lookup race.
  • Before the paging and timeout round: the full Postgres lane for buzz-relay and buzz-db passed, 1455/1455.
  • After it: all 9 channel-access Postgres tests pass on an isolated database. Clippy is clean with -D warnings. The pre-push unit lanes pass at bedc2768c, after merging main through the stack (migrations renumbered to 0093–0095). CI runs the full Postgres lane on the final head.

Known limits

  • The pushes for the TTL reaper, channel delete, kick and the huddle paths are wired in but have no test of their own. The reaper loop lives in the binary.
  • Lookups overlap but aren't merged into one query. The timing test covers a full page.
  • A page's candidates come from one read of every reachable ID, sorted in memory before slicing. That's one cheap read per page, not a cursor in SQL.
  • If a pod misses a restriction-cache drop, its ingest can lag the answer by up to the cache's maximum age.
  • Typing indicators and other ephemeral kinds still reach a conversation through the existing ephemeral gate.

🤖 Generated with Claude Code

morgmart and others added 3 commits November 16, 2026 00:14
… ask again

A signed POST /query with {"access":"channels","ids":[...]} answers, per
readable channel, whether the signer may post, whether they joined, and
the role they act with. Without ids it answers for every channel the
signer can reach. A relay-signed ephemeral kind:20004 tells live
subscribers to ask again after a change to who may read or post.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  fix(relay): hold task conversations to comments and cover the review gaps
  feat(auth): tolerate client clocks up to 120 s off (#9485)
  docs: name the required stop as a relay build, not a release (#9577)
  buzz-db: drop the created_at floor, community write-fence and migration-only NIP-RS triggers (contract) (#8326)
  Keep community deletion working across a new tenant table's migration (#9304)
  docs: design Android push notifications (#9555)
  feat(push-gateway): accept deliveries on a platform-neutral route (#9557)
  fix(mobile): read a Solo chat through its newest message on open (#9515)
  fix(mobile): keep the Solo header's agent portrait while its roster reloads (#9512)
  perf(mobile): pulse the Solo working dots at 12 fps on a shared clock (#9554)
  test(mobile): match the resumeSince override in the search journey (#9546)
  mobile: show account communities in the switcher and sync saved destinations (#9262)
  perf(mobile): stop replaying stored read state on every resume (#9090)
  perf(mobile): save the open-channel directory and catch it up (#9513)
  fix(mobile): sign out from Settings in every build, keeping keys on the device (#9421)
  fix(mobile): wrap inline Markdown links with their sentence (#9462)
  feat(mobile): message the Bestie from Siri and Shortcuts (#9517)
  fix(mobile): slide a closing chat away instead of cutting to the list (#9511)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  Refuse opening a private channel that has other members (#9307)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
morgmart and others added 10 commits November 16, 2026 10:45
The list form now pages with `after`, `limit` (1 to 100) and `next`
instead of refusing past 500 channels. Every entry carries `archived`.
`post` now applies the community ban and timeout check ingest uses, and
a timed-out viewer's entries carry `timed_out_until`. Timeout and
untimeout push a relay-signed, #p-gated kind:20005 to the person and
their agents. Channel lookups overlap four at a time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  feat(deletion): clean up media for users and owned agents (#9365)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  update feedback community invite link (#9588)
  fix(mobile): name the failing step in sign-in errors (#9263)
  fix(mobile): order same-second messages by millisecond offsets (#9541)
  fix(acp): saturate observer frame size estimates (#9494)
  feat(mobile): accept mentions with Tab and send with Enter on hardware keyboards (#8733)
  Fix remote Huddle ending cleanup (#9376)
  fix(mobile): host Duo long-press menus in native sheets (#9536)
  fix(mobile): keep the relay session across auth reloads (#9543)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>

# Conflicts:
#	crates/buzz-relay/src/audio/handler.rs
Every route that sets or lifts a ban or timeout (the moderation
commands, the admin API, and resolved reports) already had to drop the
cached restriction rows. That drop is now AppState::restrictions_changed,
which also sends the per-person kind:20005 push to the person and the
agents they own. The per-route sends are gone, so a timeout set from the
dashboard or by resolving a report now pushes, and a future route that
clears the cache cannot skip it.

A timeout that runs out sends nothing; the answer's timed_out_until is
when the client asks again. A banned person's answer has post:false and
no timed_out_until.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
A banned signer, or an agent whose owner is banned, is refused with 403
and the reason before any per-channel answer. Document that, and assert
it beside the ban push.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  [buzz] Classify HTTP event request metrics by event type (#9561)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  feat(workflow): implement send_dm action (#9402)
  perf(mobile): stop following presence for people no longer shown (#9480)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  feat(relay): grow DMs in place, identified by their people (#9125)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  buzz-db: check workflow references in app code before FK retirement (#9399)
  fix(relay): enforce channel owner precedence (#9592)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
* morganm/task-conversations:
  buzz-db: check membership, agent-owner and channel references in app code (#9404)
  buzz-db: enforce five single-table guards in app writers (phase 1) (#8320)
  docs(mobile): add REVIEWING.md with mobile review principles (#9298)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant