Skip to content

feat(relay): emit NOTICE when mentioned pubkey has no active connection (#1743)#1862

Open
cameronhotchkies wants to merge 1 commit into
block:mainfrom
cameronhotchkies:fix/1743-relay-offline-notice
Open

feat(relay): emit NOTICE when mentioned pubkey has no active connection (#1743)#1862
cameronhotchkies wants to merge 1 commit into
block:mainfrom
cameronhotchkies:fix/1743-relay-offline-notice

Conversation

@cameronhotchkies

Copy link
Copy Markdown
Contributor

Summary

When a kind:9 channel message with p tags is successfully ingested, the relay now checks whether each mentioned pubkey has an active WebSocket connection in the community. If not, a NIP-01 NOTICE is sent back to the sender indicating the target appears offline.

This is Fix #1 from the #1743 scoping — giving senders immediate feedback that their mention may not be delivered in real-time.

How it works

  1. Before the event is moved into the ingest pipeline, extract all p-tag pubkeys (deduped, sender excluded)
  2. After successful ingest, check conn_manager.connection_ids_for_pubkey_in_community() for each pubkey
  3. If the returned list is empty (no active WS connection on this pod), send a NOTICE:
    ["NOTICE", "offline: mentioned user <hex> appears to have no active connection"]
    

Constraints & trade-offs

  • Pod-local only — if the target is connected to a different relay pod, the notice still fires. Acceptable for v1; a future enhancement could consult Redis presence.
  • Lightweight — no Redis round-trip. Uses the existing in-memory connection manager which is O(n) over connections but typically small.
  • Only kind:9 — no overhead added to other event types.
  • Metric: buzz_mention_offline_notices_total counter for observability.

Testing

  • cargo check -p buzz-relay
  • cargo clippy -p buzz-relay -- -D warnings ✅ (zero warnings)

Related

…on (block#1743)

When a kind:9 channel message with p-tags is ingested, the relay now checks
whether each mentioned pubkey has an active WebSocket connection in the
community. If not, a NOTICE is sent back to the sender indicating the
target appears offline.

This is pod-local only (no Redis round-trip) — a mentioned user connected
to a different pod will still trigger the notice. Acceptable for v1; a
future enhancement can consult Redis presence.

Implementation:
- Extract p-tag pubkeys before ingest (deduped, sender excluded)
- After successful ingest, check conn_manager for each pubkey
- Send NIP-01 NOTICE for each offline mention
- Metric: buzz_mention_offline_notices_total

Co-authored-by: Cameron Hotchkies <chotchkies@block.xyz>
Signed-off-by: Cameron Hotchkies <chotchkies@block.xyz>
Co-authored-by: Goose <opensource@block.xyz>
Ai-assisted: true
@cameronhotchkies cameronhotchkies requested a review from a team as a code owner July 14, 2026 18:14

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From my agent...

The underlying silent-stall problem is real, but this implementation does not yet provide a reliable sender warning.

Blocking issues:

  1. Every p tag is treated as an explicit mention. Buzz replies structurally include the replied-to author's p tag (desktop/src/features/messages/lib/threading.ts), so an ordinary reply to an offline author will produce a misleading “mentioned user” notice even when the message did not mention them. The wire format needs to distinguish explicit mentions from reply routing metadata (or this check needs to consume existing explicit-mention metadata).

  2. The desktop sender drops NOTICE frames. RelayClientSession.handleWsMessage handles only AUTH, EVENT, OK, and EOSE; ACP only writes NOTICE to its warning log. Thus normal desktop users get no visible feedback, and sending agents do not receive a machine-actionable failure signal. Please wire the result into the sender UX/agent send path so this actually fixes #1743.

  3. Presence is only pod-local and checks any authenticated connection, not a matching subscription/delivery. In a multi-pod deployment it can report an online recipient as offline; conversely, an unrelated authenticated socket can suppress the warning even when no harness subscription received the message. Please use authoritative cross-pod presence with semantics tied to the intended recipient/delivery guarantee, or explicitly narrow and prove the behavior.

Please also add focused relay/client tests covering accepted-only behavior, kind restriction, dedupe/self-exclusion, explicit mention vs reply-author p tags, online/offline cases, and visible handling of the notice. The current change adds no tests for this critical path.

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.

Dependency Dashboard

2 participants