The best way to control Claude Code, Codex and more from any computer or phone
fix(github): Load more no longer stalls on a full page of equal update times (#36910)
Julius Marminge committed
Nov 14, 2026 at 12:36 UTC
3f92b488dbbc554605e938d7d9e22a4e229e90fa
5 files changed
+229
-67
apps/server/src/pullRequest/PullRequestService.test.ts
+7
-1
@@ -3017,7 +3017,13 @@ it.effect("carries a slice on without sending the rows it already sent", () =>
3017
cursors: { "github.com acme/web": "2026-07-02T00:00:00Z|1|3" },
3018
});
3019
3020
- assert.deepStrictEqual(cursors, [{ updatedBefore: "2026-07-02T00:00:00Z", delivered: 1 }]);
3020
+ assert.deepStrictEqual(cursors, [
3021
+ {
3022
+ updatedBefore: "2026-07-02T00:00:00Z",
3023
+ delivered: 1,
3024
+ seenAt: [{ repository: "acme/web", number: 3 }],
3025
+ },
3026
+ ]);
3027
assert.deepStrictEqual(
3028
result.entries.map((entry) => entry.number),
3029
[4],
apps/server/src/pullRequest/PullRequestService.ts
+12
-1
@@ -1550,7 +1550,18 @@ export const make = Effect.gen(function* () {
1550
filters: input.filters,
1551
...(cursor === undefined
1552
? {}
1553
- : { cursor: { updatedBefore: cursor.updatedBefore, delivered: cursor.delivered } }),
1553
+ : {
1554
+ cursor: {
1555
+ updatedBefore: cursor.updatedBefore,
1556
+ delivered: cursor.delivered,
1557
+ seenAt: chunk.flatMap((project) =>
1558
+ (cursorOf(project)?.seenAt ?? []).map((number) => ({
1559
+ repository: project.repository,
1560
+ number,
1561
+ })),
1562
+ ),
1563
+ },
1564
+ }),
1565
}).pipe(
1566
observeRead,
1567
Effect.flatMap(({ value: page, observedAt }) => {
packages/source-control-core/src/server/PullRequestProvider.ts
+11
-1
@@ -176,6 +176,16 @@ export interface ProviderListCursor {
176
readonly resumeAfter?: string | undefined;
177
}
178
179
+/** One search spans several repositories, so the rows seen at the boundary name theirs. */
180
+export interface ProviderAcrossListCursor extends Omit<ProviderListCursor, "seenAt"> {
181
+ readonly seenAt?: ReadonlyArray<ProviderRepositoryNumber> | undefined;
182
+}
183
+
184
+export interface ProviderRepositoryNumber {
185
+ readonly repository: string;
186
+ readonly number: number;
187
+}
188
+
189
export interface ProviderBatchedChangeRequest extends ProviderChangeRequest {
190
readonly repository: string;
191
}
@@ -357,7 +367,7 @@ export interface PullRequestProviderApi {
367
readonly viewer: string;
368
readonly limit: number;
369
readonly query?: string | undefined;
360
- readonly cursor?: ProviderListCursor | undefined;
370
+ readonly cursor?: ProviderAcrossListCursor | undefined;
371
readonly filters?: PullRequestListFilters | undefined;
372
}) => Effect.Effect<ProviderBatchedChangeRequestPage, PullRequestProviderError>;
373
packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
+107
@@ -2009,6 +2009,113 @@ layer("GitHubPullRequestApi.layer", (it) => {
2009
}),
2010
);
2011
2012
+ it.effect("skips the rows already delivered at a tied boundary before applying the limit", () =>
2013
+ Effect.gen(function* () {
2014
+ // Twenty pull requests share the boundary instant, then five are older. GitHub's search
2015
+ // has no qualifier for a row number, so the boundary always comes back from its start.
2016
+ const repository = { nameWithOwner: "acme/web" };
2017
+ const tied = rows(20, 1, () => ({ repository }));
2018
+ const older = rows(5, 21, () => ({ updatedAt: "2026-07-01T00:00:00Z", repository }));
2019
+ mockedExecute.mockImplementation((call) => {
2020
+ const variables = call.kind === "graphql" ? (call.variables ?? {}) : {};
2021
+ const q = String(variables["q"] ?? "");
2022
+ const bound = /updated:<=(\S+)/.exec(q)?.[1];
2023
+ const matching = [...tied, ...older].filter(
2024
+ (row) => bound === undefined || String(row["updatedAt"]) <= bound,
2025
+ );
2026
+ const start = variables["after"] == null ? 0 : Number(variables["after"]);
2027
+ const end = start + Number(variables["first"]);
2028
+ const hasNextPage = end < matching.length;
2029
+ return Effect.succeed(
2030
+ output(
2031
+ encodeJson({
2032
+ data: {
2033
+ search: {
2034
+ pageInfo: { hasNextPage, endCursor: hasNextPage ? String(end) : null },
2035
+ nodes: matching.slice(start, end),
2036
+ },
2037
+ },
2038
+ }),
2039
+ ),
2040
+ );
2041
+ });
2042
+ const cli = yield* GitHubPullRequestApi.GitHubPullRequestApi;
2043
+
2044
+ const batch = yield* cli.listPullRequests({
2045
+ cwd: "/w",
2046
+ repository: "acme/web",
2047
+ host: "github.com",
2048
+ state: "open",
2049
+ involvement: "all",
2050
+ viewer: "bilal",
2051
+ limit: 10,
2052
+ cursor: {
2053
+ updatedBefore: "2026-07-02T00:00:00Z",
2054
+ delivered: 10,
2055
+ seenAt: Array.from({ length: 10 }, (_, index) => index + 1),
2056
+ },
2057
+ });
2058
+
2059
+ expect(batch.items.map((item) => item.number)).toEqual([
2060
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2061
+ ]);
2062
+
2063
+ const across = yield* cli.searchPullRequests({
2064
+ cwd: "/w",
2065
+ host: "github.com",
2066
+ repositories: ["acme/web"],
2067
+ state: "open",
2068
+ involvement: "all",
2069
+ viewer: "bilal",
2070
+ limit: 10,
2071
+ cursor: {
2072
+ updatedBefore: "2026-07-02T00:00:00Z",
2073
+ delivered: 10,
2074
+ seenAt: Array.from({ length: 10 }, (_, index) => ({
2075
+ repository: "acme/web",
2076
+ number: index + 1,
2077
+ })),
2078
+ },
2079
+ });
2080
+ expect(across.items.map((item) => item.number)).toEqual([
2081
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
2082
+ ]);
2083
+
2084
+ // Rows seen earlier that no longer match must not count as skipped, or the rest is lost.
2085
+ const moved = { updatedBefore: "2026-07-01T00:00:00Z", delivered: 10 };
2086
+ const listedPastMoved = yield* cli.listPullRequests({
2087
+ cwd: "/w",
2088
+ repository: "acme/web",
2089
+ host: "github.com",
2090
+ state: "open",
2091
+ involvement: "all",
2092
+ viewer: "bilal",
2093
+ limit: 3,
2094
+ cursor: { ...moved, seenAt: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] },
2095
+ });
2096
+ const searchedPastMoved = yield* cli.searchPullRequests({
2097
+ cwd: "/w",
2098
+ host: "github.com",
2099
+ repositories: ["acme/web"],
2100
+ state: "open",
2101
+ involvement: "all",
2102
+ viewer: "bilal",
2103
+ limit: 3,
2104
+ cursor: {
2105
+ ...moved,
2106
+ seenAt: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((number) => ({
2107
+ repository: "acme/web",
2108
+ number,
2109
+ })),
2110
+ },
2111
+ });
2112
+ for (const page of [listedPastMoved, searchedPastMoved]) {
2113
+ expect(page.items.map((item) => item.number)).toEqual([21, 22, 23]);
2114
+ expect(page.truncated).toBe(true);
2115
+ }
2116
+ }),
2117
+ );
2118
+
2119
it.effect("answers a search that found nothing with nothing, not with the whole repository", () =>
2120
Effect.gen(function* () {
2121
mockedExecute.mockReturnValueOnce(Effect.succeed(emptySearch()));
packages/source-control-github/src/server/GitHubPullRequestApi.ts
+92
-64
@@ -127,6 +127,7 @@ import {
127
} from "./gitHubPullRequestJson.ts";
128
import type {
129
ProviderChangeRequestSummary,
130
+ ProviderAcrossListCursor,
131
ProviderListCursor,
132
} from "@t3tools/source-control-core/server/PullRequestProvider";
133
@@ -387,12 +388,46 @@ const LIST_STATES: Record<PullRequestListState, ReadonlyArray<"OPEN" | "CLOSED"
388
merged: ["MERGED"],
389
};
390
390
-interface GitHubPullRequestListPage {
391
- readonly items: ReadonlyArray<GitHubPullRequestListItem>;
391
+interface GitHubPullRequestListPage<Item = GitHubPullRequestListItem> {
392
+ readonly items: ReadonlyArray<Item>;
393
readonly rawCount: number;
394
readonly endCursor: string | null;
395
}
396
397
+/**
398
+ * Pages of up to a hundred until `rows` have arrived or GitHub has no more. Each page asks
399
+ * for only the rows still missing, so the last one does not overshoot.
400
+ */
401
+const collect = Effect.fn("GitHubPullRequestApi.collect")(function* <Item, E>(
402
+ rows: number,
403
+ page: (after: string | null, rows: number) => Effect.Effect<GitHubPullRequestListPage<Item>, E>,
404
+) {
405
+ const countRows = (pages: ReadonlyArray<GitHubPullRequestListPage<Item>>) =>
406
+ pages.reduce((total, read) => total + read.rawCount, 0);
407
+ const pages: GitHubPullRequestListPage<Item>[] = [];
408
+ const seen = new Set<string>();
409
+ let after: string | null = null;
410
+ let truncated = false;
411
+ while (true) {
412
+ const read: GitHubPullRequestListPage<Item> = yield* page(after, rows - countRows(pages));
413
+ pages.push(read);
414
+ const next = read.endCursor;
415
+ if (next === null) break;
416
+ // `truncated` also covers a cursor GitHub repeated before `rows` arrived.
417
+ if (seen.has(next) || countRows(pages) >= rows) {
418
+ truncated = true;
419
+ break;
420
+ }
421
+ seen.add(next);
422
+ after = next;
423
+ }
424
+ return {
425
+ items: pages.flatMap((read) => read.items),
426
+ rawCount: countRows(pages),
427
+ truncated,
428
+ };
429
+});
430
+
431
const PULL_REQUEST_FALLBACK_MAX_ROWS = 1_000;
432
433
const DIFF_FILES_PAGE_SIZE = 100;
@@ -492,7 +527,7 @@ export class GitHubPullRequestApi extends Context.Service<
527
readonly viewer: string;
528
readonly limit: number;
529
readonly query?: string | undefined;
495
- readonly cursor?: ProviderListCursor | undefined;
530
+ readonly cursor?: ProviderAcrossListCursor | undefined;
531
readonly filters?: PullRequestListFilters | undefined;
532
}) => Effect.Effect<GitHubPullRequestSearchBatch, GitHubPullRequestApiError>;
533
@@ -893,7 +928,7 @@ function searchQuery(input: {
928
readonly involvement: PullRequestInvolvement;
929
readonly viewer: string;
930
readonly query?: string | undefined;
896
- readonly cursor?: ProviderListCursor | undefined;
931
+ readonly cursor?: Pick<ProviderListCursor, "updatedBefore"> | undefined;
932
readonly filters?: PullRequestListFilters | undefined;
933
}): string | null {
934
if (input.repositories.length === 0) return null;
@@ -1846,46 +1881,15 @@ export const make = Effect.gen(function* () {
1881
endCursor: page.endCursor,
1882
pageInfo: { hasNextPage: page.endCursor !== null, endCursor: page.endCursor },
1883
});
1849
- /**
1850
- * Pages of up to a hundred until `rows` have arrived or GitHub has no more. Each page asks
1851
- * for only the rows still missing, so the last one does not overshoot.
1852
- */
1853
- const collect = Effect.fn("GitHubPullRequestApi.collect")(function* (
1854
- rows: number,
1855
- page: (
1856
- after: string | null,
1857
- rows: number,
1858
- ) => Effect.Effect<GitHubPullRequestListPage, GitHubPullRequestApiError>,
1859
- ) {
1860
- const countRows = (pages: ReadonlyArray<GitHubPullRequestListPage>) =>
1861
- pages.reduce((total, read) => total + read.rawCount, 0);
1862
- const pages: GitHubPullRequestListPage[] = [];
1863
- const seen = new Set<string>();
1864
- let after: string | null = null;
1865
- let truncated = false;
1866
- while (true) {
1867
- const read: GitHubPullRequestListPage = yield* page(after, rows - countRows(pages));
1868
- pages.push(read);
1869
- const next = read.endCursor;
1870
- if (next === null) break;
1871
- // `truncated` also covers a cursor GitHub repeated before `rows` arrived.
1872
- if (seen.has(next) || countRows(pages) >= rows) {
1873
- truncated = true;
1874
- break;
1875
- }
1876
- seen.add(next);
1877
- after = next;
1878
- }
1879
- return {
1880
- items: pages.flatMap((read) => read.items),
1881
- rawCount: countRows(pages),
1882
- truncated,
1883
- };
1884
- });
1884
const stacks = input.host.toLowerCase() === "github.com";
1885
+ // Search cannot exclude numbers, so the rows already delivered at the boundary come back
1886
+ // first; read past them so they do not use up the limit.
1887
+ const seenAt = new Set(input.cursor?.seenAt ?? []);
1888
+ const isSeen = (item: GitHubPullRequestListItem) =>
1889
+ item.updatedAt === input.cursor?.updatedBefore && seenAt.has(item.number);
1890
const read = (
1891
continues: boolean,
1888
- requestedRows = input.limit + 1,
1892
+ requestedRows = input.limit + 1 + (continues ? seenAt.size : 0),
1893
): Effect.Effect<GitHubPullRequestListBatch, GitHubPullRequestApiError> =>
1894
collect(requestedRows, (after, rows) =>
1895
(continues
@@ -1918,7 +1922,7 @@ export const make = Effect.gen(function* () {
1922
).pipe(
1923
Effect.flatMap(({ items: rawItems, rawCount, truncated: cutShort }) => {
1924
const items = continues
1921
- ? rawItems
1925
+ ? rawItems.filter((item) => !isSeen(item))
1926
: rawItems.filter((item) => matchesUnsortedListing(item, input));
1927
if (
1928
!continues &&
@@ -1935,7 +1939,7 @@ export const make = Effect.gen(function* () {
1939
truncated:
1940
cutShort ||
1941
(continues
1938
- ? rawCount > input.limit
1942
+ ? rawCount - (rawItems.length - items.length) > input.limit
1943
: items.length > input.limit || rawCount >= requestedRows),
1944
continues,
1945
});
@@ -2012,27 +2016,51 @@ export const make = Effect.gen(function* () {
2016
operation: "searchPullRequests",
2017
});
2018
}
2015
- const rows = Math.min(input.limit + 1, PULL_REQUEST_SEARCH_MAX_ROWS);
2016
- return yield* client
2017
- .PullRequestSearch({
2018
- q: query,
2019
- first: rows,
2020
- stacks: input.host.toLowerCase() === "github.com",
2021
- stats: false,
2022
- })
2023
- .pipe(
2024
- graphql({ ...input, operation: "searchPullRequests" }),
2025
- Effect.map(({ search }) => {
2026
- const page = toPullRequestRows(search);
2027
- const items = page.rows.flatMap(({ item, repository }) =>
2028
- repository === null ? [] : [{ ...item, repository }],
2029
- );
2030
- return {
2031
- items: items.slice(0, input.limit),
2032
- truncated: page.rawCount > input.limit || page.hasNextPage,
2033
- };
2034
- }),
2035
- );
2019
+ // Search cannot exclude numbers, so the rows already delivered at the boundary come back
2020
+ // first; read past them so they do not use up the limit.
2021
+ const seenAt = new Set(
2022
+ (input.cursor?.seenAt ?? []).map(
2023
+ ({ repository, number }) => `${repository.trim().toLowerCase()}#${number}`,
2024
+ ),
2025
+ );
2026
+ const stacks = input.host.toLowerCase() === "github.com";
2027
+ let endedShort = false;
2028
+ const {
2029
+ items: rawItems,
2030
+ rawCount,
2031
+ truncated,
2032
+ } = yield* collect(
2033
+ Math.min(input.limit + 1, PULL_REQUEST_SEARCH_MAX_ROWS) + seenAt.size,
2034
+ (after, rows) =>
2035
+ client
2036
+ .PullRequestSearch({ q: query, first: pageRows(rows), after, stacks, stats: false })
2037
+ .pipe(
2038
+ graphql({ ...input, operation: "searchPullRequests" }),
2039
+ Effect.map(({ search }) => {
2040
+ const page = toPullRequestRows(search);
2041
+ // A short page that says it has more is where this read stops, not a gap to read past.
2042
+ const short = page.endCursor !== null && page.rawCount < pageRows(rows);
2043
+ if (short) endedShort = true;
2044
+ return {
2045
+ items: page.rows.flatMap(({ item, repository }) =>
2046
+ repository === null ? [] : [{ ...item, repository }],
2047
+ ),
2048
+ rawCount: page.rawCount,
2049
+ endCursor: short ? null : page.endCursor,
2050
+ };
2051
+ }),
2052
+ ),
2053
+ );
2054
+ const items = rawItems.filter(
2055
+ (item) =>
2056
+ item.updatedAt !== input.cursor?.updatedBefore ||
2057
+ !seenAt.has(`${item.repository.trim().toLowerCase()}#${item.number}`),
2058
+ );
2059
+ return {
2060
+ items: items.slice(0, input.limit),
2061
+ truncated:
2062
+ truncated || endedShort || rawCount - (rawItems.length - items.length) > input.limit,
2063
+ };
2064
}),
2065
2066
listPullRequestStats: Effect.fn("GitHubPullRequestApi.listPullRequestStats")(