@webex/plugin-meetings 3.12.0-next.1 → 3.12.0-next.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +15 -2
  3. package/dist/aiEnableRequest/index.js.map +1 -1
  4. package/dist/breakouts/breakout.js +8 -3
  5. package/dist/breakouts/breakout.js.map +1 -1
  6. package/dist/breakouts/index.js +26 -2
  7. package/dist/breakouts/index.js.map +1 -1
  8. package/dist/common/errors/webex-errors.js +49 -5
  9. package/dist/common/errors/webex-errors.js.map +1 -1
  10. package/dist/config.js +2 -2
  11. package/dist/config.js.map +1 -1
  12. package/dist/constants.js +35 -9
  13. package/dist/constants.js.map +1 -1
  14. package/dist/controls-options-manager/constants.js +11 -1
  15. package/dist/controls-options-manager/constants.js.map +1 -1
  16. package/dist/controls-options-manager/index.js +67 -29
  17. package/dist/controls-options-manager/index.js.map +1 -1
  18. package/dist/controls-options-manager/util.js +91 -0
  19. package/dist/controls-options-manager/util.js.map +1 -1
  20. package/dist/hashTree/constants.js +13 -1
  21. package/dist/hashTree/constants.js.map +1 -1
  22. package/dist/hashTree/hashTreeParser.js +898 -391
  23. package/dist/hashTree/hashTreeParser.js.map +1 -1
  24. package/dist/hashTree/utils.js +42 -0
  25. package/dist/hashTree/utils.js.map +1 -1
  26. package/dist/index.js +7 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/interceptors/dataChannelAuthToken.js +75 -15
  29. package/dist/interceptors/dataChannelAuthToken.js.map +1 -1
  30. package/dist/interceptors/locusRetry.js +23 -8
  31. package/dist/interceptors/locusRetry.js.map +1 -1
  32. package/dist/interpretation/index.js +10 -1
  33. package/dist/interpretation/index.js.map +1 -1
  34. package/dist/interpretation/interpretation.types.js +7 -0
  35. package/dist/interpretation/interpretation.types.js.map +1 -0
  36. package/dist/interpretation/siLanguage.js +1 -1
  37. package/dist/locus-info/controlsUtils.js +4 -1
  38. package/dist/locus-info/controlsUtils.js.map +1 -1
  39. package/dist/locus-info/index.js +401 -115
  40. package/dist/locus-info/index.js.map +1 -1
  41. package/dist/locus-info/infoUtils.js +36 -5
  42. package/dist/locus-info/infoUtils.js.map +1 -1
  43. package/dist/locus-info/types.js +19 -0
  44. package/dist/locus-info/types.js.map +1 -1
  45. package/dist/media/MediaConnectionAwaiter.js +15 -2
  46. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  47. package/dist/media/index.js +8 -2
  48. package/dist/media/index.js.map +1 -1
  49. package/dist/media/properties.js +1 -0
  50. package/dist/media/properties.js.map +1 -1
  51. package/dist/meeting/in-meeting-actions.js +5 -1
  52. package/dist/meeting/in-meeting-actions.js.map +1 -1
  53. package/dist/meeting/index.js +1444 -772
  54. package/dist/meeting/index.js.map +1 -1
  55. package/dist/meeting/locusMediaRequest.js +229 -82
  56. package/dist/meeting/locusMediaRequest.js.map +1 -1
  57. package/dist/meeting/muteState.js +10 -1
  58. package/dist/meeting/muteState.js.map +1 -1
  59. package/dist/meeting/request.js +5 -2
  60. package/dist/meeting/request.js.map +1 -1
  61. package/dist/meeting/util.js +35 -2
  62. package/dist/meeting/util.js.map +1 -1
  63. package/dist/meeting-info/meeting-info-v2.js +2 -2
  64. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  65. package/dist/meetings/index.js +231 -118
  66. package/dist/meetings/index.js.map +1 -1
  67. package/dist/meetings/meetings.types.js +6 -1
  68. package/dist/meetings/meetings.types.js.map +1 -1
  69. package/dist/meetings/request.js +39 -0
  70. package/dist/meetings/request.js.map +1 -1
  71. package/dist/meetings/util.js +116 -18
  72. package/dist/meetings/util.js.map +1 -1
  73. package/dist/member/index.js +10 -0
  74. package/dist/member/index.js.map +1 -1
  75. package/dist/member/types.js.map +1 -1
  76. package/dist/member/util.js +30 -0
  77. package/dist/member/util.js.map +1 -1
  78. package/dist/members/index.js +101 -43
  79. package/dist/members/index.js.map +1 -1
  80. package/dist/members/util.js +8 -1
  81. package/dist/members/util.js.map +1 -1
  82. package/dist/metrics/constants.js +10 -1
  83. package/dist/metrics/constants.js.map +1 -1
  84. package/dist/multistream/codec/constants.js +63 -0
  85. package/dist/multistream/codec/constants.js.map +1 -0
  86. package/dist/multistream/mediaRequestManager.js +62 -15
  87. package/dist/multistream/mediaRequestManager.js.map +1 -1
  88. package/dist/multistream/receiveSlot.js +9 -0
  89. package/dist/multistream/receiveSlot.js.map +1 -1
  90. package/dist/multistream/sendSlotManager.js +116 -2
  91. package/dist/multistream/sendSlotManager.js.map +1 -1
  92. package/dist/reachability/clusterReachability.js.map +1 -1
  93. package/dist/reachability/index.js +121 -83
  94. package/dist/reachability/index.js.map +1 -1
  95. package/dist/reachability/reachability.types.js +2 -0
  96. package/dist/reachability/reachability.types.js.map +1 -1
  97. package/dist/reachability/util.js +45 -0
  98. package/dist/reachability/util.js.map +1 -1
  99. package/dist/reactions/reactions.type.js.map +1 -1
  100. package/dist/recording-controller/index.js +1 -3
  101. package/dist/recording-controller/index.js.map +1 -1
  102. package/dist/roap/turnDiscovery.js +8 -1
  103. package/dist/roap/turnDiscovery.js.map +1 -1
  104. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  105. package/dist/types/config.d.ts +2 -2
  106. package/dist/types/constants.d.ts +12 -1
  107. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  108. package/dist/types/controls-options-manager/index.d.ts +16 -0
  109. package/dist/types/hashTree/constants.d.ts +2 -0
  110. package/dist/types/hashTree/hashTreeParser.d.ts +146 -17
  111. package/dist/types/hashTree/utils.d.ts +18 -0
  112. package/dist/types/index.d.ts +3 -0
  113. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  114. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  115. package/dist/types/locus-info/index.d.ts +59 -6
  116. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  117. package/dist/types/locus-info/types.d.ts +21 -1
  118. package/dist/types/media/MediaConnectionAwaiter.d.ts +10 -1
  119. package/dist/types/media/properties.d.ts +1 -0
  120. package/dist/types/meeting/in-meeting-actions.d.ts +4 -0
  121. package/dist/types/meeting/index.d.ts +143 -9
  122. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  123. package/dist/types/meeting/request.d.ts +1 -0
  124. package/dist/types/meeting/util.d.ts +9 -0
  125. package/dist/types/meetings/index.d.ts +30 -18
  126. package/dist/types/meetings/meetings.types.d.ts +15 -0
  127. package/dist/types/meetings/request.d.ts +14 -0
  128. package/dist/types/member/index.d.ts +1 -0
  129. package/dist/types/member/types.d.ts +1 -0
  130. package/dist/types/member/util.d.ts +9 -0
  131. package/dist/types/members/index.d.ts +15 -2
  132. package/dist/types/members/util.d.ts +1 -5
  133. package/dist/types/metrics/constants.d.ts +9 -0
  134. package/dist/types/multistream/codec/constants.d.ts +7 -0
  135. package/dist/types/multistream/mediaRequestManager.d.ts +22 -5
  136. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  137. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  138. package/dist/types/reachability/index.d.ts +10 -3
  139. package/dist/types/reachability/reachability.types.d.ts +7 -0
  140. package/dist/types/reachability/util.d.ts +17 -0
  141. package/dist/types/reactions/reactions.type.d.ts +3 -0
  142. package/dist/webinar/index.js +485 -234
  143. package/dist/webinar/index.js.map +1 -1
  144. package/package.json +22 -22
  145. package/src/aiEnableRequest/index.ts +16 -0
  146. package/src/breakouts/breakout.ts +3 -1
  147. package/src/breakouts/index.ts +31 -0
  148. package/src/common/errors/webex-errors.ts +50 -3
  149. package/src/config.ts +2 -2
  150. package/src/constants.ts +20 -3
  151. package/src/controls-options-manager/constants.ts +14 -1
  152. package/src/controls-options-manager/index.ts +87 -28
  153. package/src/controls-options-manager/util.ts +81 -1
  154. package/src/hashTree/constants.ts +16 -0
  155. package/src/hashTree/hashTreeParser.ts +596 -204
  156. package/src/hashTree/utils.ts +36 -0
  157. package/src/index.ts +6 -0
  158. package/src/interceptors/dataChannelAuthToken.ts +88 -12
  159. package/src/interceptors/locusRetry.ts +25 -4
  160. package/src/interpretation/index.ts +27 -9
  161. package/src/interpretation/interpretation.types.ts +11 -0
  162. package/src/locus-info/controlsUtils.ts +3 -1
  163. package/src/locus-info/index.ts +415 -136
  164. package/src/locus-info/infoUtils.ts +41 -6
  165. package/src/locus-info/types.ts +25 -1
  166. package/src/media/MediaConnectionAwaiter.ts +21 -4
  167. package/src/media/index.ts +10 -1
  168. package/src/media/properties.ts +1 -0
  169. package/src/meeting/in-meeting-actions.ts +8 -0
  170. package/src/meeting/index.ts +790 -136
  171. package/src/meeting/locusMediaRequest.ts +106 -6
  172. package/src/meeting/muteState.ts +10 -1
  173. package/src/meeting/request.ts +11 -0
  174. package/src/meeting/util.ts +47 -5
  175. package/src/meeting-info/meeting-info-v2.ts +4 -2
  176. package/src/meetings/index.ts +133 -78
  177. package/src/meetings/meetings.types.ts +19 -0
  178. package/src/meetings/request.ts +43 -0
  179. package/src/meetings/util.ts +117 -4
  180. package/src/member/index.ts +10 -0
  181. package/src/member/types.ts +1 -0
  182. package/src/member/util.ts +29 -0
  183. package/src/members/index.ts +70 -7
  184. package/src/members/util.ts +12 -4
  185. package/src/metrics/constants.ts +10 -0
  186. package/src/multistream/codec/constants.ts +58 -0
  187. package/src/multistream/mediaRequestManager.ts +119 -28
  188. package/src/multistream/receiveSlot.ts +18 -0
  189. package/src/multistream/sendSlotManager.ts +97 -3
  190. package/src/reachability/clusterReachability.ts +3 -2
  191. package/src/reachability/index.ts +47 -16
  192. package/src/reachability/reachability.types.ts +11 -0
  193. package/src/reachability/util.ts +36 -0
  194. package/src/reactions/reactions.type.ts +3 -0
  195. package/src/recording-controller/index.ts +1 -2
  196. package/src/roap/turnDiscovery.ts +9 -1
  197. package/src/webinar/index.ts +330 -50
  198. package/test/unit/spec/aiEnableRequest/index.ts +86 -0
  199. package/test/unit/spec/breakouts/breakout.ts +9 -3
  200. package/test/unit/spec/breakouts/index.ts +49 -0
  201. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  202. package/test/unit/spec/controls-options-manager/index.js +244 -29
  203. package/test/unit/spec/controls-options-manager/util.js +165 -0
  204. package/test/unit/spec/hashTree/hashTreeParser.ts +1911 -143
  205. package/test/unit/spec/hashTree/utils.ts +125 -1
  206. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +196 -0
  207. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  208. package/test/unit/spec/interpretation/index.ts +26 -4
  209. package/test/unit/spec/locus-info/controlsUtils.js +172 -57
  210. package/test/unit/spec/locus-info/index.js +645 -80
  211. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  212. package/test/unit/spec/media/MediaConnectionAwaiter.ts +55 -0
  213. package/test/unit/spec/media/index.ts +92 -0
  214. package/test/unit/spec/meeting/in-meeting-actions.ts +4 -0
  215. package/test/unit/spec/meeting/index.js +2261 -109
  216. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  217. package/test/unit/spec/meeting/muteState.js +81 -0
  218. package/test/unit/spec/meeting/request.js +12 -0
  219. package/test/unit/spec/meeting/utils.js +157 -1
  220. package/test/unit/spec/meeting-info/meetinginfov2.js +19 -10
  221. package/test/unit/spec/meetings/index.js +366 -39
  222. package/test/unit/spec/meetings/request.js +141 -0
  223. package/test/unit/spec/meetings/utils.js +402 -51
  224. package/test/unit/spec/member/index.js +7 -0
  225. package/test/unit/spec/member/util.js +89 -0
  226. package/test/unit/spec/members/index.js +216 -0
  227. package/test/unit/spec/members/request.js +37 -1
  228. package/test/unit/spec/members/utils.js +63 -0
  229. package/test/unit/spec/multistream/mediaRequestManager.ts +501 -37
  230. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  231. package/test/unit/spec/reachability/index.ts +128 -46
  232. package/test/unit/spec/reachability/util.ts +31 -0
  233. package/test/unit/spec/recording-controller/index.js +9 -8
  234. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  235. package/test/unit/spec/webinar/index.ts +516 -30
