File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments