Skip to content

Commit ed9a7b2

Browse files
committed
fix(server): hold watch remarks when review threads are incomplete
1 parent 500391c commit ed9a7b2

11 files changed

Lines changed: 38 additions & 11 deletions

‎apps/server/src/orchestration-v2/PullRequestWatchReactor.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ export const make = Effect.gen(function* () {
129129

130130
const readRemarks = Effect.fn("PullRequestWatchReactor.readRemarks")(
131131
function* (reference: PullRequestRef, activity: PullRequestActivity) {
132-
// Truncation without a continuation means the initial thread read was incomplete.
133-
if (
134-
activity.commentsTruncated &&
135-
!activity.reviewThreads.some((thread) => thread.nextCommentsCursor !== undefined)
136-
)
137-
return null;
132+
// Comment cursors cannot account for missing threads. Only finish a truncated read
133+
// when the host confirms that every thread was listed.
134+
if (activity.commentsTruncated && activity.reviewThreadsTruncated !== false) return null;
138135

139136
const comments = new Map(activity.comments.map((comment) => [comment.id, comment]));
140137
for (const thread of activity.reviewThreads) {

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
23152315
"page failure",
23162316
"repeated cursor",
23172317
"missing comments",
2318+
"thread list truncated",
23182319
])("wakes a watched thread once: %s", (mode) =>
23192320
Effect.gen(function* () {
23202321
const orchestrator = yield* Orchestrator.OrchestratorV2;
@@ -2451,6 +2452,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
24512452
: [...firstTen, { ...remark, kind: "issue-comment" }],
24522453
commentCount: mode === "single page" ? 1 : 13,
24532454
commentsTruncated: mode !== "single page",
2455+
reviewThreadsTruncated: mode === "thread list truncated" && !recovering,
24542456
reviewThreads:
24552457
mode === "single page"
24562458
? []
@@ -2507,6 +2509,8 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
25072509
messages.map((message) => message.notification?.summary),
25082510
["#7: checks failed"],
25092511
);
2512+
// Keep the two notifications ordered independently of their random message IDs.
2513+
yield* TestClock.adjust("1 millis");
25102514
recovering = true;
25112515
}
25122516
yield* reactor.sweep;

‎apps/server/src/pullRequest/GitHubPullRequestCli.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3612,7 +3612,14 @@ layer("GitHubPullRequestCli.layer", (it) => {
36123612
Effect.gen(function* () {
36133613
// A host that never runs out of pages: the walk has to end itself.
36143614
mockedExecute.mockReturnValue(
3615-
Effect.succeed(output(reviewThreadsPage([thread("PRRT_1", "c1")], "Y3Vyc29yOjE"))),
3615+
Effect.succeed(
3616+
output(
3617+
reviewThreadsPage(
3618+
[{ ...thread("PRRT_1", "c1"), comments: threadComments(["c1"], "Y3Vyc29yOjI", 3) }],
3619+
"Y3Vyc29yOjE",
3620+
),
3621+
),
3622+
),
36163623
);
36173624
const cli = yield* GitHubPullRequestCli.GitHubPullRequestCli;
36183625

@@ -3625,6 +3632,7 @@ layer("GitHubPullRequestCli.layer", (it) => {
36253632

36263633
assert.strictEqual(mockedExecute.mock.calls.length, 10);
36273634
assert.isTrue(conversation.truncated);
3635+
assert.isTrue(conversation.reviewThreadsTruncated);
36283636
}),
36293637
);
36303638

@@ -3656,6 +3664,7 @@ layer("GitHubPullRequestCli.layer", (it) => {
36563664
nextCommentsCursor: "Y3Vyc29yOjI",
36573665
});
36583666
assert.isTrue(conversation.truncated);
3667+
assert.isFalse(conversation.reviewThreadsTruncated);
36593668
}),
36603669
);
36613670

‎apps/server/src/pullRequest/GitHubPullRequestCli.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,7 @@ export const make = Effect.gen(function* () {
24092409
// where a bound kept some of the words on GitHub.
24102410
commentCount: entries.reduce((total, entry) => total + entry.commentCount, 0),
24112411
truncated: cursor !== null || entries.some((entry) => entry.nextCommentCursor !== null),
2412+
reviewThreadsTruncated: cursor !== null,
24122413
reactions,
24132414
reactionsById,
24142415
reviewers,

‎apps/server/src/pullRequest/GitHubPullRequestProvider.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ describe("getChangeRequest commits", () => {
882882
reviewThreads: [],
883883
commentCount: 0,
884884
truncated: false,
885+
reviewThreadsTruncated: false,
885886
reactions: [],
886887
reactionsById: new Map<string, ReadonlyArray<PullRequestReaction>>(),
887888
reviewers: [],
@@ -967,6 +968,7 @@ describe("getChangeRequestActivity dismissed reviews", () => {
967968
reviewThreads: [],
968969
commentCount: 0,
969970
truncated: false,
971+
reviewThreadsTruncated: false,
970972
reactions: [],
971973
reactionsById: new Map(),
972974
reviewers: [],

‎apps/server/src/pullRequest/GitHubPullRequestProvider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ export const make = Effect.gen(function* () {
411411
reviewThreads: [],
412412
commentCount: 0,
413413
truncated: true,
414+
reviewThreadsTruncated: true,
414415
reviewers: [],
415416
avatarsByLogin: new Map<string, string>(),
416417
botLogins: new Set<string>(),
@@ -479,6 +480,7 @@ export const make = Effect.gen(function* () {
479480
// are always whole and only the thread walk can stop short of the host.
480481
commentCount: pullRequest.comments.length + reviewThreads.commentCount,
481482
commentsTruncated: reviewThreads.truncated,
483+
reviewThreadsTruncated: reviewThreads.reviewThreadsTruncated,
482484
reviewThreads: reviewThreads.reviewThreads.map((thread) => ({
483485
...thread,
484486
comments: thread.comments.map((comment) => ({

‎apps/server/src/pullRequest/PullRequestProvider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export interface ProviderChangeRequestActivity {
248248
*/
249249
readonly commentCount: number;
250250
readonly commentsTruncated: boolean;
251+
readonly reviewThreadsTruncated?: boolean;
251252
readonly reviewThreads: ReadonlyArray<PullRequestReviewThread>;
252253
readonly commits: ReadonlyArray<PullRequestCommit>;
253254
/** The change request's own reactions, from a host that has them. */

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,7 +4318,8 @@ it.effect(
43184318
return Effect.succeed({
43194319
comments: [],
43204320
commentCount: 0,
4321-
commentsTruncated: false,
4321+
commentsTruncated: true,
4322+
reviewThreadsTruncated: true,
43224323
reviewThreads: [],
43234324
commits: [],
43244325
});
@@ -4342,10 +4343,14 @@ it.effect(
43424343
},
43434344
]);
43444345

4345-
yield* Effect.all([service.activity(reference), service.activity(reference)], {
4346-
concurrency: 2,
4347-
});
4346+
const activities = yield* Effect.all(
4347+
[service.activity(reference), service.activity(reference)],
4348+
{
4349+
concurrency: 2,
4350+
},
4351+
);
43484352
assert.strictEqual(activityCalls, 1);
4353+
assert.isTrue(activities.every((activity) => activity.reviewThreadsTruncated === true));
43494354

43504355
yield* service.invalidate({ reference });
43514356
yield* service.activity(reference);

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,9 @@ export const make = Effect.gen(function* () {
17781778
comments: activity.comments,
17791779
commentCount: activity.commentCount,
17801780
commentsTruncated: activity.commentsTruncated,
1781+
...(activity.reviewThreadsTruncated === undefined
1782+
? {}
1783+
: { reviewThreadsTruncated: activity.reviewThreadsTruncated }),
17811784
reviewThreads: activity.reviewThreads,
17821785
commits: activity.commits,
17831786
...(activity.reactions === undefined ? {} : { reactions: activity.reactions }),

‎apps/server/src/pullRequest/gitHubPullRequestJson.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,7 @@ export interface GitHubReviewThreadComments {
20932093
/** The host's own count of the conversation, which a bounded read can fall short of. */
20942094
readonly commentCount: number;
20952095
readonly truncated: boolean;
2096+
readonly reviewThreadsTruncated: boolean;
20962097
/** The pull request's own reactions, which sit on its description. */
20972098
readonly reactions: ReadonlyArray<PullRequestReaction>;
20982099
/** Reactions by node id, for the comments and reviews the `gh` JSON read carries no reaction on. */

0 commit comments

Comments
 (0)