@@ -1,11 +1,19 @@
1
1
  import {cloneDeep, isEmpty, zip} from 'lodash';
2
2
  import HashTree, {LeafDataItem} from './hashTree';
3
3
  import LoggerProxy from '../common/logs/logger-proxy';
4
+ import Metrics from '../metrics';
5
+ import BEHAVIORAL_METRICS from '../metrics/constants';
4
6
  import {Enum, HTTP_VERBS} from '../constants';
5
- import {DataSetNames, EMPTY_HASH} from './constants';
7
+ import {DataSetNames, DATA_SET_INIT_PRIORITY, EMPTY_HASH, LLM_DATASET_NAMES} from './constants';
6
8
  import {ObjectType, HtMeta, HashTreeObject} from './types';
7
- import {LocusDTO} from '../locus-info/types';
8
- import {deleteNestedObjectsWithHtMeta, isMetadata} from './utils';
9
+ import {LocusDTO, LocusErrorCodes} from '../locus-info/types';
10
+ import {deleteNestedObjectsWithHtMeta, isMetadata, sleep, sortByInitPriority} from './utils';
11
+
12
+ export enum SyncAllBackoffType {
13
+ NONE = 'none',
14
+ ONLY_LLM = 'onlyLLM',
15
+ ALL = 'all',
16
+ }
9
17
 
10
18
  export interface DataSet {
11
19
  url: string;
@@ -18,10 +26,12 @@ export interface DataSet {
18
26
  maxMs: number;
19
27
  exponent: number;
20
28
  };
29
+ heartbeatIntervalMs?: number;
21
30
  }
22
31
 
23
32
  export interface RootHashMessage {
24
33
  dataSets: Array<DataSet>;
34
+ heartbeatIntervalMs?: number;
25
35
  }
