commit c5037e3791e6ddfa58b8d698681045540afc3a97
parent c98e1e8a761088d545ffc8ff33592499bafcf6ca
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 21:46:33 -0500
x-trending: review 2 M2 and ruling R-d -- an untagged sighting is the opening tab's, and gone from the page needs one read of every tab that showed the post
- M2: a sighting from a read before tabs were read names no tab; it was the
tab the page opens on. Only a complete read of that tab (the source's first
known tab, else "Top"), or a read that cannot name its own tab, judges it:
a complete Latest read no longer marks such a post gone while Top stopped
at its cap.
- R-d: "gone from the page" is set only when every tab that showed the post
was read to its end without it IN THE SAME READ, and no tab of that read
shows it. Per-tab marks from different reads stay "gone from <tab> at
<time>" and never add up to it.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
2 files changed, 139 insertions(+), 23 deletions(-)
diff --git a/common/lib/xTrending/store.test.ts b/common/lib/xTrending/store.test.ts
@@ -812,3 +812,98 @@ test("R3: a read of two tabs records each tab's sightings and ranks; gone is sai
assert.deepEqual(listing.posts.find((p) => p.id === "902")?.goneTabs?.map((g) => g.tab), ["Top"]);
assert.equal(members["902"].seen.at(-1)?.tab, "Latest");
});
+
+// ── review 2 (lane x-followups): M2 and ruling R-d ─────────────────────────
+
+test("M2: a post seen only by reads from before tabs is not marked gone by a complete Latest read while Top stopped at its cap", async () => {
+ const dir = root("m2-untagged");
+ const at = (h: number) => `2026-11-17T${String(h).padStart(2, "0")}:00:00.000Z`;
+ await writeXTrendingPosts(dir, ["601", "602"].map((p) => post(p, "a", `post ${p}`)));
+ // A read from before tabs were read: its sightings name no tab (the page opened on Top).
+ await recordXTrendingRead(dir, { readId: READ_A, at: at(9), ref: REF, topic: "T", postIds: ["601", "602"], added: 2 });
+ // A two-tab read: Top stopped at its post cap (it shows 602 only), Latest read to its end, and neither shows 601.
+ const twoTabs = (readId: string, h: number, topComplete: boolean) =>
+ recordXTrendingRead(dir, {
+ readId,
+ at: at(h),
+ ref: REF,
+ topic: "T",
+ page: PAGE,
+ postIds: ["602"],
+ added: 0,
+ tabReads: [
+ { tab: "Top", timelineId: "tl-top", postIds: ["602"], ...(topComplete ? { complete: true } : {}) },
+ { tab: "Latest", timelineId: "tl-latest", postIds: [], complete: true },
+ ],
+ });
+ const capped = await twoTabs(READ_B, 10, false);
+ assert.deepEqual([capped.gone, capped.goneFromTab], [[], undefined]);
+ let members = await readXTrendingMembership(dir);
+ assert.equal(members["601"].gone, undefined);
+ assert.equal(members["601"].goneTabs, undefined, "Latest never showed it: it is not Latest's to judge");
+ // Only a complete read of the tab the page opens on judges it: then it is gone from Top, which was the only tab that showed it.
+ const READ_D = "tr-01JD0000000000000000000000";
+ const complete = await twoTabs(READ_D, 11, true);
+ assert.deepEqual(complete.gone, ["601"]);
+ members = await readXTrendingMembership(dir);
+ assert.deepEqual(Object.keys(members["601"].goneTabs ?? {}), ["Top"]);
+ assert.deepEqual(members["601"].gone, { at: at(11), read: READ_D, trendId: REF.trendId });
+});
+
+test("M2: a read that cannot name its tab still judges sightings that name none; a named read of another tab never does", async () => {
+ const dir = root("m2-unnamed");
+ const at = (h: number) => `2026-11-17T${String(h).padStart(2, "0")}:00:00.000Z`;
+ await recordXTrendingRead(dir, { readId: READ_A, at: at(9), ref: REF, topic: "T", postIds: ["611", "612"], added: 2 });
+ // Latest, named, read to its end: not its to judge.
+ const latest = await recordXTrendingRead(dir, { readId: READ_B, at: at(10), ref: REF, topic: "T", postIds: ["612"], added: 0, tab: "Latest", complete: true });
+ assert.deepEqual(latest.gone, []);
+ // An unnamed complete read: it is.
+ const unnamed = await recordXTrendingRead(dir, { readId: READ_C, at: at(11), ref: REF, topic: "T", postIds: ["612"], added: 0, complete: true });
+ assert.deepEqual(unnamed.gone, ["611"]);
+});
+
+test("R-d: gone from the PAGE needs every tab that showed the post to drop it IN THE SAME READ; marks from different reads stay per tab", async () => {
+ const dir = root("rd-same-read");
+ const at = (h: number) => `2026-11-17T${String(h).padStart(2, "0")}:00:00.000Z`;
+ const id = (n: number) => `tr-01J${String.fromCharCode(64 + n)}0000000000000000000000`;
+ const read = (n: number, top: string[], latest: string[], complete: { top?: boolean; latest?: boolean }) =>
+ recordXTrendingRead(dir, {
+ readId: id(n),
+ at: at(8 + n),
+ ref: REF,
+ topic: "T",
+ page: PAGE,
+ postIds: [...new Set([...top, ...latest])],
+ added: 0,
+ tabReads: [
+ { tab: "Top", timelineId: "tl-top", postIds: top, ...(complete.top ? { complete: true } : {}) },
+ { tab: "Latest", timelineId: "tl-latest", postIds: latest, ...(complete.latest ? { complete: true } : {}) },
+ ],
+ });
+ await writeXTrendingPosts(dir, ["621", "622"].map((p) => post(p, "a", `post ${p}`)));
+ // Read 1: both tabs show 621 and 622.
+ await read(1, ["621", "622"], ["621", "622"], { top: true, latest: true });
+ // Read 2: Latest to its end without 621; Top capped (it showed 622 only).
+ const second = await read(2, ["622"], ["622"], { latest: true });
+ assert.deepEqual([second.gone, second.goneFromTab], [[], [{ id: "621", tab: "Latest" }]]);
+ // Read 3: Top to its end without 621; Latest capped. Gone from Top now, and from Latest since read 2 — two reads: not gone from the page.
+ const third = await read(3, ["622"], ["622"], { top: true });
+ assert.deepEqual([third.gone, third.goneFromTab], [[], [{ id: "621", tab: "Top" }]]);
+ let members = await readXTrendingMembership(dir);
+ assert.equal(members["621"].gone, undefined);
+ assert.deepEqual(Object.keys(members["621"].goneTabs ?? {}).sort(), ["Latest", "Top"]);
+ assert.deepEqual(members["621"].goneTabs?.Latest?.read, id(2));
+ assert.deepEqual(members["621"].goneTabs?.Top?.read, id(3));
+ // The listing says each tab, with its own time — never "gone from the page".
+ const listing = await listXTrending(dir);
+ assert.equal(listing.posts.find((p) => p.id === "621")?.gone, undefined);
+ assert.deepEqual(listing.posts.find((p) => p.id === "621")?.goneTabs?.map((g) => [g.tab, g.read]), [["Latest", id(2)], ["Top", id(3)]]);
+ // Read 4: both tabs to their end, neither shows 621: gone from the page, by this read.
+ const fourth = await read(4, ["622"], ["622"], { top: true, latest: true });
+ assert.deepEqual(fourth.gone, ["621"]);
+ members = await readXTrendingMembership(dir);
+ assert.deepEqual(members["621"].gone, { at: at(12), read: id(4), trendId: REF.trendId });
+ // A post one tab still shows in the same read is never gone from the page, whatever the other tab says.
+ const fifth = await read(5, ["622"], [], { top: true, latest: true });
+ assert.deepEqual([fifth.gone, fifth.goneFromTab], [[], [{ id: "622", tab: "Latest" }]]);
+});
diff --git a/common/lib/xTrending/store.ts b/common/lib/xTrending/store.ts
@@ -412,9 +412,10 @@ export type XTrendingMember = {
gone?: XTrendingGone;
// GONE FROM ONE TAB (lane x-followups): per tab label ("" for a read that
// could not say its tab), the read of that tab that reached its end and did
- // not show the post. `gone` above is set once every tab that showed the
- // post has a mark here; a mark alone means "gone from that tab, still shown
- // by another".
+ // not show the post. `gone` above is set only when ONE read dropped the
+ // post from every tab that showed it (review 2, ruling R-d); marks here from
+ // different reads never add up to it. A mark alone means "gone from that
+ // tab at <time>".
goneTabs?: Record<string, XTrendingGone>;
// Earlier absences that ended: gone from `from`, shown again at `to`.
wasGone?: Array<{ from: string; to: string }>;
@@ -771,7 +772,11 @@ export async function recordXTrendingRead(channelRoot: string, input: RecordRead
}
}
await writeJsonAtomic(topicsPath(channelRoot), { version: 1, topics } satisfies TopicsFile, { mkdir: true });
- return { id: found.id, title: found.title, created, ...(renamed ? { renamed } : {}), tabReads, tabLabels };
+ // THE TAB THE PAGE OPENS ON (the reader reads it first, as "Top"): the
+ // source's first known tab, else a tab of that name. A sighting that
+ // names no tab was this tab's (review 2 M2).
+ const openingTab = source.tabs?.[0]?.label ?? tabReads.find((t) => t.tab?.trim().toLowerCase() === "top")?.tab;
+ return { id: found.id, title: found.title, created, ...(renamed ? { renamed } : {}), tabReads, tabLabels, openingTab };
});
const counts = await withJsonFileLock(membershipPath(channelRoot), async () => {
const posts = await readXTrendingMembership(channelRoot);
@@ -821,30 +826,46 @@ export async function recordXTrendingRead(channelRoot: string, input: RecordRead
});
}
// GONE, TAB BY TAB. A tab read to its end marks the posts THAT TAB showed
- // before and does not show now (`goneTabs[<tab>]`). A post is gone from
- // the PAGE (`gone`) once every tab that showed it has such a mark; until
- // then it is "gone from <tab>, still shown by <the other>".
+ // before and does not show now (`goneTabs[<tab>]`): "gone from <tab> at
+ // <time>". A mark stays per tab and per read.
//
- // WHICH SIGHTINGS A TAB'S READ JUDGES: its own tab's, and those that name
- // no tab (a read from before tabs were read: the tab the page opens on).
- // A read that cannot say its tab judges only sightings that name none.
- for (const tabRead of topic.tabReads) {
- if (!tabRead.complete) continue;
- const key = tabRead.tab ?? "";
- const shown = new Set(tabRead.postIds);
+ // GONE FROM THE PAGE (`gone`; review 2, ruling R-d) only when EVERY tab
+ // that showed the post dropped it IN THIS READ: each of its earlier
+ // sightings is judged by a tab this read read to its end without it, and
+ // no tab of this read shows it. Marks from different reads ("gone from
+ // Latest" at one read, "from Top" at a later one) never combine into it.
+ //
+ // WHICH SIGHTINGS A TAB'S READ JUDGES (review 2 M2): its own tab's. A
+ // sighting that names no tab (a read from before tabs were read) was the
+ // OPENING tab's: only a complete read of that tab judges it — or a read
+ // that cannot name its own tab. A read that cannot say its tab judges
+ // only sightings that name none.
+ const judges = (s: XTrendingSeen, tabRead: { tab?: string }) =>
+ s.tab !== undefined
+ ? tabRead.tab !== undefined && s.tab === tabRead.tab
+ : tabRead.tab === undefined || (topic.openingTab !== undefined && tabRead.tab === topic.openingTab);
+ const shownNow = new Set(topic.tabReads.flatMap((t) => t.postIds));
+ const completeReads = topic.tabReads.filter((t) => t.complete);
+ if (completeReads.length) {
for (const [id, m] of Object.entries(posts)) {
- if (shown.has(id) || m.gone || m.goneTabs?.[key]) continue;
- const ofPage = m.seen.filter((s) => s.trendId === input.ref.trendId);
- if (!ofPage.some((s) => s.read !== input.readId && s.at < input.at && (s.tab === undefined || s.tab === tabRead.tab))) continue;
+ if (m.gone) continue;
+ const earlier = m.seen.filter((s) => s.trendId === input.ref.trendId && s.read !== input.readId && s.at < input.at);
+ if (earlier.length === 0) continue;
+ const droppedBy = completeReads.filter((t) => !t.postIds.includes(id) && earlier.some((s) => judges(s, t)));
+ if (droppedBy.length === 0) continue;
const mark: XTrendingGone = { at: input.at, read: input.readId, trendId: input.ref.trendId };
- (m.goneTabs ??= {})[key] = mark;
- const named = [...new Set(ofPage.map((s) => s.tab).filter((t): t is string => t !== undefined))];
- const tabsSeen = named.length ? named : [key];
- if (tabsSeen.every((t) => m.goneTabs?.[t])) {
+ const marked: string[] = [];
+ for (const t of droppedBy) {
+ const key = t.tab ?? "";
+ if (m.goneTabs?.[key]) continue;
+ (m.goneTabs ??= {})[key] = mark;
+ if (t.tab) marked.push(t.tab);
+ }
+ if (!shownNow.has(id) && earlier.every((s) => droppedBy.some((t) => judges(s, t)))) {
m.gone = mark;
gone.push(id);
- } else if (tabRead.tab) {
- goneFromTab.push({ id, tab: tabRead.tab });
+ } else {
+ for (const tab of marked) goneFromTab.push({ id, tab });
}
}
}