Skip to content

Commit 84396b3

Browse files
only21milclaude
andcommitted
fix(github): pull request activity reports a rate-limited review-thread read instead of hiding its threads
When GitHub refused only the review-thread read with a rate limit or a held pause, the activity read swallowed the error and returned zero threads marked truncated. Clients showed "partially loaded" and the result was cached as a success. The thread read now lets rate-limit errors through, as getViewerPermissions does, so the activity read fails as rate-limited, the same as when the remarks read is limited. Other thread-read failures still degrade to the truncated fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 25bf84a commit 84396b3

2 files changed

Lines changed: 70 additions & 14 deletions

File tree

‎packages/source-control-github/src/server/GitHubPullRequestProvider.test.ts‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
33
import * as Layer from "effect/Layer";
44
import * as Redacted from "effect/Redacted";
55
import * as TestClock from "effect/testing/TestClock";
6-
import type { PullRequestReaction } from "@t3tools/contracts";
6+
import { SourceControlProviderKind, type PullRequestReaction } from "@t3tools/contracts";
77

88
import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts";
99
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
@@ -757,7 +757,7 @@ describe("getChangeRequest commits", () => {
757757
);
758758
});
759759

760-
describe("getChangeRequestActivity dismissed reviews", () => {
760+
describe("getChangeRequestActivity", () => {
761761
const dismissedReview = (body: string) => ({
762762
id: "PRR_1",
763763
kind: "review" as const,
@@ -811,6 +811,58 @@ describe("getChangeRequestActivity dismissed reviews", () => {
811811
Effect.provide(layerFor("<!-- Macroscope (Approvability) review body marker -->")),
812812
),
813813
);
814+
815+
const failingThreadRead = (error: GitHubPullRequestApi.GitHubPullRequestApiError) =>
816+
Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({
817+
getPullRequestActivity: () => Effect.succeed({ author: null, comments: [], commits: [] }),
818+
listReviewThreadComments: () => Effect.fail(error),
819+
});
820+
const retryAt = 1_900_000_000_000;
821+
822+
it.effect.each([
823+
{
824+
name: "rate limit",
825+
error: new GitHubRequestPolicy.GitHubApiRateLimitError({
826+
host: "github.com",
827+
operation: "listReviewThreadComments",
828+
retryAt,
829+
}),
830+
},
831+
{
832+
name: "rate-limit pause",
833+
error: new SourceControlRateLimit.SourceControlRateLimitPausedError({
834+
provider: SourceControlProviderKind.make("github"),
835+
host: "github.com",
836+
retryAt,
837+
}),
838+
},
839+
])("fails rate-limited when the review-thread read hits a $name", ({ error }) =>
840+
readActivity.pipe(
841+
Effect.flip,
842+
Effect.map((failure) => expect(failure).toMatchObject({ reason: "rate-limited", retryAt })),
843+
Effect.provide(failingThreadRead(error)),
844+
),
845+
);
846+
847+
it.effect(
848+
"keeps activity with truncated threads when the review-thread read fails otherwise",
849+
() =>
850+
readActivity.pipe(
851+
Effect.map((activity) => {
852+
expect(activity.reviewThreads).toEqual([]);
853+
expect(activity.reviewThreadsTruncated).toBe(true);
854+
}),
855+
Effect.provide(
856+
failingThreadRead(
857+
new GitHubRequestPolicy.GitHubApiResponseError({
858+
host: "github.com",
859+
operation: "listReviewThreadComments",
860+
status: 500,
861+
}),
862+
),
863+
),
864+
),
865+
);
814866
});
815867

816868
describe("loginAvatarUrl", () => {

‎packages/source-control-github/src/server/GitHubPullRequestProvider.ts‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,14 @@ export const make = Effect.gen(function* () {
495495
Effect.mapError(fail("getChangeRequest")),
496496
),
497497

498-
getChangeRequestActivity: (input) =>
499-
Effect.all(
500-
[
501-
cli.getPullRequestActivity(input),
502-
cli.listReviewThreadComments(input).pipe(
503-
Effect.orElseSucceed(() => ({
498+
getChangeRequestActivity: (input) => {
499+
const threadRead = cli.listReviewThreadComments(input).pipe(
500+
Effect.catchIf(
501+
(error) =>
502+
error._tag !== "GitHubApiRateLimitError" &&
503+
error._tag !== "SourceControlRateLimitPausedError",
504+
() =>
505+
Effect.succeed({
504506
comments: [],
505507
dismissalsByReviewId: new Map<string, string>(),
506508
reactions: [],
@@ -515,11 +517,12 @@ export const make = Effect.gen(function* () {
515517
botLogins: new Set<string>(),
516518
commits: [],
517519
viewer: { canUpdate: true, didAuthor: false },
518-
})),
519-
),
520-
],
521-
{ concurrency: 2 },
522-
).pipe(
520+
}),
521+
),
522+
);
523+
return Effect.all([cli.getPullRequestActivity(input), threadRead], {
524+
concurrency: 2,
525+
}).pipe(
523526
Effect.mapError(fail("getChangeRequestActivity")),
524527
Effect.map(([pullRequest, reviewThreads]): ProviderChangeRequestActivity => {
525528
const commitStats = new Map(
@@ -590,7 +593,8 @@ export const make = Effect.gen(function* () {
590593
})),
591594
};
592595
}),
593-
),
596+
);
597+
},
594598

595599
getReviewThreadComments: (input) =>
596600
cli.getReviewThreadComments(input).pipe(Effect.mapError(fail("getReviewThreadComments"))),

0 commit comments

Comments
 (0)