buzz icon indicating copy to clipboard operation
buzz copied to clipboard

feat(acp): catch up on @mentions that arrived while the harness was offline

Open rodroudi opened this issue 4 months ago • 0 comments

Summary

At startup — after channel subscriptions are established — the ACP harness now queries the relay for p-tag mentions of the agent that arrived while it was offline, and replays them through the normal event pipeline. Mentions sent to a stopped/restarting agent are no longer silently lost.

How the replay window is bounded (no double-processing): the since floor is the newer of

  1. one second after the agent's own most recent channel message — anything older than the agent's last sign of life may already have been answered, and is never replayed; and
  2. watermark - window as a hard cap (--mention-catchup-secs / BUZZ_ACP_MENTION_CATCHUP_SECS, default 6 h, 0 disables).

The ceiling is startup_watermark - 1: the live subscription REQ uses since = watermark (inclusive), so the catch-up range is disjoint from live delivery — no event can arrive through both paths, and a startup-window mention cannot steer/cancel the turn it triggered.

Replayed events are not special-cased. backfill_mentions parks them in a buffer that next_event() drains ahead of live traffic, so the author gate (respond_to policy), mention gate, and queue dedup apply to them exactly as to live events. A mention from a non-allowed author is still dropped, and the queue's existing dedup remains a second line of defense behind the disjoint bounds.

The query is scoped server-side to the subscribed channels' #h tags, so the result limit (100) cannot be exhausted by mentions from channels the harness does not serve. Client-side filtering is conservative on top of that: only kind:9 stream messages, authored by someone else, carrying a subscribed channel h tag and a p tag equal to the agent's pubkey; replayed oldest-first to preserve conversational order.

Related issue

Fixes #1743. Reproduces the incident in that thread: agent's host machine restarts, a member mentions the agent during the gap, agent comes back and the mention is gone. Complements #2893 (cross-owner mention visibility) — together they make "@mention any agent in the channel" reliable for multi-user workspaces.

Testing

  • Unit tests for the bounds computation (compute_backfill_bounds: disabled window, window cap, own-activity floor, watermark ceiling, empty-range) and for the event selection (select_backfill_events: drops own/foreign-target/unsubscribed-channel events, orders oldest-first).
  • Full buzz-acp suite: 603 pass / 0 fail. cargo clippy -p buzz-acp clean, cargo fmt applied.
  • Manual scenario: agent offline, member sends @agent hello, agent starts → catch-up queues the mention (offline-mention catch-up queued, count=1) and the agent answers it; second start replays nothing (floor moves past the agent's reply).

🤖 Generated with Claude Code

rodroudi avatar Jul 25 '26 21:07 rodroudi