buzz icon indicating copy to clipboard operation
buzz copied to clipboard

buzz-acp: after a *successful* reconnect the harness stops receiving mentions permanently, until the process is restarted

Open ElmsPark opened this issue 3 months ago • 3 comments

Summary

After buzz-acp logs autonomous reconnect succeeded and resubscribing to N channel(s) after reconnect, it can stop receiving events entirely and permanently — not only for the reconnect gap. Mentions published many minutes later, on a stable connection, produce zero log activity in the harness. The relay accepts them and p-tags them correctly. Only restarting the process restores delivery.

The agent looks completely healthy throughout: process running, presence online, subscriptions logged, no errors on either side.

This is not #4752. That issue covers mentions lost during the gap and states that "mentions published while the connection is stable are processed normally". Here the connection is stable for 14 minutes afterwards and delivery never resumes. The resubscribe appears to succeed while restoring nothing. They may share a root cause, but the observable behaviour and the impact differ: #4752 loses a bounded window, this loses everything until human intervention.

Environment

  • buzz-acp build dated 2026-08-01, self-hosted relay, closed-mode NIP-42
  • macOS 26.5.2, arm64, launchd-managed, --subscribe mentions
  • adapter: @zed-industries/claude-code-acp 0.16.2
  • reproduced on three agents across two machines and two OS accounts
  • 34 after reconnect events in one log — churn is routine, not exotic

Reproduction

  1. Leave a buzz-acp agent running until the relay connection drops and auto-reconnects (minutes to hours; ours averages several per hour).
  2. Publish a mention p-tagged to that agent, well after the reconnect completes.
  3. Observe: relay returns accepted:true with the correct mention_pubkeys; the harness logs nothing at all.
  4. Restart the harness. Publish the same mention. It is answered in seconds.

Observed

Harness log, one agent, unedited except for truncation:

22:15:06.483  WARN  buzz_acp::relay: relay connection lost — reconnecting…
22:15:06.664  INFO  buzz_acp::relay: autonomous reconnect succeeded (attempt 1)
22:15:06.664  INFO  buzz_acp: resubscribing to 8 channel(s) after reconnect
        ← 15 minutes with ZERO log lines, including across the mention below
22:30:46.141  INFO  buzz_acp: presence set to offline        (operator restart)
22:30:49.204  INFO  buzz_acp: buzz-acp starting: …
22:30:49.873  INFO  buzz_acp: subscribed to channel <8 channels>
22:30:49.873  INFO  buzz_acp: presence set to online

Controlled test either side of that restart — same channel, same sender, same message text, single variable:

time event result
22:29:26 mention published, accepted:true, correct mention_pubkeys no reply, zero log lines
22:30:49 harness restarted
22:30:59 identical mention published answered at 22:31:10

The relay side is fine: the same identity receives the events normally after restart, and a second agent on the same host was unaffected at that moment, so it is per-connection rather than relay-wide.

Expected

After resubscribing to N channel(s) after reconnect, live delivery should actually resume for those channels. If the resubscription cannot be confirmed, that should surface as an error rather than an INFO line reporting success.

Impact

This is worse than message loss because it is indefinite and invisible. There is no error, no retry, no queue entry, nothing in the log at all — a deaf agent is indistinguishable from an idle one. Concretely, for us:

  • An agent ran for 7 days appearing healthy and completed zero work.
  • In a structured multi-agent discussion, two of three participants silently stopped answering mid-session. A non-answer is not distinguishable from a considered decision not to speak, so the resulting record reported consensus that was never tested.
  • Monitoring based on process liveness and log errors reports everything green. The only reliable check we found is an end-to-end round trip: send the agent a token and require it back.

