You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The identity disappeared between INSERT and SELECT — unusual race condition.
216
+
// Cannot safely resolve; schedule orphan deletion and throw.
217
+
this.log.error(
218
+
{orphanMemberId: id, identity },
219
+
'Verified identity not found after conflict detection — scheduling orphan deletion',
220
+
)
221
+
awaitthis.scheduleOrphanMemberDeletion(id)
222
+
thrownewApplicationError(
223
+
`Identity conflict during member creation: owner not found for identity (${identity.platform}, ${identity.value}, ${identity.type})`,
224
+
)
225
+
}elseif(owner===id){
226
+
// Successfully inserted for the orphan — will be moved to the existing member below
227
+
orphanVerifiedIdentities.push(identity)
228
+
}elseif(!existingMemberId){
229
+
// First conflicting owner found
230
+
existingMemberId=owner
231
+
}elseif(existingMemberId!==owner){
232
+
// A second conflicting owner — two existing members each own a different verified
233
+
// identity of this incoming member, so the data source asserts they are the same
234
+
// person. Auto-merge the second into the first.
235
+
this.log.warn(
236
+
{
237
+
orphanMemberId: id,
238
+
primaryMemberId: existingMemberId,
239
+
secondaryMemberId: owner,
240
+
identity,
241
+
},
242
+
'Multiple conflicting verified identities belong to different existing members — merging automatically',
243
+
)
244
+
letmerged: boolean
245
+
try{
246
+
merged=awaitmergeIfAllowed(
247
+
this.pgQx,
248
+
this.temporal,
249
+
this.log,
250
+
existingMemberId,
251
+
owner,
252
+
)
253
+
}catch(mergeErr){
254
+
this.log.error(
255
+
mergeErr,
256
+
{
257
+
orphanMemberId: id,
258
+
primaryMemberId: existingMemberId,
259
+
secondaryMemberId: owner,
260
+
},
261
+
'Auto-merge of conflicting members failed — scheduling orphan deletion',
262
+
)
263
+
awaitthis.scheduleOrphanMemberDeletion(id)
264
+
thrownewApplicationError(
265
+
`Identity conflict during member creation: auto-merge of members ${existingMemberId} and ${owner} failed for identity (${identity.platform}, ${identity.value}, ${identity.type})`,
266
+
)
267
+
}
268
+
if(!merged){
269
+
this.log.error(
270
+
{
271
+
orphanMemberId: id,
272
+
primaryMemberId: existingMemberId,
273
+
secondaryMemberId: owner,
274
+
},
275
+
'Auto-merge prevented by noMerge record — scheduling orphan deletion',
276
+
)
277
+
awaitthis.scheduleOrphanMemberDeletion(id)
278
+
thrownewApplicationError(
279
+
`Identity conflict during member creation: members ${existingMemberId} and ${owner} are marked as no-merge but share identity (${identity.platform}, ${identity.value}, ${identity.type})`,
280
+
)
281
+
}
282
+
// existingMemberId (primary) survives; owner (secondary) was absorbed
283
+
this.log.info(
284
+
{
285
+
orphanMemberId: id,
286
+
survivingMemberId: existingMemberId,
287
+
mergedMemberId: owner,
288
+
identity,
289
+
},
290
+
'Auto-merge of conflicting members succeeded',
291
+
)
292
+
}
293
+
// else: owner === existingMemberId — same member owns this identity too, nothing to do
294
+
}
295
+
296
+
if(existingMemberId){
297
+
// Move any verified identities that were inserted for the orphan to the existing
298
+
// member so they are not lost when the orphan is cascade-deleted.
299
+
// UPDATE memberId rather than INSERT to avoid unique constraint violations.
`Identity conflict during member creation for member ${id}: inserted ${insertedCount} of ${data.identities.length} identities but found no conflicting owner`,
169
341
)
170
-
thrownewApplicationError('Error while inserting identities for a new member!',err)
0 commit comments