From 959fc6e9d0a68ff4de1e3b4dc3d731fb8f0b3b03 Mon Sep 17 00:00:00 2001 From: Will Pfleger Date: Wed, 17 Jun 2026 19:21:39 -0400 Subject: [PATCH] fix: give agent-observer sub a replay-capable limit (#1100) Signed-off-by: Will Pfleger Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 --- desktop/src/shared/api/observerRelay.test.mjs | 32 +++++++++++++++++++ desktop/src/shared/api/observerRelay.ts | 6 +++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 desktop/src/shared/api/observerRelay.test.mjs diff --git a/desktop/src/shared/api/observerRelay.test.mjs b/desktop/src/shared/api/observerRelay.test.mjs new file mode 100644 index 0000000000..88da91ba47 --- /dev/null +++ b/desktop/src/shared/api/observerRelay.test.mjs @@ -0,0 +1,32 @@ +import assert from "node:assert/strict"; +import test, { mock } from "node:test"; + +import { relayClient } from "./relayClient.ts"; +import { subscribeToAgentObserverFrames } from "./observerRelay.ts"; + +// Regression guard: the observer subscription MUST request a replay-capable +// limit. With `limit: 0` the relay truncates reconnect replay to zero rows +// (NIP-01: limit 0 = no historical rows), so a turn_started missed during a +// network drop never re-delivers and the active-agents badge never appears. +test("subscribeToAgentObserverFrames requests a replay-capable limit with a since window", () => { + const calls = []; + mock.method(relayClient, "subscribeLive", (filter) => { + calls.push(filter); + return () => {}; + }); + + subscribeToAgentObserverFrames("owner-pubkey", () => {}); + + assert.equal(calls.length, 1); + assert.equal( + calls[0].limit, + 1000, + "observer sub must use limit:1000 so reconnect replay can recover missed frames — limit:0 drops the gap", + ); + assert.ok( + calls[0].since && calls[0].since > 0, + "observer sub must carry `since` so launch history stays suppressed — only the reconnect replay window is backfilled", + ); + + mock.reset(); +}); diff --git a/desktop/src/shared/api/observerRelay.ts b/desktop/src/shared/api/observerRelay.ts index c534db6c67..3bd46776a7 100644 --- a/desktop/src/shared/api/observerRelay.ts +++ b/desktop/src/shared/api/observerRelay.ts @@ -11,7 +11,11 @@ export function subscribeToAgentObserverFrames( { kinds: [KIND_AGENT_OBSERVER_FRAME], "#p": [ownerPubkey], - limit: 0, + // The high `limit` lets reconnect replay recover observer frames missed + // during a drop. `since` still suppresses launch-time history; only the + // reconnect replay window is backfilled. A `limit: 0` here would truncate + // that replay to zero rows, dropping the gap (NIP-01: limit 0 = no rows). + limit: 1000, since: Math.floor(Date.now() / 1_000), }, onEvent,