Skip to content

Commit 1df9c91

Browse files
fix(server): thread reads list only open linked PRs and show their watch state (pingdotgg#34895)
1 parent 9359081 commit 1df9c91

3 files changed

Lines changed: 76 additions & 18 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.activity.test.ts‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,41 @@ function makeRun(input: {
124124

125125
it("readThread preserves caller access errors and prefers activity-run status over a newer cancelled queued run", async () => {
126126
let callerUnavailable = false;
127+
const pullRequestLink = (number: number, state: "open" | "merged", watched: boolean) => ({
128+
host: "github.com",
129+
repository: "acme/web",
130+
number,
131+
url: `https://github.com/acme/web/pull/${number}`,
132+
source: "agent",
133+
linkedAt: "2026-08-04T11:00:00.000Z",
134+
snapshot: { state },
135+
stack: null,
136+
...(watched
137+
? {
138+
watch: {
139+
startedAt: "2026-08-04T11:30:00.000Z",
140+
headSha: null,
141+
failedChecks: [],
142+
passed: false,
143+
passedChecks: [],
144+
remarksThrough: "2026-08-04T11:30:00.000Z",
145+
remarkIds: [],
146+
conflicting: false,
147+
wakes: 0,
148+
},
149+
}
150+
: {}),
151+
});
127152
const projection = {
128-
thread: baseThread({
129-
threadId: parentThreadId,
130-
title: "Parent",
131-
instanceId: parentInstanceId,
132-
model: "gpt-5.4",
133-
}),
153+
thread: {
154+
...baseThread({
155+
threadId: parentThreadId,
156+
title: "Parent",
157+
instanceId: parentInstanceId,
158+
model: "gpt-5.4",
159+
}),
160+
pullRequests: [pullRequestLink(1, "merged", false), pullRequestLink(2, "open", true)],
161+
},
134162
runs: [
135163
makeRun({ id: activeRunId, ordinal: 1, status: "running" }),
136164
makeRun({ id: cancelledRunId, ordinal: 2, status: "cancelled" }),
@@ -197,6 +225,19 @@ it("readThread preserves caller access errors and prefers activity-run status ov
197225
expect(result.thread.status).toBe("running");
198226
expect(result.thread.latestRunId).toBe(cancelledRunId);
199227
expect(result.thread.activeRunId).toBe(activeRunId);
228+
// Every page read must not repeat each linked PR, and an open PR shows whether it is watched.
229+
const listed = result.thread.pullRequests ?? [];
230+
expect(listed.map((link) => link.number)).not.toContain(1);
231+
expect(listed.find((link) => link.number === 2)).toMatchObject({
232+
watching: true,
233+
watchStartedAt: "2026-08-04T11:30:00.000Z",
234+
});
235+
const laterPage = yield* service.readThread(makeScope(), {
236+
threadId: parentThreadId,
237+
afterPosition: 0,
238+
});
239+
expect(laterPage.thread.pullRequests).toBeUndefined();
240+
expect(laterPage.thread.pullRequestCount).toBe(2);
200241

201242
callerUnavailable = true;
202243
const denied = yield* service

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
type OrchestratorMcpListScheduledTasksInput,
3838
type ProjectId,
3939
type OrchestratorMcpThreadDetail,
40-
type OrchestratorMcpThreadPullRequest,
4140
type OrchestratorMcpThreadInterruptInput,
4241
type OrchestratorMcpThreadInterruptResult,
4342
type OrchestratorMcpThreadListInput,
@@ -804,15 +803,25 @@ function threadSnooze(
804803

805804
function threadPullRequests(
806805
links: OrchestrationV2ThreadShell["pullRequests"],
807-
): OrchestratorMcpThreadPullRequest[] {
808-
return visibleThreadPullRequests(links ?? []).map((link) => ({
809-
host: normalizeThreadPullRequestKey(link).host,
810-
repository: link.repository,
811-
number: link.number,
812-
url: link.url,
813-
source: link.source,
814-
state: link.snapshot?.state ?? null,
815-
}));
806+
includeLinks = true,
807+
): Pick<OrchestratorMcpThreadListItem, "pullRequests" | "pullRequestCount"> {
808+
const visible = visibleThreadPullRequests(links ?? []);
809+
if (!includeLinks) return { pullRequestCount: visible.length };
810+
return {
811+
pullRequests: visible
812+
.filter((link) => link.snapshot?.state !== "merged" && link.snapshot?.state !== "closed")
813+
.map((link) => ({
814+
host: normalizeThreadPullRequestKey(link).host,
815+
repository: link.repository,
816+
number: link.number,
817+
url: link.url,
818+
source: link.source,
819+
state: link.snapshot?.state ?? null,
820+
watching: link.watch !== undefined,
821+
watchStartedAt: link.watch?.startedAt ?? null,
822+
})),
823+
pullRequestCount: visible.length,
824+
};
816825
}
817826

818827
// Awaited background work keeps a thread live after its turn ends, as auto-settle and the sidebar treat it.
@@ -842,7 +851,7 @@ function listItemFromShell(
842851
runtimeMode: shell.runtimeMode,
843852
interactionMode: shell.interactionMode,
844853
linkedPullRequest: shell.linkedPullRequest ?? null,
845-
pullRequests: threadPullRequests(shell.pullRequests),
854+
...threadPullRequests(shell.pullRequests),
846855
...threadSettlement(shell),
847856
...threadSnooze(shell, nowMs),
848857
parentThreadId: shell.lineage.parentThreadId,
@@ -859,6 +868,7 @@ function threadDetail(
859868
itemCount: number,
860869
shell: OrchestrationV2ThreadShell,
861870
nowMs: number,
871+
firstPage: boolean,
862872
): OrchestratorMcpThreadDetail {
863873
const latest = ThreadManagementService.latestRun(projection);
864874
const active = ThreadManagementService.latestActiveRun(projection);
@@ -877,7 +887,7 @@ function threadDetail(
877887
runtimeMode: projection.thread.runtimeMode,
878888
interactionMode: projection.thread.interactionMode,
879889
linkedPullRequest: projection.thread.linkedPullRequest ?? null,
880-
pullRequests: threadPullRequests(projection.thread.pullRequests),
890+
...threadPullRequests(projection.thread.pullRequests, firstPage),
881891
titleRegeneration:
882892
projection.thread.titleRegeneration === undefined ||
883893
projection.thread.titleRegeneration === null
@@ -3107,6 +3117,7 @@ const make = Effect.gen(function* () {
31073117
timeline.totalItems,
31083118
shell,
31093119
yield* Clock.currentTimeMillis,
3120+
input.afterPosition === undefined && input.itemId === undefined,
31103121
),
31113122
recentRuns: target.runs
31123123
.toSorted((left, right) => right.ordinal - left.ordinal)

‎packages/contracts/src/orchestratorMcp.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ export const OrchestratorMcpThreadPullRequest = Schema.Struct({
357357
url: TrimmedNonEmptyString,
358358
source: ThreadPullRequestLinkSource,
359359
state: Schema.NullOr(PullRequestState),
360+
watching: Schema.Boolean,
361+
watchStartedAt: Schema.NullOr(IsoDateTime),
360362
});
361363
export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
362364

@@ -374,7 +376,9 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
374376
runtimeMode: RuntimeMode,
375377
interactionMode: ProviderInteractionMode,
376378
linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
379+
/** Linked pull requests not yet merged or closed; list_thread_pull_requests has all of them. */
377380
pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
381+
pullRequestCount: Schema.optional(NonNegativeInt),
378382
settled: Schema.Boolean,
379383
settledAt: Schema.NullOr(IsoDateTime),
380384
snoozed: Schema.Boolean,
@@ -445,7 +449,9 @@ export const OrchestratorMcpThreadDetail = Schema.Struct({
445449
runtimeMode: RuntimeMode,
446450
interactionMode: ProviderInteractionMode,
447451
linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
452+
/** Open linked pull requests, on the first page only; list_thread_pull_requests has all of them. */
448453
pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
454+
pullRequestCount: Schema.optional(NonNegativeInt),
449455
titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
450456
branch: Schema.NullOr(Schema.String),
451457
worktreePath: Schema.NullOr(Schema.String),

0 commit comments

Comments
 (0)