26
36
  export interface HashTreeMessage {
27
37
  dataSets: Array<DataSet>;
@@ -47,6 +57,7 @@ interface InternalDataSet extends DataSet {
47
57
  hashTree?: HashTree; // set only for visible data sets
48
58
  timer?: ReturnType<typeof setTimeout>;
49
59
  heartbeatWatchdogTimer?: ReturnType<typeof setTimeout>;
60
+ syncAbortController?: AbortController;
50
61
  }
51
62
 
52
63
  type WebexRequestMethod = (options: Record<string, any>) => Promise<any>;
@@ -54,13 +65,24 @@ type WebexRequestMethod = (options: Record<string, any>) => Promise<any>;
54
65
  export const LocusInfoUpdateType = {
55
66
  OBJECTS_UPDATED: 'OBJECTS_UPDATED',
56
67
  MEETING_ENDED: 'MEETING_ENDED',
68
+ LOCUS_NOT_FOUND: 'LOCUS_NOT_FOUND',
57
69
  } as const;
58
70
 
59
71
  export type LocusInfoUpdateType = Enum<typeof LocusInfoUpdateType>;
60
- export type LocusInfoUpdateCallback = (
61
- updateType: LocusInfoUpdateType,
62
- data?: {updatedObjects: HashTreeObject[]}
63
- ) => void;
72
+
73
+ interface LocusUpdatePayloads {
74
+ [LocusInfoUpdateType.OBJECTS_UPDATED]: {updatedObjects: HashTreeObject[]};
75
+ [LocusInfoUpdateType.MEETING_ENDED]: unknown; // No extra data
76
+ [LocusInfoUpdateType.LOCUS_NOT_FOUND]: unknown; // No extra data
77
+ }
78
+
79
+ export type LocusInfoUpdate = {
80
+ [K in keyof LocusUpdatePayloads]: {
81
+ updateType: K;
82
+ } & LocusUpdatePayloads[K];
83
+ }[keyof LocusUpdatePayloads];
84
+
85
+ export type LocusInfoUpdateCallback = (update: LocusInfoUpdate) => void;
64
86
 
65
87
  interface LeafInfo {
66
88
  type: ObjectType;
@@ -75,6 +97,13 @@ interface LeafInfo {
75
97
  */
76
98
  export class MeetingEndedError extends Error {}
77
99
 
100
+ /**
101
+ * This error is thrown when a 404 is received from Locus hash tree endpoints, indicating that the locus URL
102
+ * is no longer valid (e.g. participant moved to a breakout room, or meeting ended).
103
+ * It's handled internally by HashTreeParser and results in LOCUS_NOT_FOUND being sent up.
104
+ */
105
+ export class LocusNotFoundError extends Error {}
106
+
78
107
  /* Currently Locus always sends Metadata objects only in the "self" dataset.
79
108
  * If this ever changes, update all the code that relies on this constant.
80
109
  */
@@ -96,9 +125,17 @@ class HashTreeParser {
96
125
  locusInfoUpdateCallback: LocusInfoUpdateCallback;
97
126
  visibleDataSets: VisibleDataSetInfo[];
98
127
  debugId: string;
99
- heartbeatIntervalMs?: number;
100
128
  private excludedDataSets: string[];
101
129
  state: 'active' | 'stopped';
130
+ private syncQueue: Array<{dataSetName: string; reason: string; isInitialization?: boolean}> = [];
131
+ private isSyncInProgress = false;
132
+ // tracks whether syncAllDatasets is currently in its backoff delay phase and with what scope
133
+ private syncAllBackoffType: SyncAllBackoffType = SyncAllBackoffType.NONE;
134
+ // datasets that received messages during the syncAllDatasets backoff sleep and should be skipped
135
+ private dataSetsSyncedDuringBackoff: Set<string> = new Set();
136
+ private syncQueueProcessingPromise: Promise<void> = Promise.resolve();
137
+ // top-level heartbeat interval from the most recent message, used as fallback when dataset-level value is missing
138
+ private topLevelHeartbeatIntervalMs?: number;
102
139
 
103
140
  /**
104
141
  * Constructor for HashTreeParser
@@ -224,16 +261,16 @@ class HashTreeParser {
224
261
  * @param {DataSet} dataSetInfo The new data set to be added
225
262
  * @returns {Promise}
226
263
  */
227
- private initializeNewVisibleDataSet(
264
+ private async initializeNewVisibleDataSet(
228
265
  visibleDataSetInfo: VisibleDataSetInfo,
229
266
  dataSetInfo: DataSet
230
- ): Promise<{updateType: LocusInfoUpdateType; updatedObjects?: HashTreeObject[]}> {
267
+ ): Promise<void> {
231
268
  if (this.isVisibleDataSet(dataSetInfo.name)) {
232
269
  LoggerProxy.logger.info(
233
270
  `HashTreeParser#initializeNewVisibleDataSet --> ${this.debugId} Data set "${dataSetInfo.name}" already exists, skipping init`
234
271
  );
235
272
 
236
- return Promise.resolve({updateType: LocusInfoUpdateType.OBJECTS_UPDATED, updatedObjects: []});
273
+ return;
237
274
  }
238
275
 
239
276
  LoggerProxy.logger.info(
@@ -241,7 +278,7 @@ class HashTreeParser {
241
278
  );
242
279
 
243
280
  if (!this.addToVisibleDataSetsList(visibleDataSetInfo)) {
244
- return Promise.resolve({updateType: LocusInfoUpdateType.OBJECTS_UPDATED, updatedObjects: []});
281
+ return;
245
282
  }
246
283
 
247
284
  const hashTree = new HashTree([], dataSetInfo.leafCount);
@@ -251,51 +288,8 @@ class HashTreeParser {
251
288
  hashTree,
252
289
  };
253
290
 
254
- return this.sendInitializationSyncRequestToLocus(dataSetInfo.name, 'new visible data set');
255
- }
256
-
257
- /**
258
- * Sends a special sync request to Locus with all leaves empty - this is a way to get all the data for a given dataset.
259
- *
260
- * @param {string} datasetName - name of the dataset for which to send the request
261
- * @param {string} debugText - text to include in logs
262
- * @returns {Promise}
263
- */
264
- private sendInitializationSyncRequestToLocus(
265
- datasetName: string,
266
- debugText: string
267
- ): Promise<{updateType: LocusInfoUpdateType; updatedObjects?: HashTreeObject[]}> {
268
- const dataset = this.dataSets[datasetName];
269
-
270
- if (!dataset) {
271
- LoggerProxy.logger.warn(
272
- `HashTreeParser#sendInitializationSyncRequestToLocus --> ${this.debugId} No data set found for ${datasetName}, cannot send the request for leaf data`
273
- );
274
-
275
- return Promise.resolve(null);
276
- }
277
-
278
- const emptyLeavesData = new Array(dataset.leafCount).fill([]);
279
-
280
- LoggerProxy.logger.info(
281
- `HashTreeParser#sendInitializationSyncRequestToLocus --> ${this.debugId} Sending initial sync request to Locus for data set "${datasetName}" with empty leaf data`
282
- );
283
-
284
- return this.sendSyncRequestToLocus(this.dataSets[datasetName], emptyLeavesData).then(
285
- (syncResponse) => {
286
- if (syncResponse) {
287
- return {
288
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
289
- updatedObjects: this.parseMessage(
290
- syncResponse,
291
- `via empty leaves /sync API call for ${debugText}`
292
- ),
293
- };
294
- }
295
-
296
- return {updateType: LocusInfoUpdateType.OBJECTS_UPDATED, updatedObjects: []};
297
- }
298
- );
291
+ this.enqueueSyncForDataset(dataSetInfo.name, 'new visible data set initialization', true);
292
+ await this.syncQueueProcessingPromise;
299
293
  }
300
294
 
301
295
  /**
@@ -382,9 +376,8 @@ class HashTreeParser {
382
376
  if (this.state === 'stopped') {
383
377
  return;
384
378
  }
385
- const updatedObjects: HashTreeObject[] = [];
386
379
 
387
- for (const dataSet of visibleDataSets) {
380
+ for (const dataSet of sortByInitPriority(visibleDataSets, DATA_SET_INIT_PRIORITY)) {
388
381
  const {name, leafCount, url} = dataSet;
389
382
 
390
383
  if (!this.dataSets[name]) {
@@ -420,19 +413,12 @@ class HashTreeParser {
420
413
  );
421
414
  this.dataSets[name].hashTree = new HashTree([], leafCount);
422
415
 
423
- // eslint-disable-next-line no-await-in-loop
424
- const data = await this.sendInitializationSyncRequestToLocus(name, debugText);
425
-
426
- if (data.updateType === LocusInfoUpdateType.OBJECTS_UPDATED) {
427
- updatedObjects.push(...(data.updatedObjects || []));
428
- }
416
+ this.enqueueSyncForDataset(name, `initialization sync for ${debugText}`, true);
429
417
  }
430
418
  }
431
419
 
432
- this.callLocusInfoUpdateCallback({
433
- updateType: LocusInfoUpdateType.OBJECTS_UPDATED,
434
- updatedObjects,
435
- });
420
+ // wait for all enqueued initialization syncs to complete
421
+ await this.syncQueueProcessingPromise;
436
422
  }
437
423
 
438
424
  /**
@@ -450,7 +436,7 @@ class HashTreeParser {
450
436
  // object mapping dataset names to arrays of leaf data
451
437
  const leafInfo: Record<string, Array<LeafInfo>> = {};
452
438
 
453
- const findAndStoreMetaData = (currentLocusPart: any) => {
439
+ const findAndStoreMetaData = (currentLocusPart: any, currentLocusPartName: string) => {
454
440
  if (typeof currentLocusPart !== 'object' || currentLocusPart === null) {
455
441
  return;
456
442
  }
@@ -465,10 +451,18 @@ class HashTreeParser {
465
451
  };
466
452
 
467
453
  if (copyData) {
468
- newLeafInfo.data = cloneDeep(currentLocusPart);
454
+ if ((type as string).toLowerCase() === ObjectType.control) {
455
+ // control entries require special handling, because they are signalled by Locus
456
+ // differently when coming in messages vs API responses
457
+ newLeafInfo.data = {
458
+ [currentLocusPartName]: cloneDeep(currentLocusPart),
459
+ };
460
+ } else {
461
+ newLeafInfo.data = cloneDeep(currentLocusPart);
469
462
 
470
- // remove any nested other objects that have their own htMeta
471
- deleteNestedObjectsWithHtMeta(newLeafInfo.data);
463
+ // remove any nested other objects that have their own htMeta
464
+ deleteNestedObjectsWithHtMeta(newLeafInfo.data);
465
+ }
472
466
  }
473
467
 
474
468
  for (const dataSetName of dataSetNames) {
@@ -480,19 +474,19 @@ class HashTreeParser {
480
474
  }
481
475
 
482
476
  if (Array.isArray(currentLocusPart)) {
483
- for (const item of currentLocusPart) {
484
- findAndStoreMetaData(item);
477
+ for (const [index, item] of currentLocusPart.entries()) {
478
+ findAndStoreMetaData(item, index.toString());
485
479
  }
486
480
  } else {
487
481
  for (const key of Object.keys(currentLocusPart)) {
488
482
  if (Object.prototype.hasOwnProperty.call(currentLocusPart, key)) {
489
- findAndStoreMetaData(currentLocusPart[key]);
483
+ findAndStoreMetaData(currentLocusPart[key], key);
490
484
  }
491
485
  }
492
486
  }
493
487
  };
494
488
 
495
- findAndStoreMetaData(locus);
489
+ findAndStoreMetaData(locus, 'locus');
496
490
 
497
491
  return leafInfo;
498
492
  }
@@ -578,12 +572,40 @@ class HashTreeParser {
578
572
  )}`
579
573
  );
580
574
 
575
+ this.cancelPendingSyncsForDataSets(dataSets.map((ds) => ds.name));
576
+
581
577
  dataSets.forEach((dataSet) => {
582
578
  this.updateDataSetInfo(dataSet);
583
579
  this.runSyncAlgorithm(dataSet);
584
580
  });
585
581
  }
586
582
 
583
+ /**
584
+ * Handles known errors that can happen during syncs
585
+ *
586
+ * @param {any} error - The error to handle
587
+ * @returns {boolean} true if the error was recognized and handled, false otherwise
588
+ */
589
+ private handleSyncErrors(error: any) {
590
+ if (error instanceof MeetingEndedError) {
591
+ this.callLocusInfoUpdateCallback({
592
+ updateType: LocusInfoUpdateType.MEETING_ENDED,
593
+ });
594
+
595
+ return true;
596
+ }
597
+ if (error instanceof LocusNotFoundError) {
598
+ this.callLocusInfoUpdateCallback({
599
+ updateType: LocusInfoUpdateType.LOCUS_NOT_FOUND,
600
+ });
601
+ this.stop();
602
+
603
+ return true;
604
+ }
605
+
606
+ return false;
607
+ }
608
+
587
609
  /**
588
610
  * Asynchronously initializes new visible data sets
589
611
  *
@@ -600,11 +622,7 @@ class HashTreeParser {
600
622
  );
601
623
  queueMicrotask(() => {
602
624
  this.initializeNewVisibleDataSets(dataSetsRequiringInitialization).catch((error) => {
603
- if (error instanceof MeetingEndedError) {
604
- this.callLocusInfoUpdateCallback({
605
- updateType: LocusInfoUpdateType.MEETING_ENDED,
606
- });
607
- } else {
625
+ if (!this.handleSyncErrors(error)) {
608
626
  LoggerProxy.logger.warn(
609
627
  `HashTreeParser#queueInitForNewVisibleDataSets --> ${
610
628
  this.debugId
@@ -682,7 +700,14 @@ class HashTreeParser {
682
700
 
683
701
  const {dataSets, locus, metadata} = update;
684
702
 
703
+ LoggerProxy.logger.info(
704
+ `HashTreeParser#handleLocusUpdate --> ${this.debugId} received update with dataSets=${dataSets
705
+ ?.map((ds) => ds.name)
706
+ .join(',')} metadata=${metadata ? 'yes' : 'no'}`
707
+ );
708
+
685
709
  if (!dataSets) {
710
+ // this happens for example when we handle GET /loci response
686
711
  LoggerProxy.logger.info(
687
712
  `HashTreeParser#handleLocusUpdate --> ${this.debugId} received hash tree update without dataSets`
688
713
  );
@@ -780,12 +805,25 @@ class HashTreeParser {
780
805
  maxMs: receivedDataSet.backoff.maxMs,
781
806
  exponent: receivedDataSet.backoff.exponent,
782
807
  };
808
+ this.dataSets[receivedDataSet.name].heartbeatIntervalMs = receivedDataSet.heartbeatIntervalMs;
783
809
  LoggerProxy.logger.info(
784
810
  `HashTreeParser#updateDataSetInfo --> ${this.debugId} updated "${receivedDataSet.name}" dataset to version=${receivedDataSet.version}, root=${receivedDataSet.root}`
785
811
  );
786
812
  }
787
813
  }
788
814
 
815
+ /**
816
+ * Updates the leaf count for a data set, resizing its hash tree accordingly.
817
+ *
818
+ * @param {InternalDataSet} dataSet - The data set to update
819
+ * @param {number} newLeafCount - The new leaf count
820
+ * @returns {void}
821
+ */
822
+ private updateDataSetLeafCount(dataSet: InternalDataSet, newLeafCount: number): void {
823
+ dataSet.hashTree?.resize(newLeafCount);
824
+ dataSet.leafCount = newLeafCount;
825
+ }
826
+
789
827
  /**
790
828
  * Checks for changes in the visible data sets based on the updated objects.
791
829
  * @param {HashTreeObject[]} updatedObjects - The list of updated hash tree objects.
@@ -836,6 +874,8 @@ class HashTreeParser {
836
874
  */
837
875
  private deleteHashTree(dataSetName: string) {
838
876
  this.dataSets[dataSetName].hashTree = undefined;
877
+ this.dataSets[dataSetName].syncAbortController?.abort();
878
+ this.dataSets[dataSetName].syncAbortController = undefined;
839
879
 
840
880
  // we also need to stop the timers as there is no hash tree anymore to sync
841
881
  if (this.dataSets[dataSetName].timer) {
@@ -952,7 +992,7 @@ class HashTreeParser {
952
992
  }
953
993
  const allDataSets = await this.getAllVisibleDataSetsFromLocus();
954
994
 
955
- for (const ds of addedDataSets) {
995
+ for (const ds of sortByInitPriority(addedDataSets, DATA_SET_INIT_PRIORITY)) {
956
996
  const dataSetInfo = allDataSets.find((d) => d.name === ds.name);
957
997
 
958
998
  LoggerProxy.logger.info(
@@ -964,12 +1004,8 @@ class HashTreeParser {
964
1004
  `HashTreeParser#initializeNewVisibleDataSets --> ${this.debugId} missing info about data set "${ds.name}" in Locus response from visibleDataSetsUrl`
965
1005
  );
966
1006
  } else {
967
- // we're awaiting in a loop, because in practice there will be only one new data set at a time,
968
- // so no point in trying to parallelize this
969
1007
  // eslint-disable-next-line no-await-in-loop
970
- const updates = await this.initializeNewVisibleDataSet(ds, dataSetInfo);
971
-
972
- this.callLocusInfoUpdateCallback(updates);
1008
+ await this.initializeNewVisibleDataSet(ds, dataSetInfo);
973
1009
  }
974
1010
  }
975
1011
  }
@@ -989,25 +1025,39 @@ class HashTreeParser {
989
1025
  const {dataSets, visibleDataSetsUrl} = message;
990
1026
 
991
1027
  LoggerProxy.logger.info(
992
- `HashTreeParser#parseMessage --> ${this.debugId} received message ${debugText || ''}:`,
993
- message
1028
+ `HashTreeParser#parseMessage --> ${this.debugId} ${
1029
+ debugText || ''
1030
+ } dataSets: ${message.dataSets
1031
+ ?.map(({name, version}) => `${name}:${version}`)
1032
+ .join(',')}, elements: ${message.locusStateElements
1033
+ ?.map(
1034
+ (el) =>
1035
+ `${el.htMeta.elementId.type}:${el.htMeta.elementId.id}:${el.htMeta.elementId.version}${
1036
+ el.data ? '+' : '-'
1037
+ }`
1038
+ )
1039
+ .join(',')}`
994
1040
  );
1041
+
995
1042
  if (message.locusStateElements?.length === 0) {
996
1043
  LoggerProxy.logger.warn(
997
1044
  `HashTreeParser#parseMessage --> ${this.debugId} got empty locusStateElements!!!`
998
1045
  );
999
- // todo: send a metric
1046
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_EMPTY_LOCUS_STATE_ELEMENTS, {
1047
+ debugId: this.debugId,
1048
+ });
1000
1049
  }
1001
1050
 
1002
1051
  // first, update our metadata about the datasets with info from the message
1003
1052
  this.visibleDataSetsUrl = visibleDataSetsUrl;
1004
1053
  dataSets.forEach((dataSet) => this.updateDataSetInfo(dataSet));
1054
+ this.cancelPendingSyncsForDataSets(dataSets.map((ds) => ds.name));
1005
1055
 
1006
1056
  const updatedObjects: HashTreeObject[] = [];
1007
1057
 
1008
1058
  // when we detect new visible datasets, it may be that the metadata about them is not
1009
1059
  // available in the message, they will require separate async initialization
1010
- let dataSetsRequiringInitialization = [];
1060
+ let dataSetsRequiringInitialization: VisibleDataSetInfo[] = [];
1011
1061
 
1012
1062
  // first find out if there are any visible data set changes - they're signalled in Metadata object updates
1013
1063
  const metadataUpdates = (message.locusStateElements || []).filter((object) =>
@@ -1015,7 +1065,7 @@ class HashTreeParser {
1015
1065
  );
1016
1066
 
1017
1067
  if (metadataUpdates.length > 0) {
1018
- const updatedMetadataObjects = [];
1068
+ const updatedMetadataObjects: HashTreeObject[] = [];
1019
1069
 
1020
1070
  metadataUpdates.forEach((object) => {
1021
1071
  // todo: once Locus supports it, we will use the "view" field here instead of dataSetNames
@@ -1044,7 +1094,7 @@ class HashTreeParser {
1044
1094
  }
1045
1095
  }
1046
1096
 
1047
- if (message.locusStateElements?.length > 0) {
1097
+ if (message.locusStateElements && message.locusStateElements.length > 0) {
1048
1098
  // by this point we now have this.dataSets setup for data sets from this message
1049
1099
  // and hash trees created for the new visible data sets,
1050
1100
  // so we can now process all the updates from the message
@@ -1110,9 +1160,10 @@ class HashTreeParser {
1110
1160
  return;
1111
1161
  }
1112
1162
 
1113
- if (message.heartbeatIntervalMs) {
1114
- this.heartbeatIntervalMs = message.heartbeatIntervalMs;
1163
+ if (message.heartbeatIntervalMs !== undefined) {
1164
+ this.topLevelHeartbeatIntervalMs = message.heartbeatIntervalMs;
1115
1165
  }
1166
+
1116
1167
  if (this.isEndMessage(message)) {
1117
1168
  LoggerProxy.logger.info(
1118
1169
  `HashTreeParser#handleMessage --> ${this.debugId} received sentinel END MEETING message`
@@ -1140,20 +1191,17 @@ class HashTreeParser {
1140
1191
  * @param {Object} updates parsed from a Locus message
1141
1192
  * @returns {void}
1142
1193
  */
1143
- private callLocusInfoUpdateCallback(updates: {
1144
- updateType: LocusInfoUpdateType;
1145
- updatedObjects?: HashTreeObject[];
1146
- }) {
1194
+ private callLocusInfoUpdateCallback(updates: LocusInfoUpdate) {
1147
1195
  if (this.state === 'stopped') {
1148
1196
  return;
1149
1197
  }
1150
1198
 
1151
- const {updateType, updatedObjects} = updates;
1199
+ const {updateType} = updates;
1152
1200
 
1153
- if (updateType === LocusInfoUpdateType.OBJECTS_UPDATED && updatedObjects?.length > 0) {
1201
+ if (updateType === LocusInfoUpdateType.OBJECTS_UPDATED && updates.updatedObjects?.length > 0) {
1154
1202
  // Filter out updates for objects that already have a higher version in their datasets,
1155
1203
  // or removals for objects that still exist in any of their datasets
1156
- const filteredUpdates = updatedObjects.filter((object) => {
1204
+ const filteredUpdates = updates.updatedObjects.filter((object) => {
1157
1205
  const {elementId} = object.htMeta;
1158
1206
  const {type, id, version} = elementId;
1159
1207
 
@@ -1190,10 +1238,10 @@ class HashTreeParser {
1190
1238
  });
1191
1239
 
1192
1240
  if (filteredUpdates.length > 0) {
1193
- this.locusInfoUpdateCallback(updateType, {updatedObjects: filteredUpdates});
1241
+ this.locusInfoUpdateCallback({updateType, updatedObjects: filteredUpdates});
1194
1242
  }
1195
1243
  } else if (updateType !== LocusInfoUpdateType.OBJECTS_UPDATED) {
1196
- this.locusInfoUpdateCallback(updateType, {updatedObjects});
1244
+ this.locusInfoUpdateCallback({updateType});
1197
1245
  }
1198
1246
  }
1199
1247
 
@@ -1215,82 +1263,363 @@ class HashTreeParser {
1215
1263
  * Performs a sync for the given data set.
1216
1264
  *
1217
1265
  * @param {InternalDataSet} dataSet - The data set to sync
1218
- * @param {string} rootHash - Our current root hash for this data set
1219
1266
  * @param {string} reason - The reason for the sync (used for logging)
1267
+ * @param {boolean} [isInitialization] - Whether this is an initialization sync (sends empty leaves data instead of comparing hashes)
1220
1268
  * @returns {Promise<void>}
1221
1269
  */
1222
1270
  private async performSync(
1223
1271
  dataSet: InternalDataSet,
1224
- rootHash: string,
1225
- reason: string
1272
+ reason: string,
1273
+ isInitialization?: boolean
1226
1274
  ): Promise<void> {
1227
1275
  if (!dataSet.hashTree) {
1228
1276
  return;
1229
1277
  }
1230
1278
 
1279
+ const abortController = dataSet.syncAbortController ?? new AbortController();
1280
+ dataSet.syncAbortController = abortController;
1281
+
1282
+ const {hashTree} = dataSet;
1283
+ const rootHash = hashTree.getRootHash();
1284
+
1231
1285
  try {
1232
1286
  LoggerProxy.logger.info(
1233
1287
  `HashTreeParser#performSync --> ${this.debugId} ${reason}, syncing data set "${dataSet.name}"`
1234
1288
  );
1235
1289
 
1236
- const mismatchedLeavesData: Record<number, LeafDataItem[]> = {};
1290
+ let leavesData: Record<number, LeafDataItem[]> = {};
1237
1291
 
1238
- if (dataSet.leafCount !== 1) {
1239
- let receivedHashes;
1292
+ if (!isInitialization) {
1293
+ if (dataSet.leafCount !== 1) {
1294
+ let receivedHashes;
1240
1295
 
1241
- try {
1242
- // request hashes from sender
1243
- const {hashes, dataSet: latestDataSetInfo} = await this.getHashesFromLocus(
1244
- dataSet.name,
1245
- rootHash
1246
- );
1296
+ try {
1297
+ // request hashes from sender
1298
+ const hashesResult = await this.getHashesFromLocus(dataSet.name, rootHash);
1247
1299
 
1248
- receivedHashes = hashes;
1300
+ if (!hashesResult) {
1301
+ // hashes match, no sync needed
1302
+ return;
1303
+ }
1249
1304
 
1250
- dataSet.hashTree.resize(latestDataSetInfo.leafCount);
1251
- } catch (error) {
1252
- if (error.statusCode === 409) {
1253
- // this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
1254
- LoggerProxy.logger.info(
1255
- `HashTreeParser#getHashesFromLocus --> ${this.debugId} Got 409 when fetching hashes for data set "${dataSet.name}": ${error.message}`
1256
- );
1305
+ receivedHashes = hashesResult.hashes;
1257
1306
 
1258
- return;
1307
+ this.updateDataSetLeafCount(dataSet, hashesResult.dataSet.leafCount);
1308
+ } catch (error: any) {
1309
+ if (error?.statusCode === 409) {
1310
+ // this is a leaf count mismatch, we should do nothing, just wait for another heartbeat message from Locus
1311
+ LoggerProxy.logger.info(
1312
+ `HashTreeParser#getHashesFromLocus --> ${this.debugId} Got 409 when fetching hashes for data set "${dataSet.name}": ${error.message}`
1313
+ );
1314
+
1315
+ return;
1316
+ }
1317
+ throw error;
1259
1318
  }
1260
- throw error;
1319
+
1320
+ // identify mismatched leaves
1321
+ const mismatchedLeaveIndexes = hashTree.diffHashes(receivedHashes);
1322
+
1323
+ mismatchedLeaveIndexes.forEach((index) => {
1324
+ leavesData[index] = hashTree.getLeafData(index);
1325
+ });
1326
+ } else {
1327
+ leavesData = {0: hashTree.getLeafData(0)};
1261
1328
  }
1329
+ }
1330
+
1331
+ if (abortController.signal.aborted) {
1332
+ LoggerProxy.logger.info(
1333
+ `HashTreeParser#performSync --> ${this.debugId} abandoning sync for "${dataSet.name}" before /sync - message received during sync`
1334
+ );
1262
1335
 
1263
- // identify mismatched leaves
1264
- const mismatchedLeaveIndexes = dataSet.hashTree.diffHashes(receivedHashes);
1336
+ return;
1337
+ }
1338
+ // request sync for mismatched leaves
1339
+ let syncResponse: HashTreeMessage | null = null;
1265
1340
 
1266
- mismatchedLeaveIndexes.forEach((index) => {
1267
- mismatchedLeavesData[index] = dataSet.hashTree.getLeafData(index);
1341
+ if (isInitialization) {
1342
+ syncResponse = await this.sendSyncRequestToLocus(dataSet, {isInitialization: true});
1343
+ } else if (Object.keys(leavesData).length > 0) {
1344
+ syncResponse = await this.sendSyncRequestToLocus(dataSet, {
1345
+ mismatchedLeavesData: leavesData,
1268
1346
  });
1269
- } else {
1270
- mismatchedLeavesData[0] = dataSet.hashTree.getLeafData(0);
1271
1347
  }
1272
- // request sync for mismatched leaves
1273
- if (Object.keys(mismatchedLeavesData).length > 0) {
1274
- const syncResponse = await this.sendSyncRequestToLocus(dataSet, mismatchedLeavesData);
1275
1348
 
1276
- // sync API may return nothing (in that case data will arrive via messages)
1277
- // or it may return a response in the same format as messages
1278
- if (syncResponse) {
1279
- this.handleMessage(syncResponse, 'via sync API');
1280
- }
1349
+ // sync API may return nothing (in that case data will arrive via messages)
1350
+ // or it may return a response in the same format as messages
1351
+ // We still need to restart the sync timer as a safety net in case the messages don't arrive.
1352
+ this.runSyncAlgorithm(dataSet);
1353
+
1354
+ if (syncResponse) {
1355
+ // clear the abort controller before processing the response so that
1356
+ // parseMessage() -> cancelPendingSyncsForDataSets() doesn't log a
1357
+ // misleading "aborting sync" message for this already-completed sync
1358
+ dataSet.syncAbortController = undefined;
1359
+
1360
+ // the format of sync response is the same as messages, so we can reuse the same handler
1361
+ this.handleMessage(
1362
+ syncResponse,
1363
+ `via sync API (${
1364
+ isInitialization ? 'init' : `${Object.keys(leavesData).length} mismatched leaves`
1365
+ })`
1366
+ );
1281
1367
  }
1282
1368
  } catch (error) {
1283
- if (error instanceof MeetingEndedError) {
1284
- this.callLocusInfoUpdateCallback({
1285
- updateType: LocusInfoUpdateType.MEETING_ENDED,
1286
- });
1287
- } else {
1369
+ if (!this.handleSyncErrors(error)) {
1288
1370
  LoggerProxy.logger.warn(
1289
1371
  `HashTreeParser#performSync --> ${this.debugId} error during sync for data set "${dataSet.name}":`,
1290
1372
  error
1291
1373
  );
1292
1374
  }
1375
+ } finally {
1376
+ dataSet.syncAbortController = undefined;
1377
+ }
1378
+ }
1379
+
1380
+ /**
1381
+ * Cancels any pending or in-flight syncs for the specified data sets.
1382
+ * This removes matching entries from the sync queue and aborts any in-flight sync HTTP requests.
1383
+ *
1384
+ * @param {string[]} dataSetNames - The names of the data sets to cancel syncs for
1385
+ * @returns {void}
1386
+ */
1387
+ private cancelPendingSyncsForDataSets(dataSetNames: string[]): void {
1388
+ const previousLength = this.syncQueue.length;
1389
+
1390
+ this.syncQueue = this.syncQueue.filter((entry) => !dataSetNames.includes(entry.dataSetName));
1391
+
1392
+ if (previousLength !== this.syncQueue.length) {
1393
+ LoggerProxy.logger.info(
1394
+ `HashTreeParser#cancelPendingSyncsForDataSets --> ${this.debugId} removed ${
1395
+ previousLength - this.syncQueue.length
1396
+ } entries from sync queue for data sets: ${dataSetNames.join(', ')}`
1397
+ );
1398
+ }
1399
+
1400
+ this.markDataSetsForSyncAllBackoffSkip(dataSetNames);
1401
+ this.abortInFlightSyncs(dataSetNames);
1402
+ }
1403
+
1404
+ /**
1405
+ * If a syncAllDatasets backoff sleep is in progress, marks the given data sets to be skipped
1406
+ * after the sleep completes.
1407
+ *
1408
+ * @param {string[]} dataSetNames - The names of the data sets to mark
1409
+ * @returns {void}
1410
+ */
1411
+ private markDataSetsForSyncAllBackoffSkip(dataSetNames: string[]): void {
1412
+ if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
1413
+ for (const name of dataSetNames) {
1414
+ this.dataSetsSyncedDuringBackoff.add(name);
1415
+ }
1416
+ }
1417
+ }
1418
+
1419
+ /**
1420
+ * Aborts any in-flight sync HTTP requests for the specified data sets.
1421
+ *
1422
+ * @param {string[]} dataSetNames - The names of the data sets whose syncs should be aborted
1423
+ * @returns {void}
1424
+ */
1425
+ private abortInFlightSyncs(dataSetNames: string[]): void {
1426
+ for (const name of dataSetNames) {
1427
+ if (this.dataSets[name]?.syncAbortController) {
1428
+ LoggerProxy.logger.info(
1429
+ `HashTreeParser#cancelPendingSyncsForDataSets --> ${this.debugId} aborting in-flight sync for data set "${name}"`
1430
+ );
1431
+ this.dataSets[name].syncAbortController.abort();
1432
+ }
1433
+ }
1434
+ }
1435
+
1436
+ /**
1437
+ * Enqueues a sync for the given data set. If the data set is already in the queue, the request is ignored.
1438
+ * This ensures that all syncs are executed sequentially and no more than 1 sync runs at a time.
1439
+ *
1440
+ * @param {string} dataSetName - The name of the data set to sync
1441
+ * @param {string} reason - The reason for the sync (used for logging)
1442
+ * @param {boolean} [isInitialization=false] - Whether this is an initialization sync (uses empty leaves data instead of hash comparison)
1443
+ * @returns {void}
1444
+ */
1445
+ private enqueueSyncForDataset(
1446
+ dataSetName: string,
1447
+ reason: string,
1448
+ isInitialization = false
1449
+ ): void {
1450
+ if (this.state === 'stopped') return;
1451
+
1452
+ const existingEntry = this.syncQueue.find((entry) => entry.dataSetName === dataSetName);
1453
+
1454
+ if (existingEntry) {
1455
+ if (isInitialization) {
1456
+ existingEntry.isInitialization = true;
1457
+ }
1458
+ LoggerProxy.logger.info(
1459
+ `HashTreeParser#enqueueSyncForDataset --> ${this.debugId} data set "${dataSetName}" already in sync queue, skipping`
1460
+ );
1461
+
1462
+ return;
1463
+ }
1464
+
1465
+ this.syncQueue.push({dataSetName, reason, isInitialization});
1466
+
1467
+ if (!this.isSyncInProgress) {
1468
+ this.syncQueueProcessingPromise = this.processSyncQueue();
1469
+ }
1470
+ }
1471
+
1472
+ /**
1473
+ * Processes the sync queue sequentially. Only one instance of this method runs at a time.
1474
+ *
1475
+ * @returns {Promise<void>}
1476
+ */
1477
+ private async processSyncQueue(): Promise<void> {
1478
+ if (this.isSyncInProgress) return;
1479
+
1480
+ this.isSyncInProgress = true;
1481
+ try {
1482
+ while (this.syncQueue.length > 0 && this.state !== 'stopped') {
1483
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1484
+ const {dataSetName, reason, isInitialization} = this.syncQueue.shift()!;
1485
+ const dataSet = this.dataSets[dataSetName];
1486
+
1487
+ if (!dataSet?.hashTree) {
1488
+ // eslint-disable-next-line no-continue
1489
+ continue;
1490
+ }
1491
+
1492
+ // eslint-disable-next-line no-await-in-loop
1493
+ await this.performSync(dataSet, reason, isInitialization);
1494
+ }
1495
+ } finally {
1496
+ this.isSyncInProgress = false;
1497
+ }
1498
+ }
1499
+
1500
+ /**
1501
+ * sets the backoff type for syncAllDatasets calls, which determines the scope of datasets that will be synced after the backoff delay.
1502
+ *
1503
+ * @param {boolean} onlyLLM - Whether the backoff is for a syncAllDatasets call that is syncing only LLM datasets
1504
+ * @returns {void}
1505
+ */
1506
+ private setSyncAllBackoffType(onlyLLM: boolean): void {
1507
+ this.syncAllBackoffType = onlyLLM ? SyncAllBackoffType.ONLY_LLM : SyncAllBackoffType.ALL;
1508
+ }
1509
+
1510
+ /**
1511
+ * Checks if a syncAll backoff is already in progress. If so, upgrades the scope from
1512
+ * onlyLLM to all datasets when the new call has a broader scope.
1513
+ *
1514
+ * @param {boolean} onlyLLM - Whether the current call is for LLM datasets only
1515
+ * @returns {boolean} true if a backoff is already pending (caller should return early)
1516
+ */
1517
+ private tryUpgradePendingBackoff(onlyLLM: boolean): boolean {
1518
+ if (this.syncAllBackoffType !== SyncAllBackoffType.NONE) {
1519
+ if (!onlyLLM && this.syncAllBackoffType === SyncAllBackoffType.ONLY_LLM) {
1520
+ this.setSyncAllBackoffType(false);
1521
+ LoggerProxy.logger.info(
1522
+ `HashTreeParser#syncAllDatasets --> ${this.debugId} upgraded pending syncAll from onlyLLM to all datasets`
1523
+ );
1524
+ }
1525
+
1526
+ return true;
1293
1527
  }
1528
+
1529
+ return false;
1530
+ }
1531
+
1532
+ /**
1533
+ * Syncs all data sets that have hash trees, one by one in sequence, using the priority order
1534
+ * provided by sortByInitPriority().
1535
+ *
1536
+ * If a call is already waiting in the backoff delay phase, a new call with a broader scope
1537
+ * (onlyLLM=false) will upgrade the pending scope, and the dataset list will be computed after
1538
+ * the backoff using the upgraded scope. After the backoff, the sync queue handles deduplication
1539
+ * so no guard is needed.
1540
+ *
1541
+ * @param {Object} [options={}] - Options for syncing
1542
+ * @param {boolean} [options.onlyLLM=false] - Whether to sync only LLM based data sets
1543
+ * @returns {Promise<void>}
1544
+ */
1545
+ public async syncAllDatasets(options: {onlyLLM?: boolean} = {}): Promise<void> {
1546
+ const {onlyLLM = false} = options;
1547
+ if (this.state === 'stopped') return;
1548
+
1549
+ // if we're already in the backoff delay phase, try to upgrade the scope instead of starting a new one
1550
+ if (this.tryUpgradePendingBackoff(onlyLLM)) {
1551
+ return;
1552
+ }
1553
+
1554
+ const dataSetsToSync = this.getSortedDataSetsWithHashTrees(onlyLLM);
1555
+
1556
+ if (dataSetsToSync.length === 0) return;
1557
+
1558
+ this.setSyncAllBackoffType(onlyLLM);
1559
+
1560
+ const delay = this.getWeightedBackoffTime(dataSetsToSync[0].backoff);
1561
+
1562
+ LoggerProxy.logger.info(
1563
+ `HashTreeParser#syncAllDatasets --> ${this.debugId} starting backoff delay of ${delay}ms (onlyLLM=${onlyLLM})`
1564
+ );
1565
+
1566
+ // delay the start of the syncs - this is a Locus requirement to avoid thundering herd issues
1567
+ await sleep(delay);
1568
+
1569
+ // read the (possibly upgraded) scope and clear the backoff flag
1570
+ const effectiveBackoffType = this.syncAllBackoffType;
1571
+ const skippedDataSets = this.dataSetsSyncedDuringBackoff;
1572
+
1573
+ this.syncAllBackoffType = SyncAllBackoffType.NONE;
1574
+ this.dataSetsSyncedDuringBackoff = new Set();
1575
+
1576
+ if ((this.state as string) === 'stopped') return;
1577
+
1578
+ // re-evaluate the dataset list after the sleep, since the scope may have been upgraded
1579
+ // and exclude datasets that received messages during the backoff sleep
1580
+ const effectiveDataSetsToSync = this.getSortedDataSetsWithHashTrees(
1581
+ effectiveBackoffType === SyncAllBackoffType.ONLY_LLM
1582
+ ).filter((ds) => !skippedDataSets.has(ds.name));
1583
+
1584
+ if (skippedDataSets.size > 0) {
1585
+ LoggerProxy.logger.info(
1586
+ `HashTreeParser#syncAllDatasets --> ${
1587
+ this.debugId
1588
+ } skipping datasets that received messages during backoff: ${[...skippedDataSets].join(
1589
+ ', '
1590
+ )}`
1591
+ );
1592
+ }
1593
+
1594
+ LoggerProxy.logger.info(
1595
+ `HashTreeParser#syncAllDatasets --> ${this.debugId} syncing ${
1596
+ effectiveBackoffType === SyncAllBackoffType.ONLY_LLM ? 'only LLM' : 'all'
1597
+ } datasets: ${effectiveDataSetsToSync.map((ds) => ds.name).join(', ')}`
1598
+ );
1599
+
1600
+ for (const ds of effectiveDataSetsToSync) {
1601
+ this.enqueueSyncForDataset(ds.name, 'syncAllDatasets');
1602
+ }
1603
+
1604
+ await this.syncQueueProcessingPromise;
1605
+ }
1606
+
1607
+ /**
1608
+ * Returns the list of data sets that have hash trees, sorted by the priority order provided by sortByInitPriority().
1609
+ *
1610
+ * @param {boolean} onlyLLM - Whether to include only LLM based data sets
1611
+ * @returns {Array<{name: string, backoff: {maxMs: number, exponent: number}}>} The sorted list of data sets with their backoff configurations
1612
+ */
1613
+ private getSortedDataSetsWithHashTrees(onlyLLM: boolean) {
1614
+ let dataSets = Object.values(this.dataSets)
1615
+ .filter((dataSet) => dataSet?.hashTree)
1616
+ .map((dataSet) => ({name: dataSet.name, backoff: dataSet.backoff}));
1617
+
1618
+ if (onlyLLM) {
1619
+ dataSets = dataSets.filter((ds) => LLM_DATASET_NAMES.includes(ds.name));
1620
+ }
1621
+
1622
+ return sortByInitPriority(dataSets, DATA_SET_INIT_PRIORITY);
1294
1623
  }
1295
1624
 
1296
1625
  /**
@@ -1311,21 +1640,14 @@ class HashTreeParser {
1311
1640
  }
1312
1641
 
1313
1642
  if (!dataSet.hashTree) {
1314
- LoggerProxy.logger.info(
1315
- `HashTreeParser#runSyncAlgorithm --> ${this.debugId} Data set "${dataSet.name}" has no hash tree, skipping sync algorithm`
1316
- );
1643
+ // no hash tree, so no need to do any syncing
1644
+ // we fall into this branch often, because Locus sends dataSets in messages that are not visible to us
1317
1645
 
1318
1646
  return;
1319
1647
  }
1320
1648
 
1321
1649
  dataSet.hashTree.resize(receivedDataSet.leafCount);
1322
1650
 
1323
- // temporary log for the workshop // todo: remove
1324
- const ourCurrentRootHash = dataSet.hashTree.getRootHash();
1325
- LoggerProxy.logger.info(
1326
- `HashTreeParser#runSyncAlgorithm --> ${this.debugId} dataSet="${dataSet.name}" version=${dataSet.version} hashes before starting timer: ours=${ourCurrentRootHash} Locus=${dataSet.root}`
1327
- );
1328
-
1329
1651
  const delay = dataSet.idleMs + this.getWeightedBackoffTime(dataSet.backoff);
1330
1652
 
1331
1653
  if (delay > 0) {
@@ -1333,11 +1655,7 @@ class HashTreeParser {
1333
1655
  clearTimeout(dataSet.timer);
1334
1656
  }
1335
1657
 
1336
- LoggerProxy.logger.info(
1337
- `HashTreeParser#runSyncAlgorithm --> ${this.debugId} setting "${dataSet.name}" sync timer for ${delay}`
1338
- );
1339
-
1340
- dataSet.timer = setTimeout(async () => {
1658
+ dataSet.timer = setTimeout(() => {
1341
1659
  dataSet.timer = undefined;
1342
1660
 
1343
1661
  if (!dataSet.hashTree) {
@@ -1351,15 +1669,10 @@ class HashTreeParser {
1351
1669
  const rootHash = dataSet.hashTree.getRootHash();
1352
1670
 
1353
1671
  if (dataSet.root !== rootHash) {
1354
- await this.performSync(
1355
- dataSet,
1356
- rootHash,
1672
+ this.enqueueSyncForDataset(
1673
+ dataSet.name,
1357
1674
  `Root hash mismatch: received=${dataSet.root}, ours=${rootHash}`
1358
1675
  );
1359
- } else {
1360
- LoggerProxy.logger.info(
1361
- `HashTreeParser#runSyncAlgorithm --> ${this.debugId} "${dataSet.name}" root hash matching: ${rootHash}, version=${dataSet.version}`
1362
- );
1363
1676
  }
1364
1677
  }, delay);
1365
1678
  } else {
@@ -1379,38 +1692,39 @@ class HashTreeParser {
1379
1692
  * @returns {void}
1380
1693
  */
1381
1694
  private resetHeartbeatWatchdogs(receivedDataSets: Array<DataSet>): void {
1382
- if (!this.heartbeatIntervalMs) {
1383
- return;
1384
- }
1385
-
1386
1695
  for (const receivedDataSet of receivedDataSets) {
1387
1696
  const dataSet = this.dataSets[receivedDataSet.name];
1388
1697
 
1389
- if (!dataSet?.hashTree) {
1390
- // eslint-disable-next-line no-continue
1391
- continue;
1392
- }
1393
-
1394
1698
  if (dataSet.heartbeatWatchdogTimer) {
1395
1699
  clearTimeout(dataSet.heartbeatWatchdogTimer);
1396
1700
  dataSet.heartbeatWatchdogTimer = undefined;
1397
1701
  }
1398
1702
 
1703
+ // dataset-level heartbeatIntervalMs takes priority; fall back to top-level common value
1704
+ const heartbeatIntervalMs = dataSet?.heartbeatIntervalMs ?? this.topLevelHeartbeatIntervalMs;
1705
+
1706
+ if (!dataSet?.hashTree || !heartbeatIntervalMs) {
1707
+ // eslint-disable-next-line no-continue
1708
+ continue;
1709
+ }
1710
+
1399
1711
  const backoffTime = this.getWeightedBackoffTime(dataSet.backoff);
1400
- const delay = this.heartbeatIntervalMs + backoffTime;
1712
+ const delay = heartbeatIntervalMs + backoffTime;
1401
1713
 
1402
- dataSet.heartbeatWatchdogTimer = setTimeout(async () => {
1714
+ dataSet.heartbeatWatchdogTimer = setTimeout(() => {
1403
1715
  dataSet.heartbeatWatchdogTimer = undefined;
1404
1716
 
1405
1717
  LoggerProxy.logger.warn(
1406
1718
  `HashTreeParser#resetHeartbeatWatchdogs --> ${this.debugId} Heartbeat watchdog fired for data set "${dataSet.name}" - no heartbeat received within expected interval, initiating sync`
1407
1719
  );
1408
1720
 
1409
- await this.performSync(
1410
- dataSet,
1411
- dataSet.hashTree.getRootHash(),
1412
- `heartbeat watchdog expired`
1413
- );
1721
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_HEARTBEAT_WATCHDOG_EXPIRED, {
1722
+ debugId: this.debugId,
1723
+ dataSetName: dataSet.name,
1724
+ });
1725
+
1726
+ this.enqueueSyncForDataset(dataSet.name, `heartbeat watchdog expired`);
1727
+ this.resetHeartbeatWatchdogs([dataSet]);
1414
1728
  }, delay);
1415
1729
  }
1416
1730
  }
@@ -1443,7 +1757,13 @@ class HashTreeParser {
1443
1757
  `HashTreeParser#stop --> ${this.debugId} Stopping HashTreeParser, clearing timers and hash trees`
1444
1758
  );
1445
1759
  this.stopAllTimers();
1760
+ this.syncQueue = [];
1761
+ this.topLevelHeartbeatIntervalMs = undefined;
1762
+ this.syncAllBackoffType = SyncAllBackoffType.NONE;
1763
+ this.dataSetsSyncedDuringBackoff = new Set();
1446
1764
  Object.values(this.dataSets).forEach((dataSet) => {
1765
+ dataSet.syncAbortController?.abort();
1766
+ dataSet.syncAbortController = undefined;
1447
1767
  dataSet.hashTree = undefined;
1448
1768
  });
1449
1769
  this.visibleDataSets = [];
@@ -1451,17 +1771,27 @@ class HashTreeParser {
1451
1771
  }
1452
1772
 
1453
1773
  /**
1454
- * Resumes the HashTreeParser that was previously stopped.
1774
+ * Cleans up the HashTreeParser, stopping all timers and clearing all internal state.
1775
+ * After calling this, the parser should not be used anymore.
1776
+ * @returns {void}
1777
+ */
1778
+ public cleanUp() {
1779
+ this.stop();
1780
+ this.dataSets = {};
1781
+ }
1782
+
1783
+ /**
1784
+ * Resumes the HashTreeParser that was previously stopped, using a hash tree message.
1455
1785
  * @param {HashTreeMessage} message - The message to resume with, it must contain metadata with visible data sets info
1456
1786
  * @returns {void}
1457
1787
  */
1458
- public resume(message: HashTreeMessage) {
1788
+ public resumeFromMessage(message: HashTreeMessage) {
1459
1789
  // check that message contains metadata with visible data sets - this is essential to be able to resume
1460
1790
  const metadataObject = message.locusStateElements?.find((el) => isMetadata(el));
1461
1791
 
1462
1792
  if (!metadataObject?.data?.visibleDataSets) {
1463
1793
  LoggerProxy.logger.warn(
1464
- `HashTreeParser#resume --> ${this.debugId} Cannot resume HashTreeParser because the message is missing metadata with visible data sets info`
1794
+ `HashTreeParser#resumeFromMessage --> ${this.debugId} Cannot resume HashTreeParser because the message is missing metadata with visible data sets info`
1465
1795
  );
1466
1796
 
1467
1797
  return;
@@ -1482,7 +1812,7 @@ class HashTreeParser {
1482
1812
  };
1483
1813
  }
1484
1814
  LoggerProxy.logger.info(
1485
- `HashTreeParser#resume --> ${
1815
+ `HashTreeParser#resumeFromMessage --> ${
1486
1816
  this.debugId
1487
1817
  } Resuming HashTreeParser with data sets: ${Object.keys(this.dataSets).join(
1488
1818
  ', '
@@ -1493,18 +1823,47 @@ class HashTreeParser {
1493
1823
  this.handleMessage(message, 'on resume');
1494
1824
  }
1495
1825
 
1826
+ /**
1827
+ * Resumes the HashTreeParser that was previously stopped, using a Locus API response.
1828
+ * Unlike resumeFromMessage(), this does not require metadata/dataSets in the input,
1829
+ * as it fetches all necessary information from Locus via initializeFromGetLociResponse.
1830
+ * @param {LocusDTO} locus - locus object from an API response
1831
+ * @returns {Promise}
1832
+ */
1833
+ public async resumeFromApiResponse(locus: LocusDTO) {
1834
+ this.state = 'active';
1835
+ this.dataSets = {};
1836
+
1837
+ LoggerProxy.logger.info(
1838
+ `HashTreeParser#resumeFromApiResponse --> ${this.debugId} Resuming HashTreeParser from API response`
1839
+ );
1840
+
1841
+ await this.initializeFromGetLociResponse(locus);
1842
+ }
1843
+
1496
1844
  private checkForSentinelHttpResponse(error: any, dataSetName?: string) {
1845
+ // 404 for any dataset means the locus is no longer available at this URL - could be replaced or ended
1846
+ // if a dataset is just not visible, we would get a 400
1847
+ if (error.statusCode === 404) {
1848
+ LoggerProxy.logger.info(
1849
+ `HashTreeParser#checkForSentinelHttpResponse --> ${this.debugId} Received 404 for data set "${dataSetName}", locus not found`
1850
+ );
1851
+ this.stopAllTimers();
1852
+
1853
+ throw new LocusNotFoundError();
1854
+ }
1855
+
1497
1856
  const isValidDataSetForSentinel =
1498
1857
  dataSetName === undefined ||
1499
1858
  PossibleSentinelMessageDataSetNames.includes(dataSetName.toLowerCase());
1500
1859
 
1501
1860
  if (
1502
- ((error.statusCode === 409 && error.body?.errorCode === 2403004) ||
1503
- error.statusCode === 404) &&
1861
+ error.statusCode === 409 &&
1862
+ error.body?.errorCode === LocusErrorCodes.LOCUS_INACTIVE &&
1504
1863
  isValidDataSetForSentinel
1505
1864
  ) {
1506
1865
  LoggerProxy.logger.info(
1507
- `HashTreeParser#checkForSentinelHttpResponse --> ${this.debugId} Received ${error.statusCode} for data set "${dataSetName}", indicating that the meeting has ended`
1866
+ `HashTreeParser#checkForSentinelHttpResponse --> ${this.debugId} Received ${error.statusCode}/${error.body?.errorCode} for data set "${dataSetName}", indicating that the meeting has ended`
1508
1867
  );
1509
1868
  this.stopAllTimers();
1510
1869
 
@@ -1516,7 +1875,7 @@ class HashTreeParser {
1516
1875
  * Gets the current hashes from the locus for a specific data set.
1517
1876
  * @param {string} dataSetName
1518
1877
  * @param {string} currentRootHash
1519
- * @returns {string[]}
1878
+ * @returns {Object|null} An object containing the hashes and leaf count, or null if the hashes match and no sync is needed
1520
1879
  */
1521
1880
  private getHashesFromLocus(dataSetName: string, currentRootHash: string) {
1522
1881
  LoggerProxy.logger.info(
@@ -1535,6 +1894,15 @@ class HashTreeParser {
1535
1894
  },
1536
1895
  })
1537
1896
  .then((response) => {
1897
+ if (!response.body || isEmpty(response.body)) {
1898
+ // 204 with empty body means our hashes match Locus, no sync needed
1899
+ LoggerProxy.logger.info(
1900
+ `HashTreeParser#getHashesFromLocus --> ${this.debugId} Got ${response.statusCode} with empty body for data set "${dataSetName}", hashes match - no sync needed`
1901
+ );
1902
+
1903
+ return null;
1904
+ }
1905
+
1538
1906
  const hashes = response.body?.hashes as string[] | undefined;
1539
1907
  const dataSetFromResponse = response.body?.dataSet;
1540
1908
 
@@ -1563,6 +1931,13 @@ class HashTreeParser {
1563
1931
  error
1564
1932
  );
1565
1933
  this.checkForSentinelHttpResponse(error, dataSet.name);
1934
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_SYNC_FAILURE, {
1935
+ debugId: this.debugId,
1936
+ dataSetName,
1937
+ request: 'GET /hashtree',
1938
+ statusCode: error.statusCode,
1939
+ reason: error.message,
1940
+ });
1566
1941
 
1567
1942
  throw error;
1568
1943
  });
@@ -1572,29 +1947,43 @@ class HashTreeParser {
1572
1947
  * Sends a sync request to Locus for the specified data set.
1573
1948
  *
1574
1949
  * @param {InternalDataSet} dataSet The data set to sync.
1575
- * @param {Record<number, LeafDataItem[]>} mismatchedLeavesData The mismatched leaves data to include in the sync request.
1950
+ * @param {Object} options Either `{ isInitialization: true }` for init syncs (uses leafCount=1 with empty leaf data) or `{ mismatchedLeavesData }` for normal syncs.
1576
1951
  * @returns {Promise<HashTreeMessage|null>}
1577
1952
  */
1578
1953
  private sendSyncRequestToLocus(
1579
1954
  dataSet: InternalDataSet,
1580
- mismatchedLeavesData: Record<number, LeafDataItem[]>
1955
+ options: {isInitialization: true} | {mismatchedLeavesData: Record<number, LeafDataItem[]>}
1581
1956
  ): Promise<HashTreeMessage | null> {
1582
1957
  LoggerProxy.logger.info(
1583
1958
  `HashTreeParser#sendSyncRequestToLocus --> ${this.debugId} Sending sync request for data set "${dataSet.name}"`
1584
1959
  );
1585
1960
 
1961
+ const isInitialization = 'isInitialization' in options;
1962
+
1586
1963
  const url = `${dataSet.url}/sync`;
1587
- const body = {
1588
- leafCount: dataSet.leafCount,
1964
+ const body: {
1965
+ leafCount: number;
1966
+ leafDataEntries: {leafIndex: number; elementIds: LeafDataItem[]}[];
1967
+ } = {
1968
+ leafCount: isInitialization ? 1 : dataSet.leafCount,
1589
1969
  leafDataEntries: [],
1590
1970
  };
1591
1971
 
1592
- Object.keys(mismatchedLeavesData).forEach((index) => {
1593
- body.leafDataEntries.push({
1594
- leafIndex: parseInt(index, 10),
1595
- elementIds: mismatchedLeavesData[index],
1972
+ if (isInitialization) {
1973
+ // initialization sync: Locus requires leafCount=1 with a single empty leaf
1974
+ body.leafDataEntries.push({leafIndex: 0, elementIds: []});
1975
+ } else {
1976
+ const {mismatchedLeavesData} = options;
1977
+
1978
+ Object.keys(mismatchedLeavesData).forEach((index) => {
1979
+ const leafIndex = parseInt(index, 10);
1980
+
1981
+ body.leafDataEntries.push({
1982
+ leafIndex,
1983
+ elementIds: mismatchedLeavesData[leafIndex],
1984
+ });
1596
1985
  });
1597
- });
1986
+ }
1598
1987
 
1599
1988
  const ourCurrentRootHash = dataSet.hashTree ? dataSet.hashTree.getRootHash() : EMPTY_HASH;
1600
1989
 
@@ -1607,10 +1996,6 @@ class HashTreeParser {
1607
1996
  body,
1608
1997
  })
1609
1998
  .then((resp) => {
1610
- LoggerProxy.logger.info(
1611
- `HashTreeParser#sendSyncRequestToLocus --> ${this.debugId} Sync request succeeded for "${dataSet.name}"`
1612
- );
1613
-
1614
1999
  if (!resp.body || isEmpty(resp.body)) {
1615
2000
  LoggerProxy.logger.info(
1616
2001
  `HashTreeParser#sendSyncRequestToLocus --> ${this.debugId} Got ${resp.statusCode} with empty body for sync request for data set "${dataSet.name}", data should arrive via messages`
@@ -1627,6 +2012,13 @@ class HashTreeParser {
1627
2012
  error
1628
2013
  );
1629
2014
  this.checkForSentinelHttpResponse(error, dataSet.name);
2015
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.HASH_TREE_SYNC_FAILURE, {
2016
+ debugId: this.debugId,
2017
+ dataSetName: dataSet.name,
2018
+ request: 'POST /sync',
2019
+ statusCode: error.statusCode,
2020
+ reason: error.message,
2021
+ });
1630
2022
 
1631
2023
  throw error;
1632
2024
  });