mirror of
https://github.com/block/buzz.git
synced 2026-11-26 19:21:50 +00:00
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 <tlongwell@block.xyz> Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
This commit is contained in:
parent
bb596ecc9a
commit
eb94f8391a
@@ -50,7 +50,7 @@ export function sortMessages(messages: RelayEvent[]) {
|
||||
});
|
||||
}
|
||||
|
||||
function isTimelineWindowContentEvent(event: RelayEvent) {
|
||||
export function isTimelineWindowContentEvent(event: RelayEvent) {
|
||||
return (
|
||||
event.kind === KIND_STREAM_MESSAGE ||
|
||||
event.kind === KIND_STREAM_MESSAGE_V2 ||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { pageOlderMessagesUntilRowFloor } from "./pageOlderMessages.ts";
|
||||
import {
|
||||
maxEventIdAtSecond,
|
||||
pageOlderMessagesUntilRowFloor,
|
||||
} from "./pageOlderMessages.ts";
|
||||
import {
|
||||
channelMessagesKey,
|
||||
mergeNonContiguousTimelineMessages,
|
||||
@@ -178,3 +181,39 @@ test("late island response never downgrades a contiguous copy (downgrade race)",
|
||||
// And the reverse direction: thread replies already contiguous stay put.
|
||||
assert.equal(merged.length, cache.length);
|
||||
});
|
||||
|
||||
test("dense-second seed ignores aux and island ids at the boundary second", () => {
|
||||
const channelId = "dense-second-seed";
|
||||
const second = 7_000;
|
||||
// Two content events already held at the stalled second...
|
||||
const contentA = event({ id: id("caa", 0), createdAt: second, channelId });
|
||||
const contentB = event({ id: id("cbb", 0), createdAt: second, channelId });
|
||||
// ...an unmarked reaction whose id sorts after both (aux kinds are absent
|
||||
// from the bridge keyset pages, so its id proves nothing about content)...
|
||||
const auxLater = event({
|
||||
id: id("zaux", 0),
|
||||
kind: 7,
|
||||
createdAt: second,
|
||||
channelId,
|
||||
tags: [
|
||||
["h", channelId],
|
||||
["e", contentA.id],
|
||||
],
|
||||
});
|
||||
// ...and a marked island whose id sorts after everything.
|
||||
const islandLater = {
|
||||
...event({ id: id("zisl", 0), createdAt: second, channelId }),
|
||||
nonContiguous: true,
|
||||
};
|
||||
|
||||
const seed = maxEventIdAtSecond(
|
||||
[contentA, contentB, auxLater, islandLater],
|
||||
second,
|
||||
);
|
||||
|
||||
// Seeding from the aux/island id would tell the relay "everything up to
|
||||
// this id is held" and skip unseen content rows in the same second.
|
||||
assert.equal(seed, contentB.id);
|
||||
// No contiguous content at the second -> no fabricated cursor.
|
||||
assert.equal(maxEventIdAtSecond([auxLater, islandLater], second), null);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { countTopLevelTimelineRows } from "@/features/messages/lib/formatTimelin
|
||||
import { backfillAuxForMessages } from "@/features/messages/lib/auxBackfill";
|
||||
import {
|
||||
channelMessagesKey,
|
||||
isTimelineWindowContentEvent,
|
||||
mergeTimelineHistoryMessages,
|
||||
oldestContiguousHistoryTimestamp,
|
||||
} from "@/features/messages/lib/messageQueryKeys";
|
||||
@@ -49,15 +50,24 @@ const inFlightPasses = new Map<string, Promise<PageOlderResult>>();
|
||||
* Non-contiguous events are excluded: an out-of-band island at the boundary
|
||||
* second is a *point*, not proof that everything up to its id is held —
|
||||
* seeding past it would skip the unfetched rows before it. The island itself
|
||||
* just dedupes away when re-fetched.
|
||||
* just dedupes away when re-fetched. Auxiliary events are excluded for the
|
||||
* same reason: the bridge keyset pages timeline-content kinds only, so an aux
|
||||
* id at the boundary second says nothing about which *content* rows are held
|
||||
* — seeding from a later aux id would skip unseen content in that second.
|
||||
*
|
||||
* Exported for tests only — the pager is the sole runtime caller.
|
||||
*/
|
||||
function maxEventIdAtSecond(
|
||||
export function maxEventIdAtSecond(
|
||||
events: RelayEvent[],
|
||||
second: number,
|
||||
): string | null {
|
||||
let maxId: string | null = null;
|
||||
for (const event of events) {
|
||||
if (event.created_at !== second || event.nonContiguous) {
|
||||
if (
|
||||
event.created_at !== second ||
|
||||
event.nonContiguous ||
|
||||
!isTimelineWindowContentEvent(event)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (maxId === null || event.id > maxId) {
|
||||
|
||||
Reference in New Issue
Block a user