Files
ruv d61bf42022 perf(agentbbs): dedup PeerHello spam, dedup watch replays, O(1) seq append
Three optimizations to the ruflo-side AgentBBS federation integration
(ADR-164), all in v3/@claude-flow/cli/src/mcp-tools/agentbbs-tools.ts.

1. PeerHello dedup (register). `federation_bbs_register` appended a fresh
   PeerHello envelope on EVERY call even though the registry entry and nodeId
   were already idempotent — so a node retrying register N times emitted N
   near-identical hellos (observed live: one node published 8). Now a hello is
   emitted only for a genuinely new registration, or as a heartbeat refresh once
   FEDERATION_BBS_HELLO_WINDOW_SECS (default 60) has elapsed. Returns
   `helloEmitted` so the caller can see whether one was written (a silent
   suppression would otherwise be unverifiable).

2. Watch dedup. `federation_bbs_watch` now collapses duplicate envelopeIds
   before applying the limit, so a relay replay or a double-append cannot
   surface the same envelope twice to a watcher. Order preserved.

3. O(1) seq append. `nextSeq` re-parsed the whole room log on every
   publish/register (O(n) as the log grows). It now scans only the last 64 KiB
   to find the last seq, with a full-read fallback for the rare huge-line case.
   Monotonic seq (ADR-164 §3.2.2) is preserved and tested past the tail window.

Decision helpers (`shouldEmitHello`, `dedupEnvelopes`, `nextSeq`,
`lastPeerHelloMs`) are exported and unit-tested deterministically — the tool
handlers early-return `{degraded:true}` when the optional `agentbbs` package is
absent, so the pure logic is tested directly rather than through the wrapper.

Tests: 7 new cases; full file 15 passed / 4 skipped (the 4 are agentbbs-present
happy-path, skipped when the optional dep is absent). tsc --noEmit clean on the
changed file. Structural + degraded contract unchanged.

Scope: this is the ruflo-side integration only. Claim leases, signed result
receipts, and node reputation are agentbbs/relay-authority concerns (external
pkg + x.ruv.io gateway) — a separate track.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-09-09 22:11:58 -04:00
..
…