The best way to control Claude Code, Codex and more from any computer or phone
fix(gitlab): issue timelines keep system events past the first page of notes (#38101)
Julius Marminge committed
Nov 17, 2026 at 04:14 UTC
d3c91008059beb5fbc97b782f070f19dbb60f41b
2 files changed
+189
-33
packages/source-control-gitlab/src/server/GitLabIssueTracker.test.ts
+83
@@ -197,6 +197,89 @@ describe("GitLabIssueTracker", () => {
197
}),
198
);
199
200
+ it.effect("keeps system events after the first hundred notes in the issue timeline", () =>
201
+ Effect.gen(function* () {
202
+ const firstPage = Array.from({ length: 100 }, (_, index) => ({
203
+ id: index + 1000,
204
+ body: "Discussion",
205
+ author: { username: "julius" },
206
+ created_at: "2026-07-02T00:00:00Z",
207
+ }));
208
+ const api = yield* tracker((args) => {
209
+ const path = args[1]!;
210
+ if (path.includes("/notes?")) {
211
+ const page = new URLSearchParams(path.split("?")[1]).get("page");
212
+ if (page === "1") return encode(firstPage);
213
+ if (page === "2") {
214
+ return encode([
215
+ {
216
+ id: 1100,
217
+ body: "closed",
218
+ system: true,
219
+ author: { username: "theo" },
220
+ created_at: "2026-07-03T00:00:00Z",
221
+ },
222
+ ]);
223
+ }
224
+ return encode([]);
225
+ }
226
+ return answer(path);
227
+ });
228
+ const target = { cwd: "/w", host: "gitlab.com", scope: "acme/web", key: "42" };
229
+ const issue = yield* api.getIssue(target);
230
+ let cursor = issue.commentsCursor;
231
+ while (cursor !== null) {
232
+ cursor = (yield* api.getComments({ ...target, cursor })).nextCursor;
233
+ }
234
+ expect(issue.events).toContainEqual(
235
+ expect.objectContaining({ id: "note-1100", kind: "closed" }),
236
+ );
237
+ }),
238
+ );
239
+
240
+ it.effect("follows GitLab's next page past a short page of notes", () =>
241
+ Effect.gen(function* () {
242
+ const notes = (next: string, rows: ReadonlyArray<unknown>) =>
243
+ `HTTP/2.0 200 OK\r\nContent-Type: application/json\r\nX-Next-Page: ${next}\r\nX-Page: 1\r\n\r\n${encode(rows)}`;
244
+ const api = yield* tracker((args) => {
245
+ const path = args[1]!;
246
+ if (path.includes("/notes?")) {
247
+ const params = new URLSearchParams(path.split("?")[1]);
248
+ if (params.get("activity_filter") === "only_activity") {
249
+ return params.get("page") === "1"
250
+ ? notes("2", [])
251
+ : notes("", [
252
+ {
253
+ id: 300,
254
+ body: "closed",
255
+ system: true,
256
+ author: { username: "theo" },
257
+ created_at: "2026-07-03T00:00:00Z",
258
+ },
259
+ ]);
260
+ }
261
+ return notes("2", [
262
+ {
263
+ id: 1,
264
+ body: "Hi",
265
+ author: { username: "julius" },
266
+ created_at: "2026-07-02T00:00:00Z",
267
+ },
268
+ ]);
269
+ }
270
+ return answer(path);
271
+ });
272
+ const issue = yield* api.getIssue({
273
+ cwd: "/w",
274
+ host: "gitlab.com",
275
+ scope: "acme/web",
276
+ key: "42",
277
+ });
278
+ expect(issue.commentsCursor).toBe("2");
279
+ expect(issue.events.map((event) => event.id)).toEqual(["label-3", "note-300"]);
280
+ }),
281
+ );
282
+
283
it.effect("pages a listing by GitLab's page number and stops on a short page", () =>
284
Effect.gen(function* () {
285
const paths: string[] = [];
packages/source-control-gitlab/src/server/GitLabIssueTracker.ts
+106
-33
@@ -1,7 +1,7 @@
1
/**
2
- * GitLab's issue tracker over `glab api`. GitLab pages by offset and reports no total, so every
3
- * cursor is a page number and a full page is the only sign that more exists. Notes, label
4
- * events, linked merge requests and awards are separate endpoints, joined into the detail.
2
+ * GitLab's issue tracker over `glab api`. GitLab pages by offset, so every cursor is a page
3
+ * number. Notes, label events, linked merge requests and awards are separate endpoints, joined
4
+ * into the detail.
5
*/
6
import * as Effect from "effect/Effect";
7
import * as Result from "effect/Result";
@@ -9,6 +9,7 @@ import * as Schema from "effect/Schema";
9
import {
10
IssueTrackerKind,
11
type IssueCapabilities,
12
+ type IssueEvent,
13
type IssueInvolvement,
14
type IssueViewerPermissions,
15
} from "@t3tools/contracts";
@@ -43,6 +44,8 @@ import {
44
} from "./gitLabMergeRequestJson.ts";
45
46
const KIND = IssueTrackerKind.make("gitlab");
47
+/** How many pages of system notes the timeline reads before giving up on the rest. */
48
+const MAX_ACTIVITY_PAGES = 20;
49
50
const CAPABILITIES: IssueCapabilities = {
51
create: true,
@@ -108,6 +111,26 @@ function commentsCursor(notesNext: string | null, awardsNext: string | null): st
111
return awardsNext === null ? notesNext : `${notesNext}:${awardsNext}`;
112
}
113
114
+/**
115
+ * `glab api --include` output split into the body and GitLab's next page. GitLab can return a
116
+ * short page when it hides notes the viewer may not see, so only `X-Next-Page` says whether more
117
+ * exists; without headers a full page is taken as the sign.
118
+ */
119
+function splitPagedResponse(raw: string): {
120
+ readonly body: string;
121
+ readonly nextPage: number | null | undefined;
122
+} {
123
+ if (!raw.startsWith("HTTP/")) return { body: raw, nextPage: undefined };
124
+ const end = /\r?\n\r?\n/.exec(raw);
125
+ const headers = end === null ? raw : raw.slice(0, end.index);
126
+ const body = end === null ? "" : raw.slice(end.index + end[0].length);
127
+ const next = /^x-next-page:[ \t]*([1-9]\d{0,6})?[ \t]*\r?$/im.exec(headers);
128
+ return {
129
+ body,
130
+ nextPage: next === null ? undefined : next[1] === undefined ? null : Number(next[1]),
131
+ };
132
+}
133
+
134
function query(params: ReadonlyArray<readonly [string, string]>): string {
135
return params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
136
}
@@ -185,6 +208,7 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
208
readonly path: string;
209
readonly method?: string;
210
readonly body?: unknown;
211
+ readonly includeHeaders?: boolean;
212
}) =>
213
gitlab
214
.execute({
@@ -193,6 +217,7 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
217
args: [
218
"api",
219
input.path,
220
+ ...(input.includeHeaders === true ? ["--include"] : []),
221
...(input.method === undefined ? [] : ["--method", input.method]),
222
// A JSON body from stdin: argv is visible in process listings, and `glab api --input`
223
// sends no Content-Type of its own, which GitLab answers with HTTP 415.
@@ -214,6 +239,7 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
239
readonly path: string;
240
readonly method?: string;
241
readonly body?: unknown;
242
+ readonly includeHeaders?: boolean;
243
readonly decode: (raw: string) => Result.Result<A, unknown>;
244
}): Effect.Effect<A, IssueTrackerError> =>
245
api(input).pipe(
@@ -303,6 +329,7 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
329
readonly path: string;
330
readonly page: number;
331
readonly operation: string;
332
+ readonly onlyActivity?: boolean;
333
}) =>
334
read({
335
cwd: input.cwd,
@@ -313,14 +340,44 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
340
["page", String(input.page)],
341
["order_by", "created_at"],
342
["sort", "asc"],
343
+ ...(input.onlyActivity === true ? [["activity_filter", "only_activity"] as const] : []),
344
])}`,
317
- decode: decodeIssueNotesJson,
318
- }).pipe(
319
- Effect.map((notes) => ({
320
- ...notes,
321
- nextCursor: notes.rawCount < PAGE_SIZE ? null : String(input.page + 1),
322
- })),
323
- );
345
+ includeHeaders: true,
346
+ decode: (raw) => {
347
+ const { body, nextPage } = splitPagedResponse(raw);
348
+ return Result.map(decodeIssueNotesJson(body), (notes) => {
349
+ const next =
350
+ nextPage === undefined
351
+ ? notes.rawCount < PAGE_SIZE
352
+ ? null
353
+ : input.page + 1
354
+ : nextPage;
355
+ return { ...notes, nextCursor: next === null ? null : String(next) };
356
+ });
357
+ },
358
+ });
359
+
360
+ /** Every system note, wherever it falls among the comments, for the issue's timeline. */
361
+ const activity = Effect.fn("GitLabIssueTracker.activity")(function* (input: {
362
+ readonly cwd: string;
363
+ readonly host: string;
364
+ readonly path: string;
365
+ }) {
366
+ const events: Array<IssueEvent> = [];
367
+ let page = 1;
368
+ for (let count = 0; count < MAX_ACTIVITY_PAGES; count++) {
369
+ const notes = yield* notesPage({
370
+ ...input,
371
+ page,
372
+ operation: "getIssue",
373
+ onlyActivity: true,
374
+ });
375
+ events.push(...notes.events);
376
+ if (notes.nextCursor === null) break;
377
+ page = Number(notes.nextCursor);
378
+ }
379
+ return events;
380
+ });
381
382
const awards = (input: {
383
readonly cwd: string;
@@ -444,6 +501,7 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
501
page: 1,
502
operation: "getIssue",
503
}),
504
+ activity({ cwd: input.cwd, host: input.host, path }),
505
read({
506
cwd: input.cwd,
507
host: input.host,
@@ -469,29 +527,44 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
527
{ concurrency: 4 },
528
),
529
),
472
- Effect.map(([issue, viewerLogin, notes, labelEvents, closing, related, awardPage]) => {
473
- const closingKeys = new Set(closing.map((link) => `${link.repository}!${link.number}`));
474
- return {
475
- ...issue,
476
- viewer: viewerLogin,
477
- viewerPermissions: VIEWER_PERMISSIONS,
478
- states: ISSUE_STATES,
479
- reactions: awardPage.reactions,
480
- comments: notes.comments.map((comment) => ({
481
- ...comment,
482
- reactions: awardPage.reactionsByNoteId.get(comment.id) ?? [],
483
- })),
484
- commentsCursor: commentsCursor(notes.nextCursor, awardPage.nextCursor),
485
- events: [...notes.events, ...labelEvents].sort((left, right) =>
486
- left.createdAt.localeCompare(right.createdAt),
487
- ),
488
- // A merge request that closes the issue outranks its sighting as a mere mention.
489
- linkedPullRequests: [
490
- ...closing,
491
- ...related.filter((link) => !closingKeys.has(`${link.repository}!${link.number}`)),
492
- ],
493
- };
494
- }),
530
+ Effect.map(
531
+ ([
532
+ issue,
533
+ viewerLogin,
534
+ notes,
535
+ systemEvents,
536
+ labelEvents,
537
+ closing,
538
+ related,
539
+ awardPage,
540
+ ]) => {
541
+ const closingKeys = new Set(
542
+ closing.map((link) => `${link.repository}!${link.number}`),
543
+ );
544
+ return {
545
+ ...issue,
546
+ viewer: viewerLogin,
547
+ viewerPermissions: VIEWER_PERMISSIONS,
548
+ states: ISSUE_STATES,
549
+ reactions: awardPage.reactions,
550
+ comments: notes.comments.map((comment) => ({
551
+ ...comment,
552
+ reactions: awardPage.reactionsByNoteId.get(comment.id) ?? [],
553
+ })),
554
+ commentsCursor: commentsCursor(notes.nextCursor, awardPage.nextCursor),
555
+ events: [...systemEvents, ...labelEvents].sort((left, right) =>
556
+ left.createdAt.localeCompare(right.createdAt),
557
+ ),
558
+ // A merge request that closes the issue outranks its sighting as a mere mention.
559
+ linkedPullRequests: [
560
+ ...closing,
561
+ ...related.filter(
562
+ (link) => !closingKeys.has(`${link.repository}!${link.number}`),
563
+ ),
564
+ ],
565
+ };
566
+ },
567
+ ),
568
),
569
570
getComments: (input) => {