Skip to content

Commit eb94f83

Browse files
npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67dTyler Longwell
andcommitted
fix(desktop): dense-second keyset seed must ignore auxiliary event ids
maxEventIdAtSecond seeded the bridge composite cursor from every cached event at the boundary second, but the bridge keyset pages timeline- content kinds only. An unmarked reaction/edit/deletion at that second with an id later than the held content prefix would seed before_id past unseen content rows — a same-second hole. Apply the same isTimelineWindowContentEvent predicate the frontier helper uses, and pin it with a regression (aux and island ids at the boundary second are both ignored; all-aux yields no fabricated cursor). Found in review by Wren. Co-authored-by: Tyler Longwell <[email protected]> Signed-off-by: Tyler Longwell <[email protected]>
1 parent bb596ec commit eb94f83

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

‎desktop/src/features/messages/lib/messageQueryKeys.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function sortMessages(messages: RelayEvent[]) {
5050
});
5151
}
5252

53-
function isTimelineWindowContentEvent(event: RelayEvent) {
53+
export function isTimelineWindowContentEvent(event: RelayEvent) {
5454
return (
5555
event.kind === KIND_STREAM_MESSAGE ||
5656
event.kind === KIND_STREAM_MESSAGE_V2 ||

‎desktop/src/features/messages/lib/pageOlderMessages.test.mjs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
33

4-
import { pageOlderMessagesUntilRowFloor } from "./pageOlderMessages.ts";
4+
import {
5+
maxEventIdAtSecond,
6+
pageOlderMessagesUntilRowFloor,
7+
} from "./pageOlderMessages.ts";
58
import {
69
channelMessagesKey,
710
mergeNonContiguousTimelineMessages,
@@ -178,3 +181,39 @@ test("late island response never downgrades a contiguous copy (downgrade race)",
178181
// And the reverse direction: thread replies already contiguous stay put.
179182
assert.equal(merged.length, cache.length);
180183
});
184+
185+
test("dense-second seed ignores aux and island ids at the boundary second", () => {
186+
const channelId = "dense-second-seed";
187+
const second = 7_000;
188+
// Two content events already held at the stalled second...
189+
const contentA = event({ id: id("caa", 0), createdAt: second, channelId });
190+
const contentB = event({ id: id("cbb", 0), createdAt: second, channelId });
191+
// ...an unmarked reaction whose id sorts after both (aux kinds are absent
192+
// from the bridge keyset pages, so its id proves nothing about content)...
193+
const auxLater = event({
194+
id: id("zaux", 0),
195+
kind: 7,
196+
createdAt: second,
197+
channelId,
198+
tags: [
199+
["h", channelId],
200+
["e", contentA.id],
201+
],
202+
});
203+
// ...and a marked island whose id sorts after everything.
204+
const islandLater = {
205+
...event({ id: id("zisl", 0), createdAt: second, channelId }),
206+
nonContiguous: true,
207+
};
208+
209+
const seed = maxEventIdAtSecond(
210+
[contentA, contentB, auxLater, islandLater],
211+
second,
212+
);
213+
214+
// Seeding from the aux/island id would tell the relay "everything up to
215+
// this id is held" and skip unseen content rows in the same second.
216+
assert.equal(seed, contentB.id);
217+
// No contiguous content at the second -> no fabricated cursor.
218+
assert.equal(maxEventIdAtSecond([auxLater, islandLater], second), null);
219+
});

‎desktop/src/features/messages/lib/pageOlderMessages.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { countTopLevelTimelineRows } from "@/features/messages/lib/formatTimelin
44
import { backfillAuxForMessages } from "@/features/messages/lib/auxBackfill";
55
import {
66
channelMessagesKey,
7+
isTimelineWindowContentEvent,
78
mergeTimelineHistoryMessages,
89
oldestContiguousHistoryTimestamp,
910
} from "@/features/messages/lib/messageQueryKeys";
@@ -49,15 +50,24 @@ const inFlightPasses = new Map<string, Promise<PageOlderResult>>();
4950
* Non-contiguous events are excluded: an out-of-band island at the boundary
5051
* second is a *point*, not proof that everything up to its id is held —
5152
* seeding past it would skip the unfetched rows before it. The island itself
52-
* just dedupes away when re-fetched.
53+
* just dedupes away when re-fetched. Auxiliary events are excluded for the
54+
* same reason: the bridge keyset pages timeline-content kinds only, so an aux
55+
* id at the boundary second says nothing about which *content* rows are held
56+
* — seeding from a later aux id would skip unseen content in that second.
57+
*
58+
* Exported for tests only — the pager is the sole runtime caller.
5359
*/
54-
function maxEventIdAtSecond(
60+
export function maxEventIdAtSecond(
5561
events: RelayEvent[],
5662
second: number,
5763
): string | null {
5864
let maxId: string | null = null;
5965
for (const event of events) {
60-
if (event.created_at !== second || event.nonContiguous) {
66+
if (
67+
event.created_at !== second ||
68+
event.nonContiguous ||
69+
!isTimelineWindowContentEvent(event)
70+
) {
6171
continue;
6272
}
6373
if (maxId === null || event.id > maxId) {

0 commit comments

Comments
 (0)