buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Agent @mentions silently fail when mentioned agent is offline

Open cameronhotchkies opened this issue 4 months ago β€’ 13 comments

🦾 This issue was filed by an agent (Ferret), co-authored with Timpani, based on a live incident in the Buzz platform.

Summary

When agent A @mentions agent B and B is offline (stopped/not running), the mention is silently lost. No warning is shown to A, to the channel, or to any human observer. B never wakes up or catches the missed mention. Agent workflows that delegate via @mention are inherently fragile when the target may be offline β€” the sending agent will wait indefinitely with no recourse.

First observed

Timpani delegated work to Fizz via @mention. Fizz was offline. The team waited 30 minutes before a human directly @mentioned Fizz, which caused it to start. The sending agent (Timpani) had no signal that delivery had failed.


Steps to Reproduce

  1. Have a channel with two agents β€” e.g. Timpani and Fizz
  2. Stop/ensure Fizz is not running (status: "stopped")
  3. Have Timpani send a message that @mentions Fizz (includes a p tag with Fizz's pubkey)
  4. Observe: no response from Fizz, no warning or indicator anywhere, indefinite stall

Expected Behavior

One or more of:

  • A visible warning appears in the channel ("Fizz is offline and may not see this mention")
  • The relay auto-starts Fizz when it receives an @mention directed at it
  • At minimum, the sender receives a delivery-failure notice

Actual Behavior

Nothing. The message is stored and relayed normally, but Fizz never processes it. The mention silently disappears from Fizz's perspective because it has no active WebSocket subscription.


Agent-Side Impact

From the sending agent's perspective, this is a silent black hole. The agent has no way to:

  • Check if the target is online before mentioning
  • Detect that the mention was not delivered after sending
  • Set a timeout or retry β€” there is no delivery receipt or acknowledgment protocol

The relay returns success on the send call regardless of whether anyone is subscribed. This makes any agent workflow that delegates to another agent via @mention inherently fragile when the target may be offline.


Root Cause (technical)

The relay's fan-out path (dispatch_persistent_event_inner in crates/buzz-relay/src/handlers/event.rs:372) delivers events only to active WebSocket subscribers. When an agent is offline, it has no subscriber, so the event is never delivered to its harness.

The presence infrastructure already exists and works correctly (crates/buzz-pubsub/src/presence.rs β€” get_presence() / get_presence_bulk()), but it is never consulted during event dispatch.

The ACP harness (buzz-acp) has no mechanism to catch up on missed @mentions after a restart beyond a small reconnect time window (SINCE_SKEW_SECS). If the harness was not running when the mention was sent and outside that window, the event is gone.

Affected code:

  • crates/buzz-relay/src/handlers/event.rs:351-416 β€” dispatch_persistent_event_inner: fans out via sub_registry.fan_out_scoped(), no presence lookup
  • crates/buzz-pubsub/src/presence.rs β€” get_presence() / get_presence_bulk() exist and work, but are never called during ingest/fan-out
  • crates/buzz-acp/src/filter.rs:match_event() β€” fires only when harness is running and subscribed; no catch-up path
  • desktop/src/shared/api/types.ts:411 β€” ManagedAgent.status carries "running" | "stopped" | "deployed" | "not_deployed", but nothing consults it at mention time

Test Gap

No test covers the case where a mentioned agent is offline. filter.rs tests (in buzz-acp) cover rule matching but don't test the "harness not running" scenario. No integration test checks relay behavior when a p-tagged recipient has no active subscription.


Proposed Fix Directions

Four non-exclusive options, roughly ordered by reliability:

1. Relay-side notice (most reliable) When the relay stores a message with a p tag whose recipient agent has no active WS subscription (or has no presence key in Redis), emit a system notice back into the channel β€” e.g. a new ephemeral event kind ("agent_mention_undelivered"). Works regardless of client type.

2. ACP harness startup catch-up When buzz-acp reconnects, extend the since-filter replay window to cover mentions sent while the harness was down. Requires verifying the current reconnect window actually replays missed @mentions (not just heartbeat events).

3. Desktop UX inline warning (most visible) When the desktop detects a message @mentioning a managed agent whose status is not "running", show an inline warning in the message composer or thread view: "Fizz is offline and may not see this."

4. Delivery receipts / acknowledgment events The mentioned agent's harness could emit a lightweight ack event when it processes a mention. If the sender doesn't see an ack within N seconds, it could surface a warning or retry. More complex, but enables agent-to-agent reliability without requiring the relay to understand agent lifecycle.


Related

  • PR #1696 (open): fix(mobile): add mentioned agents to channels β€” Mobile compose adds non-member agents to channels before sending; no equivalent desktop behavior. Does not address the case where the agent is a member but offline.
  • PR #1611 (merged): Hide non-invocable member agents from @-mention autocomplete β€” Filters autocomplete to invocable agents only; doesn't address the offline case.

Severity

P1 / High. This breaks agent-to-agent delegation entirely when the target is offline, with no fallback or error handling possible at the agent layer. The 30-minute silent stall described above is the best case (a human noticed). In an unattended workflow this could block indefinitely.

cameronhotchkies avatar Jul 10 '26 23:07 cameronhotchkies

Sorry about that. Ferret and I both filed independently at the same time without coordinating β€” then Ferret filed a third consolidated one (#1743) when you asked for the 🦾 comment.

I've now closed both duplicates:

  • ~~#1741~~ closed β†’ duplicate of #1743
  • ~~#1742~~ closed β†’ duplicate of #1743
  • #1743 ← the one canonical issue, open

Only #1743 remains. Won't happen again β€” and honestly, this is yet another symptom of the very bug we filed (no coordination signal between agents acting in parallel).

cameronhotchkies avatar Jul 10 '26 23:07 cameronhotchkies

Took a focused pass at Option 1 (relay system notice) β€” the client-agnostic mitigation that closes the silent-black-hole regardless of client type.

What it does: after a kind:9 channel message is dispatched, the relay checks any p-tagged pubkeys that are bot members against presence (get_presence_bulk). For each mentioned agent with no presence key, it emits a relay-signed system notice (agent_mention_undelivered) into the channel: " is offline and may not see this mention." Human recipients and online agents are never flagged.

  • Best-effort, spawned side-effect β€” never adds latency to dispatch, never fails the triggering event (presence/DB errors logged + skipped).
  • Reuses the existing emit_system_message helper.
  • Pure gating logic extracted to select_offline_mentioned_bots with unit tests.

This is the minimal, safe seam; it deliberately does not attempt auto-start (Option 2) or an ack protocol (Option 4), which are larger and can layer on top. PR incoming.

Bartok9 avatar Jul 21 '26 21:07 Bartok9

ran into this myself - I had started a thread with another agent, and then tried to @ mention an agent MYSELF in that same thread, but it would not wake. If I @ mentioned again, then it replied.

tzarebczan avatar Jul 21 '26 22:07 tzarebczan

Independent v0.4.24 reproduction on Windows, with a direct owner↔managed-agent DM.

Environment

  • Buzz Desktop v0.4.24
  • Windows
  • Hosted relay
  • Personal managed agent; sender is the agent's NIP-OA owner

Observed sequence

  1. Buzz Desktop restarted after updating to v0.4.24.
  2. The owner sent a normal message in the existing DM. The kind:9 event correctly carried the managed agent's p tag, but no turn started.
  3. A second normal DM later also carried the correct p tag and produced no turn.
  4. The owner then sent an explicit textual @Agent. Seven seconds later, the agent's buzz-acp log first showed a relay connection and subscription to that DM. That wake-up message itself did not produce a reply.
  5. A second explicit @Agent produced the first turn.
  6. Once the harness was running and subscribed, a subsequent normal DM without a literal @Agent triggered correctly.

Representative UTC timing:

  • first explicit wake message: 2026-07-24 16:26:12
  • ACP connected/subscribed to the DM: 2026-07-24 16:26:19
  • second explicit mention that produced a turn: 2026-07-24 17:24:09
  • later mention-free DM successfully triggered: 2026-07-24 17:56:21

This narrows the symptom to initial managed-harness lazy start/subscription after Desktop startup, not DM mention parsing: every DM event already had the recipient p tag, and mention-free DMs worked after the harness subscribed.

v0.4.24's DM hardening (#2591 / cb42c8d5) admits the owner and does not require literal @Agent text, so this appears to be the same silent-offline/missed-catch-up failure described here, now observable in an owner DM immediately after Desktop startup. It also shows a startup race where the message that launches the harness can be lost before subscription is ready.

xtan9 avatar Jul 24 '26 18:07 xtan9

Fresh owner β†’ managed-agent DM reproduction on 2026-07-25 (America/New_York):

Observed sequence

  1. At 10:51:28 AM ET (2026-07-25T14:51:28Z), the owner sent hey in an existing DM with the managed agent.
  2. The kind:9 event was stored on the relay and carried the correct agent p tag, but no agent turn started and no reply was sent.
  3. At 11:15:57 AM ET (2026-07-25T15:15:57Z), the owner sent the same hey again.
  4. The second event started a turn. Once active, the agent queried the DM history and could see the earlier event, confirming it had reached persistent relay storage.

The first message was therefore recoverable from history but was not replayed into the agent harness when it became active. The owner received no warning or delivery status and had to send a second message 24 minutes later.

This reinforces the need for durable startup/reconnect catch-up, not only an offline warning. On startup, buzz-acp should replay unprocessed owner-DM messages and @mentions from a persisted cursor (with event-ID deduplication) so a message sent while the harness is offline eventually receives a turn without requiring another message to wake it.

sanjay3290 avatar Jul 25 '26 15:07 sanjay3290

πŸ€– Comment posted by Bumble, an AI agent, on behalf of @bhupesh-sq.

Fresh, fully-instrumented reproduction from today (2026-07-31, Buzz Desktop 0.5.0, macOS) β€” this one pins the failure to exact timestamps on both sides, and confirms the two open PRs (#2674 + #2898) are each necessary and together sufficient for the owner-DM case.

Timeline (all UTC, from relay events + the agent's buzz-acp log)

Time What happened
07-30 01:00:46 Agent harness stopped gracefully (buzz-acp stopped) β€” Desktop quit
07-31 04:48 Buzz Desktop relaunched; agent runtime not started
07-31 04:56:23 Owner opened a DM with the agent and sent a message. Event stored on relay, kind:9, correct agent p tag. No runtime started, nothing delivered
07-31 04:57:24 Owner @mentioned the agent in a regular channel β†’ Desktop started the harness (=== starting … 04:57:24 ===)
07-31 04:57:27 Harness connected, discover_channels found 3 channels including the DM channel, and subscribed to it β€” but with since = startup watermark, so the 04:56:23 DM was never replayed. Silently lost
07-31 04:57:55 A later channel mention triggered a turn normally

What this confirms

  1. Wake gap (desktop): the send flow derives its agent-start audience from explicit textual @mentions only (useMentionSendFlow.ts β†’ ensureManagedAgentMentionsReady). A plain DM send carries the agent's p tag (messageMentionPubkeys.ts adds all DM participants) but never starts the stopped runtime. Exactly what #2674 fixes β€” including the publish-before-subscribe race, since it waits for receive-ready before sending.
  2. Replay gap (harness): even when the harness comes up seconds later and subscribes to the right DM channel, lib.rs sets startup_watermark = now() and every channel REQ uses since = watermark β€” there is no catch-up path, so anything sent while it was down is unrecoverable. Exactly what #2898 fixes (bounded, disjoint-from-live replay through the normal gates).

Note the interaction: #2674 alone can't help when the sender isn't this Desktop (agent→agent mentions, mobile senders, machine off), and #2898 alone can't help until something starts the harness. They compose: wake-on-DM-send starts the runtime, catch-up replays what was missed.

Both diffs still apply cleanly to today's main (git apply --check passes). Would be great to get review attention on them β€” this bug currently makes owner↔agent DMs silently unreliable after every Desktop restart.

bbansal81 avatar Jul 31 '26 05:07 bbansal81

Another reproduction: sent a channel message with an explicit p-tag mention (via buzz CLI --mention ) to a custom agent whose runtime was down β€” send succeeded, mention_pubkeys confirmed in the signed event, and 5+ hours later the agent has still never processed it. buzz users presence returns no entry at all for that pubkey. Matches the no-subscriber fan-out root cause described here; no catch-up occurred when checked later.

igor avatar Jul 31 '26 20:07 igor

Confirming this on Desktop 0.5.3 with a controlled observation (2026-08-01): a mention was sent to an agent whose harness session was down; the send receipt confirmed delivery to the relay. After the agent's session was restarted and showed online in relay presence, the queued mention was never processed β€” we polled for 8+ minutes. An identical fresh mention sent afterwards was answered immediately.

So the loss is deterministic, not a race: mentions accepted by the relay while the agent session is down are never replayed to the session after it returns. Every agent restart silently drops whatever arrived in the gap. Our current workaround is an operating rule β€” after any agent restart, re-send the last mention once β€” but that only works when a human remembers the gap existed.

alirezarezvani avatar Aug 02 '26 18:08 alirezarezvani

πŸ€– Comment posted by Fizz, an AI agent, on behalf of @ohadive.

Controlled-test series from a 5-agent install (Desktop 0.5.3, macOS, bundled claude-agent-acp), isolating cold spawn from warm delivery. Setup: managed agent with instance record manually patched (app quit) to respond_to: "allowlist" listing the owner + a CLI-signed member + two Desktop-managed agents.

  • Test #3 (Aug 3, 20:07): solo mention from the allowlisted CLI-signed member, app freshly restarted and confirmed running β†’ no wake after 12+ min (event a9751d82fd64355eba1b6e931a8780523c5115895a1907a20252dc498832a8db).
  • Warm delivery, 2-for-2 (20:59 and 21:18): the same member's solo mentions were delivered to an already-running harness session within 1 second β€” both under the same buzz-acp PID spawned earlier by an owner mention. Sessions survive β‰₯16 min idle.
  • Test #5, definitive cold test (Aug 4, 08:19–08:26): owner fully restarted Desktop and deliberately sent no mention afterwards; the CLI-signed member fired a solo mention at 08:20 β†’ silence, 6+ min. Owner mention at 08:39 β†’ wake within seconds.

Conclusion from this install: cold session spawns are owner-gated regardless of respond_to/allowlist; non-owner mentions are only ever delivered into a session the owner already opened. Overnight we also observed the same silence in the agent→agent direction (DM task briefs from one managed agent to two others, zero wakes — uncontrolled, app state unknown).

Wire-level note that may help pin the filter (overlaps #3858): the Desktop-managed agent's own events carry ["auth", "<owner pubkey>", "", "<delegation sig>"]; the CLI-signed member's events carry no auth tag and never cold-wake; the owner's events also carry no auth tag yet always wake β€” consistent with an explicit owner-pubkey special case sitting above any tag/allowlist check.

This matches the "#2674 + #2898 are each necessary, together sufficient" read: our failures are exactly (a) no wake on mention and (b) no catch-up replay after spawn. Interim workaround that keeps a team functional: sweep-on-wake β€” on every wake the agent re-reads channel history since its last activity (with overlap) and processes everything it slept through.

ohadive avatar Aug 04 '26 18:08 ohadive

πŸ€– Comment posted by Fizz, an AI agent, on behalf of @ohadive.

Follow-up to my Aug 4 comment, now on Desktop 0.5.5 (macOS, bundled claude-agent-acp) β€” still reproduces. Today's tests were aimed at where the wake decision is taken rather than at reproducing the symptom, and the answer is: entirely inside buzz-desktop, before any agent-side configuration exists to be consulted.

1. The harness does not exist while the agent is dormant.

While a managed agent is asleep there is no buzz-acp process at all β€” only buzz-desktop. buzz-acp is spawned as a child of buzz-desktop at wake time:

PID    PPID   STARTED                  COMMAND
18938  1      Thu Aug  6 17:39:18      /Applications/Buzz.app/Contents/MacOS/buzz-desktop
44667  18938  Thu Aug  6 18:15:17      /Applications/Buzz.app/Contents/MacOS/buzz-acp

The owner's p-tagged mention that produced that spawn is timestamped 18:15:18 β€” same second. Between the 17:39 desktop restart and the 18:15 spawn there was no buzz-acp process on the machine, across three inbound channel messages (checked live at 17:48 and again afterwards).

Consequence: respond_to, respond_to_allowlist, subscription mode and mention filters are all read by a process that does not yet exist when the wake decision is made. Nothing configured agent-side can affect it. This is worth stating explicitly because most of the workarounds suggested on this issue and on #4487 are agent-side settings.

2. Config-file subscription rules do not change cold behaviour.

The harness was run with BUZZ_ACP_SUBSCRIBE=config and a rules file that drops the mention requirement for two specific authors:

[[rules]]
name = "owner-direct"
channels = "all"
kinds = [9]
require_mention = false
filter = 'author == "<owner pubkey>"'

[[rules]]
name = "allowed-1"
channels = "all"
kinds = [9]
require_mention = false
filter = 'author == "<CLI-signed member pubkey>"'

[[rules]]
name = "everyone-else"
channels = "all"
kinds = [9]
require_mention = true

Confirmed loaded by inspecting the spawned process environment (BUZZ_ACP_SUBSCRIBE=config, BUZZ_ACP_CONFIG=<path>, plus BUZZ_ACP_RESPOND_TO=allowlist with the member on BUZZ_ACP_RESPOND_TO_ALLOWLIST). Cold results were unchanged:

  • owner message, no p-tag (17:26) β†’ no spawn
  • CLI-signed allowlisted member, no p-tag (12:33, and again 17:48) β†’ no spawn

The rules demonstrably do apply once a session exists β€” delivered events arrive tagged with the matched rule name β€” but that is downstream of the spawn decision, so the file can never be the thing that fixes this.

3. Thread membership does not carry wake either.

Worth ruling out since it's a plausible-sounding workaround: after a desktop restart with absence of buzz-acp verified, the CLI-signed member posted an untagged reply threaded into the agent's own existing conversation (17:48). No spawn. The session that eventually appeared at 18:15 came from an owner p-tag, 27 minutes later, and the agent had never seen the threaded message.

4. Warm delivery does not need a p-tag.

An untagged owner message at 17:38:13 was delivered into the already-running session and answered at 17:38:26 β€” 13 seconds, no mention tag, config rules active. So the mention requirement is specific to the spawn path, not to delivery. (Untagged warm delivery from a non-owner, and untagged warm delivery with config rules disabled, are both untested on this install β€” I'm not claiming either.)

Net for this issue: on this install a cold wake requires owner sender AND a p-tag mention, and both conditions are evaluated in buzz-desktop upstream of the harness process. That makes it unfixable agent-side; it has to land in the spawn path, which matches the "#2674 + #2898 are each necessary, together sufficient" read from earlier comments.

Practical impact for anyone running a multi-agent setup: agent→agent coordination cannot start a session at all. Every cross-agent handoff has to be relayed by the human owner, and the only interim mitigation that holds is sweep-on-wake — on every wake, re-read channel history since last activity with generous overlap and process everything slept through.

ohadive avatar Aug 06 '26 15:08 ohadive

Cross-reference: I've opened #5396, which proposes an agent-writable lifecycle event kind (started / stopped / restarted / crashed) rendered as a system row in the channel.

It doesn't fix the delivery problem this issue is about β€” a mention aimed at a down agent would still be dropped β€” but it targets the part several people here describe as the worst symptom: that nobody can tell the agent is gone. Today an agent's death is local Desktop state plus owner-private encrypted telemetry, and presence loses its offline edge on a hard crash (connection.rs:291 clears the Redis key and publishes nothing).

@Bartok9 β€” I've cited your July sketch of a relay-emitted agent_mention_undelivered notice as the main alternative, since as far as I can tell it never landed (no occurrence in the tree). The relay-emitted route avoids the authorization question entirely and is a better fit for anything the relay can observe by itself; I'd defer to it for that half if you or the maintainers prefer that direction.

Berenger-Wooclap avatar Aug 09 '26 12:08 Berenger-Wooclap

@Berenger-Wooclap β€” the relay-emitted half you deferred is still #2296 (agent_mention_undelivered on explicit mention tags + presence). Just rebased onto current main and re-pushed.

RFC #5396 (agent-writable lifecycle) is complementary for start/stop/crash visibility; it doesn’t replace the offline-mention notice. Happy to keep iterating on #2296 with maintainers rather than folding lifecycle into that PR.

Bartok9 avatar Aug 09 '26 12:08 Bartok9

Related doc inconsistency + one more drop path.

  1. crates/buzz-acp/README.md:262 (at a8e1c66c4) says "On startup, the harness replays all unprocessed @mentions since the last run." But run() captures startup_watermark = now() before connecting (src/lib.rs:1992) and uses it as the initial subscribe_since for channels discovered at startup, so mentions sent while the harness was down are never delivered after restart. Either the note or the behavior should change (e.g. persist a per-channel last-processed watermark).

  2. When the agent returns a usage-limit error (Claude: "You've hit your session limit Β· resets 6:10pm"), the queue retries 10x with backoff (~25 min) then dead-letters the batch, although the reset time is known and may be hours away. Observed: dead-lettering batch after 10 retries β€” discarding 1 events.

Our workaround: periodic heartbeat prompt (BUZZ_ACP_HEARTBEAT_*) that re-reads the feed, plus an external supervisor that defers nudges until the reset time.

wonhoji avatar Oct 20 '26 08:10 wonhoji