292
return [];
293
}
295
>
// Sort only when the buffer is not in chronological order,
296
>
// which can happen when events arrive out of order (e.g.
297
>
// tail-first backfill). When events arrive in
298
>
// order (the common case) the check is O(n) with no sort.
299
>
if (!this._isSorted(result)) {
300
result.sort((a, b) => a.created.getTime() - b.created.getTime());
301
}
303
>
// subagentInvocation + userMessage from the same span), keep
304
>
// the one with the richest kind.
305
>
result = this._deduplicateEvents(result);
306
>
return result;
307
>
}
308
309
// Cross-session query: merge all buffers and sort to interleave.