Skip to content

Commit 959fc6e

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix: give agent-observer sub a replay-capable limit (#1100)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 4201311 commit 959fc6e

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import assert from "node:assert/strict";
2+
import test, { mock } from "node:test";
3+
4+
import { relayClient } from "./relayClient.ts";
5+
import { subscribeToAgentObserverFrames } from "./observerRelay.ts";
6+
7+
// Regression guard: the observer subscription MUST request a replay-capable
8+
// limit. With `limit: 0` the relay truncates reconnect replay to zero rows
9+
// (NIP-01: limit 0 = no historical rows), so a turn_started missed during a
10+
// network drop never re-delivers and the active-agents badge never appears.
11+
test("subscribeToAgentObserverFrames requests a replay-capable limit with a since window", () => {
12+
const calls = [];
13+
mock.method(relayClient, "subscribeLive", (filter) => {
14+
calls.push(filter);
15+
return () => {};
16+
});
17+
18+
subscribeToAgentObserverFrames("owner-pubkey", () => {});
19+
20+
assert.equal(calls.length, 1);
21+
assert.equal(
22+
calls[0].limit,
23+
1000,
24+
"observer sub must use limit:1000 so reconnect replay can recover missed frames — limit:0 drops the gap",
25+
);
26+
assert.ok(
27+
calls[0].since && calls[0].since > 0,
28+
"observer sub must carry `since` so launch history stays suppressed — only the reconnect replay window is backfilled",
29+
);
30+
31+
mock.reset();
32+
});

‎desktop/src/shared/api/observerRelay.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export function subscribeToAgentObserverFrames(
1111
{
1212
kinds: [KIND_AGENT_OBSERVER_FRAME],
1313
"#p": [ownerPubkey],
14-
limit: 0,
14+
// The high `limit` lets reconnect replay recover observer frames missed
15+
// during a drop. `since` still suppresses launch-time history; only the
16+
// reconnect replay window is backfilled. A `limit: 0` here would truncate
17+
// that replay to zero rows, dropping the gap (NIP-01: limit 0 = no rows).
18+
limit: 1000,
1519
since: Math.floor(Date.now() / 1_000),
1620
},
1721
onEvent,

0 commit comments

Comments
 (0)