@devries-cameron20 / t3code-1 / commits / cfa69444d3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(gitlab): show authentication and rate-limit errors from activity reads (#18817)

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 05:34 UTC cfa69444d334ea0fd22582f962d8ccdfd19d07e8
3 files changed +210 -15
apps/server/src/pullRequest/PullRequestService.test.ts
+85 -2
@@ -1,10 +1,10 @@
1 -import { SourceControlProviderKind } from "@t3tools/contracts";
1 +import { SourceControlProviderKind, VcsProcessExitError } from "@t3tools/contracts";
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import * as NodeV8 from "node:v8";
4 import * as NodeVM from "node:vm";
5 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
6 import * as KeyValueStore from "effect/persistence/KeyValueStore";
7 -import { assert, it } from "@effect/vitest";
7 +import { assert, expect, it } from "@effect/vitest";
8 import * as Cause from "effect/Cause";
9 import * as Clock from "effect/Clock";
10 import * as Deferred from "effect/Deferred";
@@ -34,6 +34,9 @@ import * as PullRequestFilesViewed from "../persistence/PullRequestFilesViewed.t
34 import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
35 import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
36 import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
37 +import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";
38 +import * as GitLabPullRequestCli from "@t3tools/source-control-gitlab/server/GitLabPullRequestCli";
39 +import * as GitLabPullRequestProvider from "@t3tools/source-control-gitlab/server/GitLabPullRequestProvider";
40 import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";
41 import * as ForgejoPullRequestProvider from "@t3tools/source-control-forgejo/server/ForgejoPullRequestProvider";
42 import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
@@ -7856,6 +7859,86 @@ it.effect.each([
7859 }),
7860 );
7861
7862 +it.effect("pauses uncached GitLab activity after only the reactions endpoint is rate limited", () =>
7863 + Effect.gen(function* () {
7864 + let commandCalls = 0;
7865 + const provider = yield* GitLabPullRequestProvider.make.pipe(
7866 + Effect.provide(
7867 + GitLabPullRequestCli.layer.pipe(
7868 + Layer.provide(GitLabCli.layer),
7869 + Layer.provide(
7870 + TestSourceControlHost.layer({
7871 + process: {
7872 + run: (input) =>
7873 + Effect.suspend(() => {
7874 + commandCalls += 1;
7875 + return input.args[1] === "graphql"
7876 + ? Effect.fail(
7877 + new VcsProcessExitError({
7878 + operation: input.operation,
7879 + command: input.command,
7880 + cwd: input.cwd,
7881 + exitCode: 1,
7882 + detail: "API rate limit exceeded.",
7883 + failureKind: "rate-limited",
7884 + }),
7885 + )
7886 + : Effect.succeed(TestSourceControlHost.processOutput("[]"));
7887 + }),
7888 + },
7889 + }),
7890 + ),
7891 + ),
7892 + ),
7893 + );
7894 + const service = yield* makeService({
7895 + projects: [
7896 + project({
7897 + id: "p1",
7898 + title: "web",
7899 + workspaceRoot: "/repo",
7900 + repository: "acme/web",
7901 + provider: "gitlab",
7902 + host: "gitlab.example.test",
7903 + }),
7904 + ],
7905 + providers: [provider],
7906 + });
7907 + const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
7908 +
7909 + expect(yield* Effect.result(service.activity(reference))).toMatchObject({
7910 + _tag: "Failure",
7911 + failure: {
7912 + _tag: "PullRequestOperationError",
7913 + cause: {
7914 + _tag: "PullRequestProviderError",
7915 + reason: "rate-limited",
7916 + cause: { _tag: "GitLabCliRateLimitError" },
7917 + },
7918 + },
7919 + });
7920 + const firstCommandCalls = commandCalls;
7921 + assert.isAbove(firstCommandCalls, 0);
7922 +
7923 + // A different merge request cannot reuse the first request's cached failure.
7924 + expect(yield* Effect.result(service.activity({ ...reference, number: 2 }))).toMatchObject({
7925 + _tag: "Failure",
7926 + failure: {
7927 + _tag: "PullRequestOperationError",
7928 + cause: {
7929 + _tag: "PullRequestProviderError",
7930 + reason: "rate-limited",
7931 + cause: {
7932 + _tag: "SourceControlRateLimitPausedError",
7933 + host: "gitlab.example.test",
7934 + },
7935 + },
7936 + },
7937 + });
7938 + assert.strictEqual(commandCalls, firstCommandCalls);
7939 + }),
7940 +);
7941 +
7942 it.effect("expands only files the change request changes, across every slice of its diff", () =>
7943 Effect.gen(function* () {
7944 const read: Array<string> = [];
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts
+101
@@ -2,6 +2,7 @@ import { assert, describe, expect, it, vi } from "@effect/vitest";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4
5 +import * as GitLabCli from "./GitLabCli.ts";
6 import * as GitLabPullRequestCli from "./GitLabPullRequestCli.ts";
7 import { gitLabViewerPermissions, make } from "./GitLabPullRequestProvider.ts";
8
@@ -264,3 +265,103 @@ describe("expanding unchanged lines", () => {
265 }),
266 );
267 });
268 +
269 +describe("optional activity reads", () => {
270 + const reference = { cwd: "/w", repository: "acme/web", host: "gitlab.com", number: 7 };
271 + const comment = {
272 + id: "42",
273 + kind: "issue-comment" as const,
274 + author: null,
275 + body: "Keep this comment",
276 + createdAt: "2026-07-01T00:00:00Z",
277 + url: null,
278 + path: null,
279 + reviewState: null,
280 + };
281 + const commit = {
282 + oid: "abc",
283 + messageHeadline: "Keep this commit",
284 + committedDate: "2026-07-01T00:00:00Z",
285 + };
286 + const reads = {
287 + listNotes: () => Effect.succeed({ comments: [comment], truncated: false }),
288 + listCommits: () => Effect.succeed([commit]),
289 + listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),
290 + listReactions: () => Effect.succeed({ reactions: [], reactionsByNoteId: new Map() }),
291 + };
292 + const context = {
293 + operation: "execute" as const,
294 + command: "glab" as const,
295 + cwd: "/w",
296 + cause: null,
297 + };
298 +
299 + it.effect.each([
300 + {
301 + operation: "listNotes",
302 + error: new GitLabCli.GitLabCliAuthenticationError(context),
303 + reason: "unauthenticated",
304 + },
305 + {
306 + operation: "listCommits",
307 + error: new GitLabCli.GitLabCliUnavailableError(context),
308 + reason: "missing-tool",
309 + },
310 + ] as const)(
311 + "reports $reason instead of successful partial activity",
312 + ({ operation, error, reason }) =>
313 + Effect.gen(function* () {
314 + const provider = yield* make.pipe(
315 + Effect.provide(
316 + Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
317 + ...reads,
318 + [operation]: () => Effect.fail(error),
319 + }),
320 + ),
321 + );
322 +
323 + expect(yield* Effect.result(provider.getChangeRequestActivity(reference))).toMatchObject({
324 + _tag: "Failure",
325 + failure: {
326 + _tag: "PullRequestProviderError",
327 + provider: "gitlab",
328 + operation: "getChangeRequestActivity",
329 + reason,
330 + detail: error.detail,
331 + cause: error,
332 + },
333 + });
334 + }),
335 + );
336 +
337 + it.effect("keeps comments and commits when optional discussions and reactions fail", () =>
338 + Effect.gen(function* () {
339 + const provider = yield* make.pipe(
340 + Effect.provide(
341 + Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
342 + ...reads,
343 + listDiscussions: () =>
344 + Effect.fail(
345 + new GitLabPullRequestCli.GitLabMergeRequestReadError({
346 + command: "glab",
347 + cwd: "/w",
348 + operation: "listDiscussions",
349 + cause: null,
350 + }),
351 + ),
352 + listReactions: () => Effect.fail(new GitLabCli.GitLabCliCommandError(context)),
353 + }),
354 + ),
355 + );
356 +
357 + expect(yield* provider.getChangeRequestActivity(reference)).toEqual({
358 + comments: [{ ...comment, reactions: [] }],
359 + commentCount: 1,
360 + commentsTruncated: true,
361 + reviewThreads: [],
362 + reactions: [],
363 + commits: [commit],
364 + });
365 + }),
366 + );
367 +});
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+24 -13
@@ -95,6 +95,23 @@ export const make = Effect.gen(function* () {
95 cause: error,
96 });
97
98 + // Optional endpoints may lose part of the activity, but an unusable CLI or account must
99 + // reach the caller so it can report authentication failures and pause a throttled host.
100 + const recoverRead = <A>(
101 + read: Effect.Effect<A, GitLabPullRequestCli.GitLabPullRequestCliError>,
102 + fallback: A,
103 + ) =>
104 + read.pipe(
105 + Effect.catch((error) => {
106 + const { reason } = gitLabProviderFailure(error);
107 + return reason === "rate-limited" ||
108 + reason === "unauthenticated" ||
109 + reason === "missing-tool"
110 + ? Effect.fail(error)
111 + : Effect.succeed(fallback);
112 + }),
113 + );
114 +
115 const provider: PullRequestProviderApi = {
116 kind: SourceControlProviderKind.make("gitlab"),
117 capabilities: CAPABILITIES,
@@ -155,19 +172,13 @@ export const make = Effect.gen(function* () {
172 getChangeRequestActivity: (input) =>
173 Effect.all(
174 [
158 - cli
159 - .listNotes(input)
160 - .pipe(Effect.orElseSucceed(() => ({ comments: [], truncated: true }))),
161 - cli.listCommits(input).pipe(Effect.orElseSucceed(() => [])),
162 - cli
163 - .listDiscussions(input)
164 - .pipe(Effect.orElseSucceed(() => ({ threads: [], truncated: true }))),
165 - cli.listReactions(input).pipe(
166 - Effect.orElseSucceed(() => ({
167 - reactions: [] as ReadonlyArray<PullRequestReaction>,
168 - reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
169 - })),
170 - ),
175 + recoverRead(cli.listNotes(input), { comments: [], truncated: true }),
176 + recoverRead(cli.listCommits(input), []),
177 + recoverRead(cli.listDiscussions(input), { threads: [], truncated: true }),
178 + recoverRead(cli.listReactions(input), {
179 + reactions: [] as ReadonlyArray<PullRequestReaction>,
180 + reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
181 + }),
182 ],
183 { concurrency: 4 },
184 ).pipe(