From ed3be0f1b4d6698903beba159e38387bd7c0b47b Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Thu, 12 Nov 2026 20:18:02 -0500 Subject: [PATCH] fix(github): watch fingerprints notice merge state and review comment changes Signed-off-by: Yordis Prieto --- .../PullRequestWatchReactor.ts | 4 +- .../src/orchestration-v2/runtimeLayer.test.ts | 93 +++++++++++++++++++ .../src/server/PullRequestProvider.ts | 2 + .../src/server/gitHubPullRequestJson.test.ts | 12 +++ .../src/server/gitHubPullRequestJson.ts | 5 + .../src/server/pullRequestBatches.graphql | 3 + .../src/server/pullRequestBatches.graphql.ts | 8 +- 7 files changed, 125 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index 6ebd999a783a8..fe939ed09c4bc 100644 --- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts @@ -180,6 +180,7 @@ function planRead( return { detail: read || checksDue, activity: read }; } const activity = + fingerprint.includesRemarkState === false || last.remarks !== fingerprint.remarks || !last.remarksComplete || now - last.at >= FINGERPRINT_REREAD_MS; @@ -580,9 +581,10 @@ export const make = Effect.gen(function* () { if ( last === undefined || group.targets.some((target) => !last.watches.has(watchKey(target))) || + fingerprint?.includesRemarkState === false || (fingerprint !== null && last.remarks !== fingerprint.remarks) ) { - // A new watch or changed host remarks needs a fresh view of every tail. + // A new watch, changed host remarks, or partial remark state needs a fresh view of every tail. threadTails.delete(group.key); } const reference = referenceOf(group); diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index 647c6bc0880f6..552cf0258612a 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -4965,6 +4965,99 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); + it.effect.each([true, false])( + "reads activity on every sweep while the fingerprint lacks remark state (complete: %s)", + (complete) => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const threadId = ThreadId.make(`runtime-pull-request-watch-partial-${complete}`); + const projectId = ProjectId.make(`pr-watch-partial-project-${complete}`); + yield* seedProject({ + projectId, + title: "Watch partial remarks", + workspaceRoot: "/workspace/watch-partial", + defaultModelSelection: null, + createdAt: "2026-10-01T00:00:00.000Z", + }); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make(`pr-watch-partial-create-${complete}`), + threadId, + projectId, + title: "Watch partial remarks", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 94 }; + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-partial-start-${complete}`), + threadId, + ...key, + watching: true, + link: { url: "https://github.com/pingdotgg/t3code/pull/94", source: "agent" }, + }); + + let activityReads = 0; + const host = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(PullRequestService.PullRequestService)({ + // The fingerprint never moves, so only a missing remark total can prompt an activity read. + watchFingerprint: () => + Effect.succeed({ status: "quiet", remarks: "none", includesRemarkState: complete }), + invalidate: () => Effect.void, + detail: () => + Effect.succeed({ + ...watchedPullRequestDetail({ + projectId, + number: 94, + at: "2026-10-02T12:00:00.000Z", + }), + headSha: "6074dd48ff", + checks: [ + { name: "lint", status: "success", description: null, url: null, required: true }, + ], + }), + activity: (input) => + Effect.sync(() => { + if (input.number === 94) activityReads++; + return { + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], + }; + }), + }), + ); + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const sweep = reactor.sweep.pipe(Effect.andThen(worker.drain())); + + yield* sweep; + const afterFirst = activityReads; + yield* sweep; + yield* sweep; + assert.equal(activityReads, complete ? afterFirst : afterFirst + 2); + + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-partial-end-${complete}`), + threadId, + ...key, + watching: false, + }); + yield* worker.drain(); + }), + ); + // regression: #21155 watching a pull request again repeated news the thread already got it.effect("watching a dismissed stack layer again keeps what its last watch told", () => Effect.gen(function* () { diff --git a/packages/source-control-core/src/server/PullRequestProvider.ts b/packages/source-control-core/src/server/PullRequestProvider.ts index 81d5e33d110f4..de84081b359bc 100644 --- a/packages/source-control-core/src/server/PullRequestProvider.ts +++ b/packages/source-control-core/src/server/PullRequestProvider.ts @@ -75,6 +75,8 @@ export class PullRequestProviderError extends Schema.TaggedError { readonly reviews: number; readonly removals: number; readonly timelineItems: number; + readonly mergeStateStatus?: string; + readonly totalCommentsCount?: number | null; }) => ({ state: "OPEN", mergeable: "MERGEABLE", + mergeStateStatus: input.mergeStateStatus ?? "BLOCKED", + updatedAt: "2026-10-01T00:00:00Z", + totalCommentsCount: input.totalCommentsCount === undefined ? 3 : input.totalCommentsCount, headRefOid: "abc123", comments: { totalCount: 1, nodes: [{ lastEditedAt: input.commentEditedAt }] }, reviews: { totalCount: input.reviews, nodes: [] }, @@ -1816,11 +1821,18 @@ describe("pull request watch fingerprints", () => { }; const before = fingerprint(base); const checkFinished = fingerprint({ ...base, running: 1, failed: 1 }); + const mergeStateChanged = fingerprint({ ...base, mergeStateStatus: "CLEAN" }); + const reviewCommented = fingerprint({ ...base, totalCommentsCount: 4 }); + const partial = fingerprint({ ...base, totalCommentsCount: null }); const summaryEdited = fingerprint({ ...base, commentEditedAt: "2026-10-05T23:47:43Z" }); const replied = fingerprint({ ...base, reviews: 2 }); expect(checkFinished.status).not.toBe(before.status); expect(checkFinished.remarks).toBe(before.remarks); + expect(mergeStateChanged.status).not.toBe(before.status); + expect(reviewCommented.remarks).not.toBe(before.remarks); + expect(before.includesRemarkState).toBe(true); + expect(partial.includesRemarkState).toBe(false); expect(summaryEdited.remarks).not.toBe(before.remarks); expect(summaryEdited.status).toBe(before.status); expect(replied.remarks).not.toBe(before.remarks); diff --git a/packages/source-control-github/src/server/gitHubPullRequestJson.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.ts index 24cbd59260d62..66bdc18405598 100644 --- a/packages/source-control-github/src/server/gitHubPullRequestJson.ts +++ b/packages/source-control-github/src/server/gitHubPullRequestJson.ts @@ -985,6 +985,7 @@ export function toPullRequestSummary(pr: SummarizedPullRequest): GitHubPullReque export interface GitHubPullRequestWatchFingerprint { readonly status: string; readonly remarks: string; + readonly includesRemarkState: boolean; } type EditedConnection = WatchedPullRequest["comments"] | WatchedPullRequest["reviews"]; @@ -1012,12 +1013,16 @@ export function toPullRequestWatchFingerprint( status: [ pr.state, pr.mergeable, + pr.mergeStateStatus, pr.headRefOid, stateCounts(contexts?.checkRunCountsByState ?? null), stateCounts(contexts?.statusContextCountsByState ?? null), pr.mergeQueueRemovals?.filteredCount ?? 0, ].join(" "), + includesRemarkState: pr.totalCommentsCount !== null, remarks: [ + pr.updatedAt, + pr.totalCommentsCount, pr.comments.totalCount, newestEdit(pr.comments), pr.reviews?.totalCount ?? 0, diff --git a/packages/source-control-github/src/server/pullRequestBatches.graphql b/packages/source-control-github/src/server/pullRequestBatches.graphql index 1dfc73d831b2f..255f1f1c40c11 100644 --- a/packages/source-control-github/src/server/pullRequestBatches.graphql +++ b/packages/source-control-github/src/server/pullRequestBatches.graphql @@ -95,6 +95,9 @@ query PullRequestWatchFingerprint( pullRequest(number: $number) { state mergeable + mergeStateStatus + updatedAt + totalCommentsCount headRefOid comments(first: 100, orderBy: { field: UPDATED_AT, direction: DESC }) { totalCount diff --git a/packages/source-control-github/src/server/pullRequestBatches.graphql.ts b/packages/source-control-github/src/server/pullRequestBatches.graphql.ts index 1a4e0ef5e85e6..68d08f22c1ed7 100644 --- a/packages/source-control-github/src/server/pullRequestBatches.graphql.ts +++ b/packages/source-control-github/src/server/pullRequestBatches.graphql.ts @@ -377,6 +377,12 @@ export const PullRequestWatchFingerprintRepositoryPullRequestPullRequest = Schem state: GraphQL.enumLiterals(Shared.PullRequestState.literals), /** Whether or not the pull request can be merged based on the existence of merge conflicts. */ mergeable: GraphQL.enumLiterals(Shared.MergeableState.literals), + /** Detailed information about the current pull request merge state status. */ + mergeStateStatus: GraphQL.enumLiterals(Shared.MergeStateStatus.literals), + /** Identifies the date and time when the object was last updated. */ + updatedAt: Shared.DateTime, + /** Returns a count of how many comments this pull request has received. */ + totalCommentsCount: Schema.NullOr(Shared.Int), /** Identifies the oid of the head ref associated with the pull request, even if the ref has been deleted. */ headRefOid: Shared.GitObjectID, /** A list of comments associated with the pull request. */ @@ -409,7 +415,7 @@ export const PullRequestWatchFingerprint = GraphQL.query("PullRequestWatchFinger { name: "mergeQueue", body: "Boolean!" } ], selections: [ - { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){pullRequest(number:$", "number", "){state mergeable headRefOid comments(first:100 orderBy:{field:UPDATED_AT direction:DESC}){totalCount nodes{lastEditedAt}}reviews(last:100){totalCount nodes{lastEditedAt}}reviewThreads{totalCount}mergeQueueRemovals:timelineItems(itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){filteredCount}commits(last:1){nodes{commit{statusCheckRollup{contexts{checkRunCountsByState{state count}statusContextCountsByState{state count}}}}}}}}"] } + { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){pullRequest(number:$", "number", "){state mergeable mergeStateStatus updatedAt totalCommentsCount headRefOid comments(first:100 orderBy:{field:UPDATED_AT direction:DESC}){totalCount nodes{lastEditedAt}}reviews(last:100){totalCount nodes{lastEditedAt}}reviewThreads{totalCount}mergeQueueRemovals:timelineItems(itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){filteredCount}commits(last:1){nodes{commit{statusCheckRollup{contexts{checkRunCountsByState{state count}statusContextCountsByState{state count}}}}}}}}"] } ], fragments: [] },