Suggestions

  • Verify the resubscription (await the relay's acknowledgement per channel) before logging success, and log a distinct error if it cannot be confirmed.
  • Treat "no events received since reconnect" as a health signal and self-heal, rather than trusting the socket's own state.
  • Failing both, expose a --reconnect-max-silence that recycles the connection after N seconds without inbound traffic — a blunt but effective backstop for the current behaviour.

ElmsPark avatar Aug 27 '26 11:08 ElmsPark

Update from the reporter, with a version correction and a workaround that may be useful to others hitting this.

Version correction

The original report was made against a build dated 2026-08-01, i.e. 0.5.4-era. I have since found that all three of my agents were running August binaries while 0.5.23 sat installed on another machine, so the report should be read as 0.5.4, not current. Worth knowing before anyone spends time on it.

All three are now on 0.5.23. It is too early to say whether the behaviour persists: deafness here surfaces over hours to days, and the upgrade is hours old. I will report back either way.

Workaround, for anyone blocked on this now

--exit-after-inactivity (new since my original build) makes the failure bounded rather than indefinite. Deafness can only begin at a reconnect, and the process is only ever fully deaf, so recycling an idle harness caps the damage:

export BUZZ_ACP_EXIT_AFTER_INACTIVITY=1800

with the process under a supervisor that restarts it (launchd KeepAlive here). The harness exits after 30 minutes with no dispatched events and no turn in flight, and comes back as a fresh process, which cannot be deaf. Worst case goes from indefinite to 30 minutes.

Verified rather than assumed, with the timer temporarily at 60s:

2026-09-16T07:09:12.657118Z  INFO buzz_acp: inactivity bound reached — exiting gracefully inactivity_seconds=60
2026-09-16T07:09:12.657439Z  INFO buzz_acp: shutdown: waiting for in-flight prompts
2026-09-16T07:09:12.700788Z  INFO buzz_acp: buzz-acp starting: relay=wss://buzz.elmspark.com ...

The waiting for in-flight prompts line is the part that makes it safe: it cannot interrupt a turn. Supervisor returned a new PID in under a second.

The cost is that a mention landing inside the restart gap is lost. Against an agent that ran seven days deaf, that is the better trade.

One code observation

In resubscribe_after_reconnect (crates/buzz-acp/src/relay.rs), send_subscribe returning true means the REQ was written to the socket, not that the relay honoured it. channel_dropped_since is cleared on that basis, and the success line is logged on that basis. If a REQ can be accepted at the socket and then not served, that would produce exactly what I observed: a confident resubscribing to N channel(s) after reconnect, no CLOSED, no error, and no events ever again.

That is a guess from reading the current source, not something I have instrumented.

ElmsPark avatar Sep 16 '26 07:09 ElmsPark

Additional reproduction data from a self-hosted relay on a dedicated VPS (4 buzz-acp agents, systemd-managed), matching the described "deaf after successful reconnect" symptom — plus one instrumented observation that may help narrow the root cause.

Our variant: the ping/pong accounting dies while the socket keeps sending heartbeats

Symptom identical to the OP: after autonomous reconnect succeeded + resubscribing to N channel(s), the harness logs nothing further, relay shows the connection established and NIP-42 authed, mentions accepted with correct p-tags, zero harness log activity. Restart fixes it.

What we could add: we strace'd the wedged harness (buzz-acp binary, 2026-10-22 build):

  • The process does write small TLS records (~28 bytes, 4/min cadence) to the relay socket fd — consistent with the 30s ping timer firing at the transport layer.
  • But the harness logs zero DEBUG buzz_acp::relay: sent ping to relay lines (a healthy sibling agent logs 100+ per hour), and no no pong received → reconnect cycle ever fires on its own — the ping ledger that drives both the log line and the pong-timeout appears dead in the same task that owns the read loop.
  • resubscribe_after_reconnect logs success, matching the OP's observation that send_subscribe returning true ≠ relay serving the subscription.

This suggests the wedge is not (only) the subscription write path, but the relay reader/bookkeeping task going inert after a successful reconnect — the socket still gets heartbeat writes from some other task, while whatever consumes inbound frames (and logs pings/publishes acks) stops. Worth checking whether the reconnect path swaps or shadows the read task and the old one is left holding the logs.

Timeline from one incident (UTC, 2026-10-22):

  • 06:14:09 fresh start, online, 3 channels subscribed — healthy log burst, then silence
  • 06:20:39 no pong received within 10s (the only self-detection we ever saw) → reconnect succeeded 06:20:46
  • 06:26 user message ingested by relay, harness: no log lines at all
  • restart required to recover; recurred ~6 times across the day on the same agent only

Workaround in production

BUZZ_ACP_EXIT_AFTER_INACTIVITY=300 + systemd Restart=always, as suggested above — confirmed working here too, bounds deafness to the inactivity window (graceful exit only with no in-flight turn; new process comes up healthy in <2s).

chipchipss avatar Oct 22 '26 08:10 chipchipss

Correction to my earlier comment: one of the two observations was an artifact of our own logging config, not the bug.

We had compared a healthy agent against the affected one by counting DEBUG buzz_acp::relay: sent ping to relay lines. But only the healthy agent's unit had RUST_LOG=info,buzz_acp::relay=debug,... set (a leftover debug drop-in); the affected agent had no RUST_LOG at all, so its ping lines were never emitted regardless of health. With logging equalized, the affected agent logs pings every 30s from a fresh start and the socket behaves normally.

Revised diagnosis for our incident: the recurring deafness we saw on 2026-10-22 was consistent with the other failure chain — mention events accepted by the relay landing in restart gaps and post-reconnect resubscribe windows (the #4752/#6935 family), amplified by an unrelated upstream model-routing outage that produced silent end_turn turns. The strace observation stands (28-byte TLS records at ping cadence on the socket fd while journal showed no ping lines), but its explanation is log-level filtering, not a dead ledger task.

Keeping BUZZ_ACP_EXIT_AFTER_INACTIVITY=300 + systemd restart as our production bound. Apologies for the noise — the log-level finding may still be useful for anyone else diffing two agents' journals as a health signal: normalize RUST_LOG first.

chipchipss avatar Oct 22 '26 09:10 chipchipss