From 5f3281e50fb346b729f60f6007df41545414cddf Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Fri, 20 Nov 2026 01:49:35 +0530 Subject: [PATCH 1/2] fix(convex): a team feed page keeps a member's rows past their share batchScanConversations stops a batch once it has the rows it wants, then called the index exhausted whenever that batch was short, though it never read the rest of it. paginateTeamFeed then marked the member done, so a member whose remaining rows fit in one fetch but outnumbered their share of a page lost the rest for good. The web team feed hits this whenever its per-member fetch is larger than its per-member share. A short batch now ends the index only when it was read to its end. Codecast-Session: https://codecast.sh/conversation/jx79cm21j5mrr7qzwdvv3vd17d8jhz7s --- packages/convex/convex/feedPagination.test.ts | 16 +++++++++++++--- packages/convex/convex/feedPagination.ts | 8 ++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/convex/convex/feedPagination.test.ts b/packages/convex/convex/feedPagination.test.ts index 2b48880908..38f018f015 100644 --- a/packages/convex/convex/feedPagination.test.ts +++ b/packages/convex/convex/feedPagination.test.ts @@ -27,7 +27,10 @@ function makeFetchPage(tables: Record) { const acceptMain = (c: any) => !c.subagent; // Drain the feed to the end, asserting per-page invariants as we go. -async function drain(tables: Record, opts?: { limit?: number; startCursor?: string | null; maxPages?: number }) { +async function drain( + tables: Record, + opts?: { limit?: number; startCursor?: string | null; maxPages?: number; perMemberFetch?: number; perMemberWant?: number }, +) { const limit = opts?.limit ?? 5; let cursor: string | null = opts?.startCursor ?? null; const pages: any[][] = []; @@ -39,8 +42,8 @@ async function drain(tables: Record, opts?: { limit?: number; sta limit, fetchPage: makeFetchPage(tables), accept: acceptMain, - perMemberFetch: 4, - perMemberWant: 3, + perMemberFetch: opts?.perMemberFetch ?? 4, + perMemberWant: opts?.perMemberWant ?? 3, maxBatches: 2, }); pages.push(page.rows); @@ -94,6 +97,13 @@ describe("paginateTeamFeed", () => { expect(seen.size).toBe(6); }); + test("a member whose rows fit one batch keeps those past its share for the next page", async () => { + // One fetch reads all five rows and the page takes three: the other two lead the next page. + const tables = { a: member([{ t: 50 }, { t: 40 }, { t: 30 }, { t: 20 }, { t: 10 }], "a") }; + const { seen } = await drain(tables, { limit: 3, perMemberFetch: 10, perMemberWant: 3 }); + expect(seen.size).toBe(5); + }); + test("legacy numeric cursor is honored as a shared bound and upgrades to composite", async () => { const tables = { a: member([{ t: 100 }, { t: 80 }, { t: 60 }], "a"), diff --git a/packages/convex/convex/feedPagination.ts b/packages/convex/convex/feedPagination.ts index 7c023759fc..e5c3716221 100644 --- a/packages/convex/convex/feedPagination.ts +++ b/packages/convex/convex/feedPagination.ts @@ -29,15 +29,19 @@ export async function batchScanConversations(opts: { exhausted = true; break; } + // A scan that reaches `want` mid-batch has not examined the rest of it, + // so a short batch is the end of the index only when read to its end. + let examined = 0; for (const c of batch) { + examined++; if (accept(c)) { rows.push(c); if (rows.length >= want) break; } } - cursor = batch[batch.length - 1].updated_at; + cursor = batch[examined - 1].updated_at; oldestSeen = cursor; - if (batch.length < batchSize) { + if (examined === batch.length && batch.length < batchSize) { exhausted = true; break; } From 73624aa61ad1b0fc18038ad073b301ad56858913 Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Fri, 20 Nov 2026 02:59:56 +0530 Subject: [PATCH 2/2] fix(convex): the team feed pager ends when no member can be read With every member hidden, paginateTeamFeed had no member to scan and still answered a non-null cursor, so the web team feed asked for the same empty page again on every load. No member to read now ends the feed. Codecast-Session: https://codecast.sh/conversation/jx79cm21j5mrr7qzwdvv3vd17d8jhz7s --- packages/convex/convex/feedPagination.test.ts | 13 +++++++++++++ packages/convex/convex/feedPagination.ts | 2 ++ 2 files changed, 15 insertions(+) diff --git a/packages/convex/convex/feedPagination.test.ts b/packages/convex/convex/feedPagination.test.ts index 38f018f015..01df0dc997 100644 --- a/packages/convex/convex/feedPagination.test.ts +++ b/packages/convex/convex/feedPagination.test.ts @@ -104,6 +104,19 @@ describe("paginateTeamFeed", () => { expect(seen.size).toBe(5); }); + test("a team with no member to read ends at once", async () => { + const page = await paginateTeamFeed({ + memberIds: [], + cursor: null, + limit: 5, + fetchPage: makeFetchPage({}), + accept: acceptMain, + perMemberFetch: 4, + perMemberWant: 3, + }); + expect(page).toEqual({ rows: [], nextCursor: null }); + }); + test("legacy numeric cursor is honored as a shared bound and upgrades to composite", async () => { const tables = { a: member([{ t: 100 }, { t: 80 }, { t: 60 }], "a"), diff --git a/packages/convex/convex/feedPagination.ts b/packages/convex/convex/feedPagination.ts index e5c3716221..1421678be9 100644 --- a/packages/convex/convex/feedPagination.ts +++ b/packages/convex/convex/feedPagination.ts @@ -111,6 +111,8 @@ export async function paginateTeamFeed(opts: { maxBatches?: number; }): Promise<{ rows: any[]; nextCursor: string | null }> { const { memberIds, limit, fetchPage, accept, perMemberFetch, perMemberWant, maxBatches = 4 } = opts; + // No member to read (everyone hidden) is the end, not an empty page to repeat. + if (memberIds.length === 0) return { rows: [], nextCursor: null }; const { legacy, members } = parseFeedCursor(opts.cursor); const boundOf = (id: string): MemberBound => (members ? members[id] : legacy ?? undefined);