fix: give agent-observer sub a replay-capable limit (#1100)

Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Will Pfleger
2026-06-17 19:21:39 -04:00
committed by GitHub
parent 4201311821
commit 959fc6e9d0
2 changed files with 37 additions and 1 deletions

View File

@@ -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();
});

View File

@@ -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,