@devries-cameron20 / t3code Mirror · read-only / commits / 7dceb76f4c
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

fix(server): watched PRs wake the agent when they merge (#26271)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 18, 2026 at 21:32 UTC 7dceb76f4c1416ffae3839e19dceb4d0c19c9ca2
26 files changed +936 -88
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+4 -6
@@ -17,7 +17,10 @@ import {
17 threadPullRequestKeysEqual,
18 visibleThreadPullRequests,
19 } from "../sourceControl/threadPullRequests.ts";
20 -import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
20 +import {
21 + isChangeRequestCloseCommand,
22 + sourceControlDefinitions,
23 +} from "../sourceControl/sourceControlDefinitions.ts";
24 import * as Cause from "effect/Cause";
25 import * as Clock from "effect/Clock";
26 import * as Context from "effect/Context";
@@ -52,11 +55,6 @@ const CLOSED_FINAL_AFTER_MS = 24 * 60 * 60 * 1_000;
55 // A link whose host read failed waits a sweep, then twice as long after each further failure.
56 const FAILED_READ_BACKOFF_MS = 60 * 1_000;
57
55 -const isChangeRequestCloseCommand = (command: string) =>
56 - sourceControlDefinitions.definitions.some(
57 - (definition) => definition.changeRequestCloseCommand?.test(command) === true,
58 - );
59 -
58 // Where a shell starts a command, past `NAME=value` assignments and wrappers like `timeout 60`.
59 // A create command anywhere else, as in `echo "gh pr create"`, is text, not a command that runs.
60 const COMMAND_START =
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+132 -30
@@ -1,14 +1,22 @@
1 import {
2 CommandId,
3 + isOrchestrationV2WorkActive,
4 MessageId,
5 type OrchestrationV2Notification,
6 type PullRequestActivity,
7 type PullRequestComment,
8 + type PullRequestDetail,
9 type PullRequestRef,
10 type PullRequestThreadCommentsResult,
11 type ThreadPullRequestLink,
12 + type ThreadId,
13 type ThreadPullRequestWatch,
14 } from "@t3tools/contracts";
15 +import { commandIndicatesFailure } from "@t3tools/shared/toolOutput";
16 +import {
17 + changeRequestsClosedBy,
18 + isChangeRequestCloseCommand,
19 +} from "../sourceControl/sourceControlDefinitions.ts";
20 import {
21 normalizeThreadPullRequestKey,
22 threadPullRequestKeyOf,
@@ -37,10 +45,12 @@ import * as PullRequestService from "../pullRequest/PullRequestService.ts";
45 import { forkParked } from "../serverActivation.ts";
46 import * as Orchestrator from "./Orchestrator.ts";
47 import * as ProjectionStore from "./ProjectionStore.ts";
48 +import { isTerminalRunStatus } from "./ThreadManagementService.ts";
49 import {
50 combinePullRequestWatchWakes,
51 evaluatePullRequestWatch,
52 PULL_REQUEST_WATCH_NO_CHECKS_MS,
53 + pullRequestWatchEndMessage,
54 pullRequestWatchMessage,
55 } from "./pullRequestWatch.ts";
56
@@ -292,6 +302,17 @@ export const make = Effect.gen(function* () {
302 // A pass reads watches and records new ones, so passes must not overlap.
303 const passes = Semaphore.makeUnsafe(1);
304 const lastReads = new Map<string, LastRead>();
305 + /**
306 + * Each thread's merge and close commands, by item, with the pull requests each names. One counts
307 + * while it runs and, if it succeeded, until the read at its end is done.
308 + */
309 + const agentEnds = new Map<ThreadId, Map<string, ReadonlySet<number> | "any">>();
310 + // The agent needs no wake for a merge or close it made itself. Anything ending later, as a
311 + // `--auto` merge does, is news.
312 + const endedByAgent = (target: WatchTarget) =>
313 + [...(agentEnds.get(target.thread.id)?.values() ?? [])].some(
314 + (named) => named === "any" || named.has(target.link.number),
315 + );
316 const threadTails = new Map<
317 string,
318 {
@@ -524,30 +545,34 @@ export const make = Effect.gen(function* () {
545 );
546 });
547
527 - const closed = (groupKey: string, target: WatchTarget) =>
528 - hold({
529 - groupKey,
530 - target,
531 - next: null,
532 - wake: {
533 - text: `Pull request #${target.link.number} (${target.link.url}) was closed, so T3 Code stopped watching it. Call watch_pull_request if it reopens.`,
534 - notification: {
535 - source: { kind: "monitor" },
536 - outcome: "updated",
537 - summary: `#${target.link.number}: closed, stopped watching`,
538 - },
539 - },
540 - reason: "closed",
541 - });
548 + const finished = (
549 + groupKey: string,
550 + target: WatchTarget,
551 + detail: Pick<PullRequestDetail, "state" | "baseBranch" | "mergeCommitSha" | "mergedBy">,
552 + ) => {
553 + const reason = detail.state === "merged" ? "merged" : "closed";
554 + return endedByAgent(target)
555 + ? record(target, null).pipe(Effect.tap(() => ended(target, reason)))
556 + : hold({
557 + groupKey,
558 + target,
559 + next: null,
560 + wake: pullRequestWatchEndMessage({
561 + number: target.link.number,
562 + url: target.link.url,
563 + detail,
564 + }),
565 + reason,
566 + });
567 + };
568
543 - const endsWithoutRead = ({ thread, link }: WatchTarget): WatchEndReason | undefined =>
544 - link.snapshot?.state === "merged"
545 - ? "merged"
546 - : thread.settledOverride === "settled" || thread.settledAt !== null
547 - ? "settled"
548 - : thread.lineage.relationshipToParent === "subagent"
549 - ? "subagent"
550 - : undefined;
569 + // A merged snapshot still gets one read, so the wake can name the merge commit.
570 + const endsWithoutRead = ({ thread }: WatchTarget): WatchEndReason | undefined =>
571 + thread.settledOverride === "settled" || thread.settledAt !== null
572 + ? "settled"
573 + : thread.lineage.relationshipToParent === "subagent"
574 + ? "subagent"
575 + : undefined;
576
577 const eachTarget = <E>(
578 group: WatchGroup,
@@ -566,6 +591,16 @@ export const make = Effect.gen(function* () {
591 ),
592 ).pipe(Effect.map((landed) => landed.every(Boolean)));
593
594 + // A merged PR's watch holds its thread from settling, so it must not wait out the host.
595 + const endMergedSnapshots = (group: WatchGroup) => {
596 + const merged = group.targets.filter((target) => target.link.snapshot?.state === "merged");
597 + return eachTarget({ ...group, targets: merged }, (target) =>
598 + target.link.snapshot ? finished(group.key, target, target.link.snapshot) : Effect.void,
599 + ).pipe(
600 + Effect.as({ ...group, targets: group.targets.filter((target) => !merged.includes(target)) }),
601 + );
602 + };
603 +
604 const referenceOf = (group: WatchGroup) => {
605 const first = group.targets[0]!;
606 return { projectId: first.thread.projectId, ...identityOf(first.link) };
@@ -620,6 +655,11 @@ export const make = Effect.gen(function* () {
655 if (Cause.hasInterruptsOnly(detailRead.cause))
656 return yield* Effect.failCause(detailRead.cause);
657 lastReads.delete(group.key);
658 + const unended = yield* endMergedSnapshots(group);
659 + if (unended.targets.length === 0) {
660 + readFailures.delete(group.key);
661 + return;
662 + }
663 const reason = providerFailureReason(detailRead.cause);
664 if (reason === "rate-limited") return;
665 // Transport and host failures can outlast the failure limit; keep the watch for recovery.
@@ -629,7 +669,7 @@ export const make = Effect.gen(function* () {
669 }
670 const failures = (readFailures.get(group.key) ?? 0) + 1;
671 readFailures.set(group.key, failures);
632 - if (failures >= READ_FAILURE_LIMIT && (yield* eachTarget(group, giveUp))) {
672 + if (failures >= READ_FAILURE_LIMIT && (yield* eachTarget(unended, giveUp))) {
673 readFailures.delete(group.key);
674 }
675 return yield* Effect.failCause(detailRead.cause);
@@ -651,11 +691,7 @@ export const make = Effect.gen(function* () {
691 }
692 if (detail.state !== "open") {
693 lastReads.delete(group.key);
654 - return yield* eachTarget(group, (target) =>
655 - detail.state === "closed"
656 - ? closed(group.key, target)
657 - : record(target, null).pipe(Effect.tap(() => ended(target, "merged"))),
658 - );
694 + return yield* eachTarget(group, (target) => finished(group.key, target, detail));
695 }
696
697 // A failed comments read leaves remarks incomplete, so the next pass reads them again;
@@ -812,7 +848,7 @@ export const make = Effect.gen(function* () {
848 }),
849 Effect.flatMap((fingerprint) =>
850 fingerprint === "paused"
815 - ? Effect.void
851 + ? endMergedSnapshots(group).pipe(Effect.asVoid)
852 : reads.withPermit(
853 readGroup(group, fingerprint).pipe(
854 Effect.catchCause(
@@ -840,9 +876,75 @@ export const make = Effect.gen(function* () {
876 Effect.withSpan("PullRequestWatchReactor.readOnChange"),
877 );
878
879 + // A full read, since an unchanged fingerprint or snapshot would otherwise skip the detail.
880 + const readThreadWatches = (threadId: ThreadId) =>
881 + projections.getThreadsWithPullRequests(threadId).pipe(
882 + Effect.flatMap((threads) =>
883 + Effect.forEach(
884 + threads.flatMap((thread) =>
885 + visibleThreadPullRequests(thread.pullRequests ?? [])
886 + .filter((link) => link.watch !== undefined)
887 + .map((link) => [thread.projectId, threadPullRequestKeyOf(link)] as const),
888 + ),
889 + ([projectId, pullRequest]) =>
890 + // After any pass in flight, which could record a read from before the merge.
891 + passes
892 + .withPermit(Effect.sync(() => lastReads.delete(`${projectId} ${pullRequest}`)))
893 + .pipe(Effect.andThen(readOnChange(pullRequest))),
894 + { discard: true },
895 + ),
896 + ),
897 + Effect.catchCause(logFailure("pull request watch read after a merge failed", { threadId })),
898 + );
899 +
900 const start: PullRequestWatchReactor["Service"]["start"] = Effect.fn(
901 "PullRequestWatchReactor.start",
902 )(function* () {
903 + // Reading a thread's watches as its agent's merge or close ends lets them end at once.
904 + const agentReads = yield* FiberMap.make<string>();
905 + const finished = new Set<string>();
906 + yield* forkParked(
907 + Stream.runForEach(engine.streamDomainEvents, (event) => {
908 + if (event.type === "run.updated") {
909 + // A run can stop before its command reports that it ended.
910 + const commands = agentEnds.get(event.threadId);
911 + if (commands === undefined || !isTerminalRunStatus(event.payload.status)) {
912 + return Effect.void;
913 + }
914 + for (const id of commands.keys()) if (!finished.has(id)) commands.delete(id);
915 + if (commands.size === 0) agentEnds.delete(event.threadId);
916 + return Effect.void;
917 + }
918 + if (event.type !== "turn-item.updated") return Effect.void;
919 + const item = event.payload;
920 + if (
921 + item.type !== "command_execution" ||
922 + finished.has(item.id) ||
923 + !isChangeRequestCloseCommand(item.input)
924 + ) {
925 + return Effect.void;
926 + }
927 + const commands = agentEnds.get(event.threadId) ?? new Map();
928 + agentEnds.set(event.threadId, commands);
929 + commands.set(item.id, changeRequestsClosedBy(item.input));
930 + if (isOrchestrationV2WorkActive(item.status)) return Effect.void;
931 + finished.add(item.id);
932 + const done = Effect.sync(() => {
933 + commands.delete(item.id);
934 + if (commands.size === 0 && agentEnds.get(event.threadId) === commands) {
935 + agentEnds.delete(event.threadId);
936 + }
937 + });
938 + // Some providers report a command that failed as completed.
939 + return Effect.andThen(
940 + item.status === "completed" && !commandIndicatesFailure(item) ? Effect.void : done,
941 + FiberMap.run(
942 + agentReads,
943 + item.id,
944 + )(readThreadWatches(event.threadId).pipe(Effect.ensuring(done))),
945 + );
946 + }).pipe(Effect.catchCause(logFailure("pull request watch command stream failed", {}))),
947 + );
948 // One feed per pull request: the host keeps one subscription per pull request and account.
949 const feeds = yield* FiberMap.make<string>();
950 const follow = Effect.gen(function* () {
apps/server/src/orchestration-v2/WireProjection.ts
+2 -7
@@ -17,10 +17,10 @@ import {
17 } from "@t3tools/shared/orchestrationV2DedupedBodies";
18 import { MCP_APP_OUTPUT_KEY, readMcpAppReference } from "@t3tools/shared/mcpApp";
19 import {
20 + commandIndicatesFailure,
21 compactDynamicToolOutput,
22 omitToolOutputImageData,
23 toolOutputImages,
23 - toolOutputIndicatesFailure,
24 } from "@t3tools/shared/toolOutput";
25
26 // A checkpoint over vendored or generated trees can list 15k+ files; the card needs a prefix.
@@ -167,12 +167,7 @@ export function projectTurnItemForWire(item: OrchestrationV2TurnItem): Orchestra
167 const { output, ...projected } = item;
168 // A successful search can print "ENOENT" or "exit code 2", so output text
169 // decides only when the provider reported no exit code.
170 - const failed =
171 - item.exitCode === undefined
172 - ? item.outputIndicatesFailure === true ||
173 - (output !== undefined &&
174 - toolOutputIndicatesFailure(output.slice(0, MAX_DETAIL_STRING_BYTES)))
175 - : item.exitCode !== 0;
170 + const failed = commandIndicatesFailure(item);
171 return {
172 ...projected,
173 ...(failed ? { outputIndicatesFailure: true } : {}),
apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+40
@@ -8,6 +8,7 @@ import { assert, describe, it } from "@effect/vitest";
8 import {
9 PULL_REQUEST_WATCH_WAKE_LIMIT,
10 evaluatePullRequestWatch as evaluate,
11 + pullRequestWatchEndMessage,
12 pullRequestWatchMessage,
13 } from "./pullRequestWatch.ts";
14
@@ -1008,3 +1009,42 @@ describe("evaluatePullRequestWatch", () => {
1009 assert.isTrue(unanswered(STARTED));
1010 });
1011 });
1012 +
1013 +describe("pullRequestWatchEndMessage", () => {
1014 + const url = "https://git.cafe/pingdotgg/t3code/pull/7";
1015 + const end = (overrides: Partial<Parameters<typeof pullRequestWatchEndMessage>[0]["detail"]>) =>
1016 + pullRequestWatchEndMessage({
1017 + number: 7,
1018 + url,
1019 + detail: { state: "merged", baseBranch: "main", ...overrides },
1020 + });
1021 + const mergeCommitSha = "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9";
1022 +
1023 + it("says how the pull request ended, with the merge commit and merger the host reports", () => {
1024 + const merged = end({
1025 + mergeCommitSha,
1026 + mergedBy: { login: "juliusmarminge", name: null, avatarUrl: null },
1027 + });
1028 + assert.equal(
1029 + merged.text,
1030 + `Pull request #7 (${url}) was merged into main by juliusmarminge as 3b2f958, so T3 Code stopped watching it.`,
1031 + );
1032 + assert.deepEqual(merged.notification, {
1033 + source: { kind: "monitor" },
1034 + outcome: "completed",
1035 + summary: "#7: merged, stopped watching",
1036 + });
1037 + // GitCafe reports a merge made on GitHub without who made it.
1038 + assert.equal(
1039 + end({ mergeCommitSha }).text,
1040 + `Pull request #7 (${url}) was merged into main as 3b2f958, so T3 Code stopped watching it.`,
1041 + );
1042 +
1043 + const closed = end({ state: "closed" });
1044 + assert.equal(
1045 + closed.text,
1046 + `Pull request #7 (${url}) was closed without merging, so T3 Code stopped watching it. If it is reopened, call watch_pull_request to watch it again.`,
1047 + );
1048 + assert.equal(closed.notification.summary, "#7: closed, stopped watching");
1049 + });
1050 +});
apps/server/src/orchestration-v2/pullRequestWatch.ts
+27
@@ -447,6 +447,33 @@ export function combinePullRequestWatchWakes(
447 };
448 }
449
450 +export function pullRequestWatchEndMessage(input: {
451 + readonly number: number;
452 + readonly url: string;
453 + readonly detail: Pick<PullRequestDetail, "state" | "baseBranch" | "mergeCommitSha" | "mergedBy">;
454 +}): { readonly text: string; readonly notification: OrchestrationV2Notification } {
455 + const { detail } = input;
456 + const merged = detail.state === "merged";
457 + const how = merged
458 + ? [
459 + `was merged into ${detail.baseBranch}`,
460 + detail.mergedBy ? ` by ${detail.mergedBy.login}` : "",
461 + detail.mergeCommitSha ? ` as ${detail.mergeCommitSha.slice(0, 7)}` : "",
462 + ].join("")
463 + : "was closed without merging";
464 + return {
465 + text: [
466 + `Pull request #${input.number} (${input.url}) ${how}, so T3 Code stopped watching it.`,
467 + ...(merged ? [] : ["If it is reopened, call watch_pull_request to watch it again."]),
468 + ].join(" "),
469 + notification: {
470 + source: { kind: "monitor" },
471 + outcome: merged ? "completed" : "updated",
472 + summary: `#${input.number}: ${merged ? "merged" : "closed"}, stopped watching`,
473 + },
474 + };
475 +}
476 +
477 export function pullRequestWatchMessage(input: {
478 readonly number: number;
479 readonly url: string;
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+494 -4
@@ -48,6 +48,7 @@ import * as FileSystem from "effect/FileSystem";
48 import * as Layer from "effect/Layer";
49 import * as Option from "effect/Option";
50 import * as Path from "effect/Path";
51 +import * as PubSub from "effect/PubSub";
52 import * as Queue from "effect/Queue";
53 import * as Ref from "effect/Ref";
54 import * as Stream from "effect/Stream";
@@ -4593,6 +4594,494 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
4594 }),
4595 );
4596
4597 + // regression: watched #26248 merged and its agent kept saying it was still watching
4598 + it.effect("wakes once when a watched pull request merges, naming the merge commit", () =>
4599 + Effect.gen(function* () {
4600 + const orchestrator = yield* Orchestrator.OrchestratorV2;
4601 + const threadId = ThreadId.make("runtime-pull-request-watch-merged");
4602 + const projectId = ProjectId.make("pr-watch-merged-project");
4603 + yield* seedProject({
4604 + projectId,
4605 + title: "Watch merged",
4606 + workspaceRoot: "/workspace/watch-merged",
4607 + defaultModelSelection: null,
4608 + createdAt: "2026-10-01T00:00:00.000Z",
4609 + });
4610 + yield* orchestrator.dispatch({
4611 + type: "thread.create",
4612 + createdBy: "user",
4613 + creationSource: "web",
4614 + commandId: CommandId.make("pr-watch-merged-create"),
4615 + threadId,
4616 + projectId,
4617 + title: "Watch merged",
4618 + modelSelection,
4619 + runtimeMode: "full-access",
4620 + interactionMode: "default",
4621 + branch: null,
4622 + worktreePath: null,
4623 + });
4624 + yield* orchestrator.dispatch({
4625 + type: "thread.pull-request.watch",
4626 + commandId: CommandId.make("pr-watch-merged-start"),
4627 + threadId,
4628 + host: "github.com",
4629 + repository: "pingdotgg/t3code",
4630 + number: 15,
4631 + watching: true,
4632 + link: { url: "https://github.com/pingdotgg/t3code/pull/15", source: "agent" },
4633 + });
4634 + const reactor = yield* PullRequestWatchReactor.make.pipe(
4635 + Effect.provide(
4636 + Layer.mergeAll(
4637 + NodeServices.layer,
4638 + NodeCrypto.layer,
4639 + Layer.mock(PullRequestService.PullRequestService)({
4640 + detail: () =>
4641 + Effect.succeed({
4642 + ...watchedPullRequestDetail({
4643 + projectId,
4644 + number: 15,
4645 + at: "2026-10-02T12:00:00.000Z",
4646 + }),
4647 + state: "merged" as const,
4648 + mergedAt: "2026-10-02T12:00:00.000Z",
4649 + mergeCommitSha: "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9",
4650 + mergedBy: { login: "juliusmarminge", name: null, avatarUrl: null },
4651 + }),
4652 + activity: () =>
4653 + Effect.succeed({
4654 + comments: [],
4655 + commentCount: 0,
4656 + commentsTruncated: false,
4657 + reviewThreads: [],
4658 + commits: [],
4659 + }),
4660 + }),
4661 + ),
4662 + ),
4663 + );
4664 + yield* reactor.sweep;
4665 + yield* TestClock.adjust("10 minutes");
4666 + yield* reactor.sweep;
4667 +
4668 + assert.isUndefined((yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch);
4669 + const wakes = (yield* orchestrator.getThreadRecords(threadId, ["messages"])).messages.filter(
4670 + (message) => message.notification != null,
4671 + );
4672 + assert.deepEqual(
4673 + wakes.map((message) => message.notification?.summary),
4674 + ["#15: merged, stopped watching"],
4675 + );
4676 + assert.include(wakes[0]!.text, "merged into main by juliusmarminge as 3b2f958");
4677 + }),
4678 + );
4679 +
4680 + it.effect.each([
4681 + // The agent's merge of #19 needs no wake, but its command did not close #20.
4682 + { name: "completed", status: "completed", wakes: ["#20: closed, stopped watching"] },
4683 + // A merge command that failed ended nothing itself.
4684 + {
4685 + name: "failed",
4686 + status: "failed",
4687 + wakes: ["#19: merged, stopped watching", "#20: closed, stopped watching"],
4688 + },
4689 + {
4690 + name: "exit-1",
4691 + status: "completed",
4692 + exitCode: 1,
4693 + wakes: ["#19: merged, stopped watching", "#20: closed, stopped watching"],
4694 + },
4695 + {
4696 + name: "failure-output",
4697 + status: "completed",
4698 + output: "GraphQL: Pull request is not mergeable\n<exited with exit code 1>",
4699 + wakes: ["#19: merged, stopped watching", "#20: closed, stopped watching"],
4700 + },
4701 + ] as const)(
4702 + "ends a watch without a wake when the thread's own agent merged it ($name)",
4703 + ({ name: key, status: ended, wakes: expected, ...result }) =>
4704 + Effect.gen(function* () {
4705 + const orchestrator = yield* Orchestrator.OrchestratorV2;
4706 + const threadId = ThreadId.make(`runtime-pull-request-watch-own-merge-${key}`);
4707 + const projectId = ProjectId.make(`pr-watch-own-merge-${key}-project`);
4708 + yield* seedProject({
4709 + projectId,
4710 + title: "Watch own merge",
4711 + workspaceRoot: `/workspace/watch-own-merge-${key}`,
4712 + defaultModelSelection: null,
4713 + createdAt: "2026-10-01T00:00:00.000Z",
4714 + });
4715 + yield* orchestrator.dispatch({
4716 + type: "thread.create",
4717 + createdBy: "user",
4718 + creationSource: "web",
4719 + commandId: CommandId.make(`pr-watch-own-merge-${key}-create`),
4720 + threadId,
4721 + projectId,
4722 + title: "Watch own merge",
4723 + modelSelection,
4724 + runtimeMode: "full-access",
4725 + interactionMode: "default",
4726 + branch: null,
4727 + worktreePath: null,
4728 + });
4729 + for (const number of [19, 20]) {
4730 + yield* orchestrator.dispatch({
4731 + type: "thread.pull-request.watch",
4732 + commandId: CommandId.make(`pr-watch-own-merge-${key}-start-${number}`),
4733 + threadId,
4734 + host: "github.com",
4735 + repository: "pingdotgg/t3code",
4736 + number,
4737 + watching: true,
4738 + link: { url: `https://github.com/pingdotgg/t3code/pull/${number}`, source: "agent" },
4739 + });
4740 + }
4741 +
4742 + const states = new Map<number, PullRequestDetail["state"]>([
4743 + [19, "open"],
4744 + [20, "open"],
4745 + ]);
4746 + const detailReads = yield* Queue.unbounded<number>();
4747 + const agentRead = yield* Deferred.make<void>();
4748 + // Each of the reactor's subscribers reads every event, as each event sink stream does.
4749 + const agentEvents = yield* PubSub.unbounded<OrchestrationV2DomainEvent>({ replay: 16 });
4750 + const host = Layer.mergeAll(
4751 + NodeServices.layer,
4752 + NodeCrypto.layer,
4753 + Layer.mock(PullRequestService.PullRequestService)({
4754 + detail: (input) =>
4755 + Effect.sync(() => states.get(input.number)!).pipe(
4756 + Effect.tap(() => Queue.offer(detailReads, input.number)),
4757 + // Reads of an open pull request are slow, so the first sweep outlasts the merge.
4758 + Effect.tap((state) => (state === "open" ? Effect.sleep("1 second") : Effect.void)),
4759 + Effect.map((state) => ({
4760 + ...watchedPullRequestDetail({
4761 + projectId,
4762 + number: input.number,
4763 + at: "2026-10-02T12:00:00.000Z",
4764 + }),
4765 + state,
4766 + })),
4767 + ),
4768 + activity: () =>
4769 + Effect.succeed({
4770 + comments: [],
4771 + commentCount: 0,
4772 + commentsTruncated: false,
4773 + reviewThreads: [],
4774 + commits: [],
4775 + }),
4776 + // A fingerprint that never changes, so only a forced read sees an end.
4777 + watchFingerprint: () => Effect.succeed({ status: "steady", remarks: "" }),
4778 + invalidate: () => Effect.void,
4779 + changes: () => Stream.never,
4780 + }),
4781 + Layer.succeed(Orchestrator.OrchestratorV2, {
4782 + ...orchestrator,
4783 + streamDomainEvents: Stream.fromPubSub(agentEvents),
4784 + }),
4785 + // Only the read at a command's end asks for one thread's watches.
4786 + Layer.effect(
4787 + ProjectionStore.ProjectionStoreV2,
4788 + Effect.map(ProjectionStore.ProjectionStoreV2, (store) => ({
4789 + ...store,
4790 + getThreadsWithPullRequests: (thread?: ThreadId) =>
4791 + store
4792 + .getThreadsWithPullRequests(thread)
4793 + .pipe(
4794 + Effect.tap(() =>
4795 + thread === undefined ? Effect.void : Deferred.succeed(agentRead, undefined),
4796 + ),
4797 + ),
4798 + })),
4799 + ),
4800 + );
4801 + const runId = RunId.make(`run:${threadId}:1`);
4802 + const command = (status: "running" | typeof ended) =>
4803 + Effect.map(DateTime.now, (at): OrchestrationV2DomainEvent => ({
4804 + type: "turn-item.updated",
4805 + id: EventId.make(`event:${threadId}:merge-${status}`),
4806 + threadId,
4807 + runId,
4808 + occurredAt: at,
4809 + payload: {
4810 + id: TurnItemId.make(`item:${threadId}:merge`),
4811 + threadId,
4812 + runId,
4813 + nodeId: null,
4814 + providerThreadId: null,
4815 + providerTurnId: null,
4816 + nativeItemRef: null,
4817 + parentItemId: null,
4818 + ordinal: 1,
4819 + status,
4820 + title: null,
4821 + startedAt: at,
4822 + completedAt: status === "completed" ? at : null,
4823 + updatedAt: at,
4824 + type: "command_execution",
4825 + input: "gh pr merge 19 --squash",
4826 + ...(status === "running" ? {} : result),
4827 + },
4828 + }));
4829 + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
4830 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
4831 + yield* reactor.start();
4832 + // The first sweep has read both as open, and has not recorded that yet.
4833 + yield* Queue.take(detailReads);
4834 + yield* Queue.take(detailReads);
4835 +
4836 + // While the agent merges #19, someone else closes #20.
4837 + yield* PubSub.publish(agentEvents, yield* command("running"));
4838 + states.set(19, "merged");
4839 + states.set(20, "closed");
4840 + // The command's end reads the thread's watches in full, after that sweep.
4841 + yield* PubSub.publish(agentEvents, yield* command(ended));
4842 + yield* Deferred.await(agentRead);
4843 + yield* TestClock.adjust("1 second");
4844 + yield* Queue.take(detailReads);
4845 + yield* Queue.take(detailReads);
4846 + // A sweep waits for that read to finish.
4847 + yield* reactor.sweep;
4848 + yield* worker.drain();
4849 + const thread = yield* orchestrator.getThreadShell(threadId);
4850 + assert.isTrue(thread?.pullRequests?.every((link) => link.watch === undefined));
4851 + const wakes = (yield* orchestrator.getThreadRecords(threadId, [
4852 + "messages",
4853 + ])).messages.flatMap((message) => message.notification?.summary ?? []);
4854 + assert.sameMembers(wakes, [...expected]);
4855 + }),
4856 + );
4857 +
4858 + it.effect("a pull request closed, reopened, and then merged wakes once for each end", () =>
4859 + Effect.gen(function* () {
4860 + const orchestrator = yield* Orchestrator.OrchestratorV2;
4861 + const threadId = ThreadId.make("runtime-pull-request-watch-reopened");
4862 + const projectId = ProjectId.make("pr-watch-reopened-project");
4863 + yield* seedProject({
4864 + projectId,
4865 + title: "Watch reopened",
4866 + workspaceRoot: "/workspace/watch-reopened",
4867 + defaultModelSelection: null,
4868 + createdAt: "2026-10-01T00:00:00.000Z",
4869 + });
4870 + yield* orchestrator.dispatch({
4871 + type: "thread.create",
4872 + createdBy: "user",
4873 + creationSource: "web",
4874 + commandId: CommandId.make("pr-watch-reopened-create"),
4875 + threadId,
4876 + projectId,
4877 + title: "Watch reopened",
4878 + modelSelection,
4879 + runtimeMode: "full-access",
4880 + interactionMode: "default",
4881 + branch: null,
4882 + worktreePath: null,
4883 + });
4884 + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 16 };
4885 + const watch = (id: string) =>
4886 + orchestrator.dispatch({
4887 + type: "thread.pull-request.watch",
4888 + commandId: CommandId.make(`pr-watch-reopened-${id}`),
4889 + threadId,
4890 + ...key,
4891 + watching: true,
4892 + link: { url: "https://github.com/pingdotgg/t3code/pull/16", source: "agent" },
4893 + });
4894 + yield* watch("start");
4895 +
4896 + let state: PullRequestDetail["state"] = "closed";
4897 + const host = Layer.mergeAll(
4898 + NodeServices.layer,
4899 + NodeCrypto.layer,
4900 + Layer.mock(PullRequestService.PullRequestService)({
4901 + detail: () =>
4902 + Effect.sync(() => ({
4903 + ...watchedPullRequestDetail({
4904 + projectId,
4905 + number: 16,
4906 + at: "2026-10-02T12:00:00.000Z",
4907 + }),
4908 + state,
4909 + checks: [{ name: "lint", status: "pending" as const, description: null, url: null }],
4910 + })),
4911 + activity: () =>
4912 + Effect.succeed({
4913 + comments: [],
4914 + commentCount: 0,
4915 + commentsTruncated: false,
4916 + reviewThreads: [],
4917 + commits: [],
4918 + }),
4919 + }),
4920 + );
4921 + const summaries = Effect.map(
4922 + orchestrator.getThreadRecords(threadId, ["messages"]),
4923 + ({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []),
4924 + );
4925 + const watching = Effect.map(
4926 + orchestrator.getThreadShell(threadId),
4927 + (thread) => thread?.pullRequests?.[0]?.watch !== undefined,
4928 + );
4929 + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
4930 + yield* reactor.sweep;
4931 + assert.deepEqual(yield* summaries, ["#16: closed, stopped watching"]);
4932 + assert.isFalse(yield* watching);
4933 +
4934 + // Reopening does not restart the watch; the agent was told to watch again.
4935 + state = "open";
4936 + yield* watch("again");
4937 + yield* TestClock.adjust("10 minutes");
4938 + yield* reactor.sweep;
4939 + assert.isTrue(yield* watching);
4940 + assert.deepEqual(yield* summaries, ["#16: closed, stopped watching"]);
4941 +
4942 + // The link's own sync can see the merge before the watch reads it.
4943 + state = "merged";
4944 + yield* orchestrator.dispatch({
4945 + type: "thread.pull-request-link.sync",
4946 + commandId: CommandId.make("pr-watch-reopened-synced"),
4947 + threadId,
4948 + ...key,
4949 + snapshot: {
4950 + state: "merged",
4951 + title: "Watched pull request",
4952 + headBranch: "feature",
4953 + baseBranch: "main",
4954 + isDraft: false,
4955 + updatedAt: null,
4956 + syncedAt: "2026-10-02T12:30:00.000Z",
4957 + mergedAt: "2026-10-02T12:30:00.000Z",
4958 + },
4959 + stack: null,
4960 + });
4961 + yield* TestClock.adjust("10 minutes");
4962 + yield* reactor.sweep;
4963 + assert.deepEqual(yield* summaries, [
4964 + "#16: closed, stopped watching",
4965 + "#16: merged, stopped watching",
4966 + ]);
4967 + assert.isFalse(yield* watching);
4968 + }),
4969 + );
4970 +
4971 + it.effect.each([
4972 + // A transport failure, which an open pull request's watch outlasts.
4973 + { name: "unreachable", reason: "failed" },
4974 + // A rate limit pauses the watch before its detail read.
4975 + { name: "rate-limited", reason: "rate-limited" },
4976 + ] as const)(
4977 + "wakes from a merged snapshot when the host cannot be read ($name)",
4978 + ({ name, reason }) =>
4979 + Effect.gen(function* () {
4980 + const orchestrator = yield* Orchestrator.OrchestratorV2;
4981 + const projectId = ProjectId.make(`pr-watch-merged-unreadable-${name}-project`);
4982 + yield* seedProject({
4983 + projectId,
4984 + title: "Watch merged unreadable",
4985 + workspaceRoot: `/workspace/watch-merged-unreadable-${name}`,
4986 + defaultModelSelection: null,
4987 + createdAt: "2026-10-01T00:00:00.000Z",
4988 + });
4989 + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 8 };
4990 + // Another thread watches the same pull request, before its own link syncs.
4991 + const [merged, unsynced] = (["merged", "unsynced"] as const).map((which) =>
4992 + ThreadId.make(`runtime-pull-request-watch-merged-unreadable-${name}-${which}`),
4993 + ) as [ThreadId, ThreadId];
4994 + for (const threadId of [merged, unsynced]) {
4995 + yield* orchestrator.dispatch({
4996 + type: "thread.create",
4997 + createdBy: "user",
4998 + creationSource: "web",
4999 + commandId: CommandId.make(`${threadId}-create`),
5000 + threadId,
5001 + projectId,
5002 + title: "Watch merged unreadable",
5003 + modelSelection,
5004 + runtimeMode: "full-access",
5005 + interactionMode: "default",
5006 + branch: null,
5007 + worktreePath: null,
5008 + });
5009 + yield* orchestrator.dispatch({
5010 + type: "thread.pull-request.watch",
5011 + commandId: CommandId.make(`${threadId}-start`),
5012 + threadId,
5013 + ...key,
5014 + watching: true,
5015 + link: { url: "https://github.com/pingdotgg/t3code/pull/8", source: "agent" },
5016 + });
5017 + }
5018 + yield* orchestrator.dispatch({
5019 + type: "thread.pull-request-link.sync",
5020 + commandId: CommandId.make(`${merged}-synced`),
5021 + threadId: merged,
5022 + ...key,
5023 + snapshot: {
5024 + state: "merged",
5025 + title: "Watched pull request",
5026 + headBranch: "feature",
5027 + baseBranch: "main",
5028 + isDraft: false,
5029 + updatedAt: null,
5030 + syncedAt: "2026-10-02T12:30:00.000Z",
5031 + mergedAt: "2026-10-02T12:30:00.000Z",
5032 + },
5033 + stack: null,
5034 + });
5035 + const failure = (operation: string) =>
5036 + new PullRequestOperationError({
5037 + operation,
5038 + detail: "host unreadable",
5039 + cause: new PullRequestProviderError({
5040 + provider: SourceControlProviderKind.make("github"),
5041 + operation,
5042 + reason,
5043 + detail: "host unreadable",
5044 + }),
5045 + });
5046 + const reactor = yield* PullRequestWatchReactor.make.pipe(
5047 + Effect.provide(
5048 + Layer.mergeAll(
5049 + NodeServices.layer,
5050 + NodeCrypto.layer,
5051 + Layer.mock(PullRequestService.PullRequestService)({
5052 + watchFingerprint: () =>
5053 + reason === "rate-limited"
5054 + ? Effect.fail(failure("watchFingerprint"))
5055 + : Effect.succeed(null),
5056 + invalidate: () => Effect.void,
5057 + detail: () => Effect.fail(failure("detail")),
5058 + activity: () => Effect.fail(failure("activity")),
5059 + }),
5060 + ),
5061 + ),
5062 + );
5063 + yield* reactor.sweep;
5064 + yield* TestClock.adjust("10 minutes");
5065 + yield* reactor.sweep;
5066 +
5067 + const watchOf = (threadId: ThreadId) =>
5068 + Effect.map(
5069 + orchestrator.getThreadShell(threadId),
5070 + (thread) => thread?.pullRequests?.[0]?.watch,
5071 + );
5072 + assert.isUndefined(yield* watchOf(merged));
5073 + assert.isDefined(yield* watchOf(unsynced));
5074 + const wakes = (yield* orchestrator.getThreadRecords(merged, ["messages"])).messages.filter(
5075 + (message) => message.notification != null,
5076 + );
5077 + assert.deepEqual(
5078 + wakes.map((message) => message.notification?.summary),
5079 + ["#8: merged, stopped watching"],
5080 + );
5081 + assert.include(wakes[0]!.text, "merged into main, so");
5082 + }),
5083 + );
5084 +
5085 it.effect("ends a watch on a closed pull request whose activity cannot be read", () =>
5086 Effect.gen(function* () {
5087 const orchestrator = yield* Orchestrator.OrchestratorV2;
@@ -5570,7 +6059,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
6059 ];
6060 const detailReads = yield* Queue.unbounded<void>();
6061 const watchListings = yield* Queue.unbounded<void>();
5573 - const domainEvents = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
6062 + const domainEvents = yield* PubSub.unbounded<OrchestrationV2DomainEvent>({ replay: 16 });
6063 const host = Layer.mergeAll(
6064 NodeServices.layer,
6065 NodeCrypto.layer,
@@ -5602,10 +6091,11 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
6091 invalidate: () => Effect.void,
6092 changes: () => Stream.never,
6093 }),
5605 - // Events come from a queue that exists before the reactor subscribes, so none is missed.
6094 + // Each subscriber reads every event, as each event sink stream does, and replay means one
6095 + // that subscribes late misses none.
6096 Layer.mock(Orchestrator.OrchestratorV2)({
6097 dispatch: orchestrator.dispatch,
5608 - streamDomainEvents: Stream.fromQueue(domainEvents),
6098 + streamDomainEvents: Stream.fromPubSub(domainEvents),
6099 }),
6100 Layer.mock(ProjectionStore.ProjectionStoreV2)({
6101 getThreadsWithPullRequests: (id) =>
@@ -5636,7 +6126,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
6126 watching: true,
6127 link: { url: "https://github.com/pingdotgg/t3code/pull/16", source: "agent" },
6128 });
5639 - yield* Queue.offerAll(
6129 + yield* PubSub.publishAll(
6130 domainEvents,
6131 started.storedEvents.map((stored) => stored.event),
6132 );
apps/server/src/pullRequest/PullRequestService.ts
+4
@@ -1928,6 +1928,10 @@ export const make = Effect.gen(function* () {
1928 updatedAt: changeRequest.updatedAt,
1929 observedAt,
1930 mergedAt: changeRequest.mergedAt,
1931 + ...(changeRequest.mergeCommitSha
1932 + ? { mergeCommitSha: changeRequest.mergeCommitSha }
1933 + : {}),
1934 + ...(changeRequest.mergedBy ? { mergedBy: changeRequest.mergedBy } : {}),
1935 closedAt: changeRequest.closedAt,
1936 reviewers: changeRequest.reviewers,
1937 labels: changeRequest.labels,
apps/server/src/sourceControl/sourceControlDefinitions.test.ts
+24
@@ -2,6 +2,7 @@ import { expect, it } from "@effect/vitest";
2
3 import {
4 BUILT_IN_SOURCE_CONTROL_DRIVER_LIST,
5 + changeRequestsClosedBy,
6 sourceControlDefinitions,
7 } from "./sourceControlDefinitions.ts";
8
@@ -53,3 +54,26 @@ it.each([
54 ])("does not read %s as an issue", (url) => {
55 expect(sourceControlDefinitions.parseIssueUrl(url)).toBeNull();
56 });
57 +
58 +it.each([
59 + ["gh pr merge 19 --squash", [19]],
60 + ['gh pr merge "19" --squash', [19]],
61 + ['/bin/zsh -lc "gh pr merge 19"', [19]],
62 + ['gh pr merge 19 --squash --subject "Release 20"', [19]],
63 + [`/bin/zsh -lc "gh pr merge 19 --subject 'Release 20'"`, [19]],
64 + ["gh pr merge 19 --body 'see https://github.com/o/r/pull/20'", [19]],
65 + ["gh pr merge 19 --body https://github.com/o/r/pull/20", [19]],
66 + ["gh pr merge 19 # then 20", [19]],
67 + ["gh pr merge --squash --match-head-commit 3b2f958 #19", [19]],
68 + ["gh pr close https://github.com/o/r/pull/19 && gh pr merge 20", [19, 20]],
69 + ["glab mr merge https://gitlab.com/o/r/-/merge_requests/7", [7]],
70 + ["sleep 30; cafe pr merge 26271", [26271]],
71 + ["az repos pr update --id 19 --status completed", [19]],
72 + ["az repos pr update --id=19 --status=abandoned", [19]],
73 + ["gh pr merge --squash", "any"],
74 + ["gh stack merge", "any"],
75 + ["gh pr merge 19 && gh pr merge --auto", "any"],
76 +] as const)("%s closes %j", (command, expected) => {
77 + const closed = changeRequestsClosedBy(command);
78 + expect(closed === "any" ? closed : [...closed]).toEqual(expected);
79 +});
apps/server/src/sourceControl/sourceControlDefinitions.ts
+39
@@ -19,3 +19,42 @@ export const BUILT_IN_SOURCE_CONTROL_DRIVER_LIST = [
19 ] as const;
20
21 export const sourceControlDefinitions = builtInSourceControlDefinitions;
22 +
23 +/** A host CLI command that merges or closes a change request, such as `gh pr merge`. */
24 +export const isChangeRequestCloseCommand = (command: string) =>
25 + sourceControlDefinitions.definitions.some(
26 + (definition) => definition.changeRequestCloseCommand?.test(command) === true,
27 + );
28 +
29 +// A quoted or bare shell word. An unclosed quote, as Codex's `/bin/zsh -lc "gh pr merge 19"`
30 +// leaves after the match, runs to the end.
31 +const SHELL_WORD = /"((?:\\[\s\S]|[^"\\])*)"?|'([^']*)'?|((?:\\[\s\S]|[^\s"'\\])+)/gu;
32 +// A whole word that names one, so a number inside `--subject "Release 20"` does not.
33 +const NAMED_CHANGE_REQUEST = /^(?:--?[\w-]+=)?#?(\d+)$|^\S*\/(?:pulls?|merge_requests)\/(\d+)\/?$/u;
34 +
35 +/**
36 + * The change request numbers a merge or close command names, or "any" when one names none, as a
37 + * bare `gh pr merge` on the checked-out branch or `gh stack merge` does.
38 + */
39 +export function changeRequestsClosedBy(command: string): ReadonlySet<number> | "any" {
40 + const named = new Set<number>();
41 + for (const { changeRequestCloseCommand: close } of sourceControlDefinitions.definitions) {
42 + if (close === undefined) continue;
43 + for (const match of command.matchAll(new RegExp(close.source, `${close.flags}g`))) {
44 + // From the match's start, since Azure's match runs through `--id` to `--status`.
45 + const args = command.slice(match.index).split(/[;&|\n]/u, 1)[0] ?? "";
46 + // Every host's merge and close takes one change request, so any later one is option text.
47 + let target: string | undefined;
48 + for (const [, double, single, bare] of args.matchAll(SHELL_WORD)) {
49 + // A comment ends the command.
50 + if (bare !== undefined && /^#(?!\d+$)/u.test(bare)) break;
51 + const [, number, url] = NAMED_CHANGE_REQUEST.exec(double ?? single ?? bare ?? "") ?? [];
52 + target = number ?? url;
53 + if (target !== undefined) break;
54 + }
55 + if (target === undefined) return "any";
56 + named.add(Number(target));
57 + }
58 + }
59 + return named.size === 0 ? "any" : named;
60 +}
docs/user/source-control.md
+3 -2
@@ -337,8 +337,9 @@ check fails or waits for a maintainer's approval, the required checks pass, some
337 conflict. On github.com it also wakes the agent, with GitHub's reason, when the merge queue drops
338 the pull request without merging it. Threads in a project that watch the same pull request share one check. On GitHub, a check
339 first asks whether anything changed and reads the pull request only when it did, which keeps
340 -watching inside GitHub's rate limit. Comments from your own account do not wake it. Watching ends
341 -when the pull request merges or closes, after 10 wakes in a row that bring only comments, after 8
340 +watching inside GitHub's rate limit. Comments from your own account do not wake it. When the pull
341 +request merges or closes, watching ends, and the agent is woken once unless it merged or closed the
342 +pull request itself with the host's CLI. A reopened pull request needs a new watch. Watching also ends after 10 wakes in a row that bring only comments, after 8
343 failed reads in a row, or when you press Stop on the thread. A rate limit only pauses watching.
344 Settling or archiving a thread also ends all its watches. Unsettle the thread before starting a new
345 watch. Watching a pull request again does not repeat check or conflict news its last
packages/contracts/src/pullRequest.ts
+2
@@ -667,6 +667,8 @@ export const PullRequestDetail = Schema.Struct({
667 updatedAt: IsoDateTime,
668 observedAt: Schema.optional(Schema.Finite),
669 mergedAt: Schema.NullOr(IsoDateTime),
670 + mergeCommitSha: Schema.optional(TrimmedNonEmptyString),
671 + mergedBy: Schema.optional(PullRequestActor),
672 closedAt: Schema.NullOr(IsoDateTime),
673 reviewers: Schema.Array(PullRequestActor),
674 labels: Schema.Array(PullRequestLabel),
packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
+21
@@ -411,6 +411,12 @@ describe("derivePendingBackgroundWork kinds", () => {
411 kind: "monitor",
412 awaited: true,
413 },
414 + {
415 + taskId: "pull-request-watch:github.com/acme/app#4",
416 + description: "Watching pull request #4",
417 + kind: "monitor",
418 + awaited: true,
419 + },
420 {
421 taskId: "pull-request-watch:github.com/acme/app#5",
422 description: "Watching pull request #5",
@@ -431,6 +437,7 @@ describe("derivePendingBackgroundWork kinds", () => {
437 }).map((task) => task.taskId),
438 ).toEqual([
439 "pull-request-watch:github.com/acme/app#1",
440 + "pull-request-watch:github.com/acme/app#4",
441 "pull-request-watch:github.com/acme/app#5",
442 ]);
443 });
@@ -471,6 +478,20 @@ describe("derivePendingBackgroundWork kinds", () => {
478 pullRequests: [{ ...link(1, {}), watch: { ...watch, checksPending: true } }],
479 });
480 expect(backgroundWorkHoldsCompletion(running)).toBe(true);
481 +
482 + // Its watch has yet to wake the agent with the merge, so settling on merge waits for it.
483 + const merged = derivePendingBackgroundWork({
484 + latestRun: { id: "run-1" as never, ordinal: 1, status: "completed" },
485 + providerThreads: [],
486 + turnItems: [],
487 + pullRequests: [
488 + {
489 + ...link(1, { state: "merged" }),
490 + watch: { ...watch, passed: true, checksPending: false },
491 + },
492 + ],
493 + });
494 + expect(backgroundWorkHoldsCompletion(merged)).toBe(true);
495 });
496
497 it("lists no watch while a run is active", () => {
packages/shared/src/orchestrationV2PendingBackgroundWork.ts
+5 -5
@@ -314,10 +314,7 @@ function pullRequestWatchTasks(
314 pullRequests: ReadonlyArray<PendingBackgroundWorkPullRequest> | undefined,
315 ): Array<PendingBackgroundWorkTask> {
316 return (pullRequests ?? []).flatMap((link) =>
317 - // The watch reactor ends a merged PR's watch without waking the agent, so it holds nothing.
318 - link.watch === undefined ||
319 - link.source === "stack-dismissed" ||
320 - link.snapshot?.state === "merged"
317 + link.watch === undefined || link.source === "stack-dismissed"
318 ? []
319 : [
320 {
@@ -327,7 +324,10 @@ function pullRequestWatchTasks(
324 description: `Watching pull request #${link.number}`,
325 kind: "monitor" as const,
326 // Once every check finished, a person moves the PR next: the watch stays on but holds nothing.
330 - ...(link.watch.checksPending === false ? {} : { awaited: true as const }),
327 + // A merged PR's watch holds until its read wakes the agent, so settling on merge waits.
328 + ...(link.watch.checksPending === false && link.snapshot?.state !== "merged"
329 + ? {}
330 + : { awaited: true as const }),
331 },
332 ],
333 );
packages/shared/src/toolOutput.ts
+13
@@ -284,6 +284,19 @@ export function toolOutputIndicatesFailure(text: string): boolean {
284 );
285 }
286
287 +/** Whether a command failed. A reported exit code outranks text in its output. */
288 +export function commandIndicatesFailure(command: {
289 + readonly exitCode?: number | undefined;
290 + readonly outputIndicatesFailure?: boolean | undefined;
291 + readonly output?: string | undefined;
292 +}): boolean {
293 + if (command.exitCode !== undefined) return command.exitCode !== 0;
294 + return (
295 + command.outputIndicatesFailure === true ||
296 + (command.output !== undefined && toolOutputIndicatesFailure(command.output.slice(0, 32_768)))
297 + );
298 +}
299 +
300 export interface ToolOutputImage {
301 readonly mimeType: string;
302 readonly data?: string;
packages/source-control-core/src/server/PullRequestProvider.ts
+2
@@ -217,6 +217,8 @@ export interface ProviderChangeRequestDetail extends ProviderChangeRequest {
217 readonly body: string;
218 readonly changedFiles: number;
219 readonly mergedAt: string | null;
220 + readonly mergeCommitSha?: string | null;
221 + readonly mergedBy?: PullRequestActor | null;
222 readonly closedAt: string | null;
223 readonly reviewers: ReadonlyArray<PullRequestActor>;
224 readonly checks: ReadonlyArray<PullRequestCheck>;
packages/source-control-forgejo/src/server/ForgejoPullRequestProvider.ts
+2
@@ -368,6 +368,8 @@ export const make = Effect.gen(function* () {
368 return {
369 ...forgejoChangeRequest(pr),
370 headSha: pr.head.sha,
371 + mergeCommitSha: pr.merge_commit_sha || null,
372 + mergedBy: forgejoActor(pr.merged_by),
373 body: pr.body ?? "",
374 changedFiles: pr.changed_files ?? 0,
375 reviewers: (pr.requested_reviewers ?? []).flatMap((user) => {
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+24 -1
@@ -138,6 +138,7 @@ const requiredChecksInput = {
138 const requiredChecksLayer = (
139 branch: Effect.Effect<unknown, ForgejoCli.ForgejoCliError>,
140 statuses = requiredChecksStatuses,
141 + pull: Readonly<Record<string, unknown>> = requiredChecksPullRequest,
142 ) =>
143 Layer.mock(ForgejoCli.ForgejoCli)({
144 api: (input) => {
@@ -146,7 +147,7 @@ const requiredChecksLayer = (
147 encodeJsonEffect(response).pipe(Effect.orDie, Effect.map(processOutput));
148 switch (path) {
149 case "repos/acme/web/pulls/7":
149 - return respond(requiredChecksPullRequest);
150 + return respond(pull);
151 case "repos/acme/web/statuses/head":
152 return respond(new URLSearchParams(query).get("page") === "1" ? statuses : []);
153 case "repos/acme/web/branches/release/1.x":
@@ -421,6 +422,28 @@ it.effect.each([
422 }).pipe(Effect.provide(requiredChecksLayer(Effect.fail(cause))));
423 });
424
425 +it.effect("reads a merged pull request's merge commit and who merged it", () =>
426 + Effect.gen(function* () {
427 + const provider = yield* ForgejoPullRequestProvider.make;
428 + const detail = yield* provider.getChangeRequest(requiredChecksInput);
429 + assert.strictEqual(detail.state, "merged");
430 + assert.strictEqual(detail.mergeCommitSha, "394a757942c5c3a9fb3cca31e348849e8c6a6dbe");
431 + assert.deepStrictEqual(detail.mergedBy, { login: "gusted", name: null, avatarUrl: null });
432 + }).pipe(
433 + Effect.provide(
434 + requiredChecksLayer(Effect.succeed({ name: "release/1.x" }), [], {
435 + ...requiredChecksPullRequest,
436 + state: "closed",
437 + merged: true,
438 + closed_at: "2026-10-27T00:08:58+01:00",
439 + merged_at: "2026-10-27T00:08:58+01:00",
440 + merge_commit_sha: "394a757942c5c3a9fb3cca31e348849e8c6a6dbe",
441 + merged_by: { login: "gusted" },
442 + }),
443 + ),
444 + ),
445 +);
446 +
447 it.effect("reads Forgejo jobs that did not run as finished checks", () =>
448 Effect.gen(function* () {
449 const provider = yield* ForgejoPullRequestProvider.make;
packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts
+2
@@ -61,6 +61,8 @@ export const ForgejoPullRequest = Schema.Struct({
61 updated_at: Schema.String,
62 closed_at: Schema.NullOr(Schema.String),
63 merged_at: Schema.NullOr(Schema.String),
64 + merge_commit_sha: Schema.optional(Schema.NullOr(Schema.String)),
65 + merged_by: Schema.optional(Schema.NullOr(ForgejoUser)),
66 additions: Schema.optional(Schema.NullOr(Schema.Int)),
67 deletions: Schema.optional(Schema.NullOr(Schema.Int)),
68 changed_files: Schema.optional(Schema.NullOr(Schema.Int)),
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts
+3 -1
@@ -1097,7 +1097,8 @@ describe("GitCafePullRequestProvider", () => {
1097
1098 it.effect("reads a pull request GitHub merged as merged before the sync reports it", () => {
1099 const mergedAt = "2026-09-12T13:00:00Z";
1100 - const server = detailWith({ providerMerge: { mergedAt } });
1100 + const mergeCommitOid = "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9";
1101 + const server = detailWith({ providerMerge: { mergedAt, mergeCommitOid } });
1102 return Effect.gen(function* () {
1103 const provider = yield* GitCafePullRequestProvider.make;
1104 const detail = yield* provider.getChangeRequest(target);
@@ -1105,6 +1106,7 @@ describe("GitCafePullRequestProvider", () => {
1106 assert.strictEqual(detail.mergedAt, mergedAt);
1107 const preview = yield* provider.getChangeRequestPreview!(target);
1108 assert.strictEqual(preview.state, "merged");
1109 + assert.strictEqual(detail.mergeCommitSha, mergeCommitOid);
1110 }).pipe(Effect.provide(server.layer));
1111 });
1112
packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.ts
+1
@@ -994,6 +994,7 @@ export const make = Effect.gen(function* () {
994 changedFiles: changes?.changedFiles ?? 0,
995 closedAt: pull.closedAt,
996 mergedAt: pull.mergedAt,
997 + mergeCommitSha: pull.mergeResultOid || pull.providerMerge?.mergeCommitOid || null,
998 ...settledMerge(pull),
999 reviewers: Json.toReviewers(listed, input.host),
1000 checks: checkList,
packages/source-control-gitcafe/src/server/gitCafePullRequestJson.ts
+9 -1
@@ -88,9 +88,17 @@ export const GitCafePullDetail = Schema.Struct({
88 mergeRoute: Schema.optional(Schema.Literals(["native", "provider", "unsupported"])),
89 lockedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
90 viewerActorId: Schema.optional(Schema.NullOr(Schema.String)),
91 + mergeResultOid: Schema.optional(Schema.NullOr(Schema.String)),
92 // Set once GitHub has merged a pull request GitCafe routed there, which can be before the
93 // sync brings the merged state back.
93 - providerMerge: Schema.optional(Schema.NullOr(Schema.Struct({ mergedAt: IsoDateTime }))),
94 + providerMerge: Schema.optional(
95 + Schema.NullOr(
96 + Schema.Struct({
97 + mergedAt: IsoDateTime,
98 + mergeCommitOid: Schema.optional(Schema.NullOr(Schema.String)),
99 + }),
100 + ),
101 + ),
102 capabilities: Schema.Struct({
103 comment: Schema.Boolean,
104 review: Schema.Boolean,
packages/source-control-github/src/server/GitHubPullRequestApi.test.ts
+2
@@ -76,6 +76,8 @@ const coreResponse = (pullRequest: Readonly<Record<string, unknown>> = {}) => ({
76 deletions: 0,
77 changedFiles: 0,
78 mergedAt: null,
79 + mergeCommit: null,
80 + mergedBy: null,
81 closedAt: null,
82 isCrossRepository: false,
83 maintainerCanModify: true,
packages/source-control-github/src/server/gitHubPullRequestJson.test.ts
+22
@@ -393,6 +393,8 @@ describe("pull request detail decoding", () => {
393 createdAt: "2026-07-01T00:00:00Z",
394 updatedAt: "2026-07-05T00:00:00Z",
395 mergedAt: null,
396 + mergeCommit: null,
397 + mergedBy: null,
398 closedAt: null,
399 headRefName: "feat/detail",
400 baseRefName: "main",
@@ -551,6 +553,26 @@ describe("pull request detail decoding", () => {
553 expect(detail.checksState).toBe("pending");
554 });
555
556 + it("reads a merged pull request's merge commit and who merged it", () => {
557 + expect(
558 + detailOf([], {
559 + state: "MERGED",
560 + mergedAt: "2026-07-05T00:00:00Z",
561 + mergeCommit: { oid: "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9" },
562 + mergedBy: {
563 + __typename: "User",
564 + login: "octocat",
565 + avatarUrl: "https://avatars.githubusercontent.com/u/1",
566 + name: "Octo Cat",
567 + },
568 + }),
569 + ).toMatchObject({
570 + state: "merged",
571 + mergeCommitSha: "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9",
572 + mergedBy: { login: "octocat", name: "Octo Cat" },
573 + });
574 + });
575 +
576 it("reads an auto-merge request and strategy, and its null as off", () => {
577 expect(detailOf([], { autoMergeRequest: { mergeMethod: "SQUASH" } })).toMatchObject({
578 autoMergeEnabled: true,
packages/source-control-github/src/server/gitHubPullRequestJson.ts
+4
@@ -1031,6 +1031,8 @@ export interface GitHubPullRequestCore extends GitHubPullRequestDetail {
1031 readonly mergeQueueRemoval?: PullRequestMergeQueueRemoval;
1032 readonly maintainerCanModify: boolean;
1033 readonly canEditMaintainerEdits: boolean;
1034 + readonly mergeCommitSha?: string | null;
1035 + readonly mergedBy?: PullRequestActor | null;
1036 readonly reviewRequestTeams: ReadonlyArray<PullRequestActor>;
1037 readonly viewerAccess: GitHubViewerAccess & GitHubRepositoryAccess;
1038 readonly comparison: GitHubBaseComparison | null;
@@ -1094,6 +1096,8 @@ export function toPullRequestCore(result: PullRequestCore.Result): GitHubPullReq
1096 pr.headRepositoryOwner?.__typename === "User" &&
1097 pr.headRepository !== null &&
1098 pr.headRef !== null,
1099 + mergeCommitSha: trimmed(pr.mergeCommit?.oid),
1100 + mergedBy: toActor(pr.mergedBy),
1101 viewerAccess: {
1102 canWrite: toCanWrite(repository.viewerPermission),
1103 canDeleteBranch: toCanWrite(pr.headRepository?.viewerPermission) && pr.headRef !== null,
packages/source-control-github/src/server/pullRequestReads.graphql
+10
@@ -83,6 +83,16 @@ query PullRequestCore(
83 createdAt
84 updatedAt
85 mergedAt
86 + mergeCommit {
87 + oid
88 + }
89 + mergedBy {
90 + login
91 + avatarUrl
92 + ... on User {
93 + name
94 + }
95 + }
96 closedAt
97 headRefName
98 baseRefName
packages/source-control-github/src/server/pullRequestReads.graphql.ts
+45 -31
@@ -206,6 +206,35 @@ export declare namespace ActorAvatars {
206 export type Result = typeof ActorAvatars.result.Type
207 }
208
209 +/** Represents a Git commit. */
210 +export const MergeCommitCommit = Schema.Struct({
211 + /** The Git object ID */
212 + oid: Shared.GitObjectID
213 +})
214 +export interface MergeCommitCommit extends Schema.Struct.Type<typeof MergeCommitCommit.fields> {}
215 +
216 +/** A user is an individual's account on GitHub that owns repositories and can make new content. */
217 +export const MergedByUser = Schema.Struct({
218 + __typename: Schema.Literal("User"),
219 + /** The username used to login. */
220 + login: Schema.String,
221 + /** A URL pointing to the user's public avatar. */
222 + avatarUrl: Shared.URI,
223 + /** The user's public profile name. */
224 + name: Schema.NullOr(Schema.String)
225 +})
226 +export interface MergedByUser extends Schema.Struct.Type<typeof MergedByUser.fields> {}
227 +
228 +/** Represents an object which can take actions on GitHub. Typically a User or Bot. */
229 +export const ActorOther = Schema.Struct({
230 + __typename: GraphQL.otherTypename<Shared.Typename.Actor>()(["User"]),
231 + /** The username of the actor. */
232 + login: Schema.String,
233 + /** A URL pointing to the actor's public avatar. */
234 + avatarUrl: Shared.URI
235 +})
236 +export interface ActorOther extends Schema.Struct.Type<typeof ActorOther.fields> {}
237 +
238 /** Represents an owner of a Repository. */
239 export const RepositoryOwner = Schema.Struct({
240 __typename: GraphQL.otherTypename<Shared.Typename.RepositoryOwner>()([]),
@@ -231,7 +260,7 @@ export const HeadRefRef = Schema.Struct({
260 export interface HeadRefRef extends Schema.Struct.Type<typeof HeadRefRef.fields> {}
261
262 /** A user is an individual's account on GitHub that owns repositories and can make new content. */
234 -export const PullRequestCoreRepositoryPullRequestAuthorUser = Schema.Struct({
263 +export const AuthorUser = Schema.Struct({
264 __typename: Schema.Literal("User"),
265 /** The username used to login. */
266 login: Schema.String,
@@ -242,17 +271,7 @@ export const PullRequestCoreRepositoryPullRequestAuthorUser = Schema.Struct({
271 /** The user's public profile name. */
272 name: Schema.NullOr(Schema.String)
273 })
245 -export interface PullRequestCoreRepositoryPullRequestAuthorUser extends Schema.Struct.Type<typeof PullRequestCoreRepositoryPullRequestAuthorUser.fields> {}
246 -
247 -/** Represents an object which can take actions on GitHub. Typically a User or Bot. */
248 -export const ActorOther = Schema.Struct({
249 - __typename: GraphQL.otherTypename<Shared.Typename.Actor>()(["User"]),
250 - /** The username of the actor. */
251 - login: Schema.String,
252 - /** A URL pointing to the actor's public avatar. */
253 - avatarUrl: Shared.URI
254 -})
255 -export interface ActorOther extends Schema.Struct.Type<typeof ActorOther.fields> {}
274 +export interface AuthorUser extends Schema.Struct.Type<typeof AuthorUser.fields> {}
275
276 /** Represents an auto-merge request for a pull request */
277 export const AutoMergeRequest = Schema.Struct({
@@ -459,6 +478,13 @@ export const PullRequestCoreRepositoryPullRequestPullRequest = Schema.Struct({
478 updatedAt: Shared.DateTime,
479 /** The date and time that the pull request was merged. */
480 mergedAt: Schema.NullOr(Shared.DateTime),
481 + /** The commit that was created when this pull request was merged. */
482 + mergeCommit: Schema.NullOr(MergeCommitCommit),
483 + /** The actor who merged the pull request. */
484 + mergedBy: Schema.NullOr(Schema.Union([
485 + MergedByUser,
486 + ActorOther
487 + ])),
488 /** Identifies the date and time when the object was closed. */
489 closedAt: Schema.NullOr(Shared.DateTime),
490 /** Identifies the name of the head Ref associated with the pull request, even if the ref has been deleted. */
@@ -479,7 +505,7 @@ export const PullRequestCoreRepositoryPullRequestPullRequest = Schema.Struct({
505 headRef: Schema.NullOr(HeadRefRef),
506 /** The actor who authored the comment. */
507 author: Schema.NullOr(Schema.Union([
482 - PullRequestCoreRepositoryPullRequestAuthorUser,
508 + AuthorUser,
509 ActorOther
510 ])),
511 /** Returns the auto-merge request object if one exists for this pull request. */
@@ -536,7 +562,7 @@ export const PullRequestCore = GraphQL.query("PullRequestCore", {
562 { name: "mergeQueue", body: "Boolean!" }
563 ],
564 selections: [
539 - { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed autoMergeAllowed viewerPermission pullRequest(number:$", "number", "){number title url body state isDraft mergeable mergeStateStatus reviewDecision additions deletions changedFiles createdAt updatedAt mergedAt closedAt headRefName baseRefName headRefOid isCrossRepository maintainerCanModify headRepositoryOwner{__typename login}headRepository{nameWithOwner viewerPermission}headRef{id}author{__typename login avatarUrl...on User{id name}}autoMergeRequest{mergeMethod}mergeQueueRemovals:timelineItems(last:1 itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){nodes{__typename...on RemovedFromMergeQueueEvent{id createdAt reason}}}viewerCanUpdate viewerDidAuthor viewerCanUpdateBranch baseRef{compare(headRef:$", "headRef", "){behindBy}}reviewRequests(first:$", "requestedReviewers", "){nodes{requestedReviewer{__typename...on User{login name}...on Bot{login}...on Team{slug combinedSlug teamName:name teamAvatarUrl:avatarUrl}}}}labels(first:100){nodes{name color description}}commits(last:1){nodes{commit{statusCheckRollup{contexts(first:100){nodes{__typename...", "CheckContext", "}pageInfo{hasNextPage endCursor}}}}}}}}"] }
565 + { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed autoMergeAllowed viewerPermission pullRequest(number:$", "number", "){number title url body state isDraft mergeable mergeStateStatus reviewDecision additions deletions changedFiles createdAt updatedAt mergedAt mergeCommit{oid}mergedBy{__typename login avatarUrl...on User{name}}closedAt headRefName baseRefName headRefOid isCrossRepository maintainerCanModify headRepositoryOwner{__typename login}headRepository{nameWithOwner viewerPermission}headRef{id}author{__typename login avatarUrl...on User{id name}}autoMergeRequest{mergeMethod}mergeQueueRemovals:timelineItems(last:1 itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){nodes{__typename...on RemovedFromMergeQueueEvent{id createdAt reason}}}viewerCanUpdate viewerDidAuthor viewerCanUpdateBranch baseRef{compare(headRef:$", "headRef", "){behindBy}}reviewRequests(first:$", "requestedReviewers", "){nodes{requestedReviewer{__typename...on User{login name}...on Bot{login}...on Team{slug combinedSlug teamName:name teamAvatarUrl:avatarUrl}}}}labels(first:100){nodes{name color description}}commits(last:1){nodes{commit{statusCheckRollup{contexts(first:100){nodes{__typename...", "CheckContext", "}pageInfo{hasNextPage endCursor}}}}}}}}"] }
566 ],
567 fragments: [
568 { name: "CheckContext", body: ["on StatusCheckRollupContext{__typename...on StatusContext{context state targetUrl createdAt description isRequired(pullRequestNumber:$", "number", ")@include(if:$", "required", ")}...on CheckRun{name status conclusion startedAt completedAt detailsUrl isRequired(pullRequestNumber:$", "number", ")@include(if:$", "required", ")checkSuite{workflowRun{workflow{name}}}}}"] }
@@ -611,18 +637,6 @@ export declare namespace PullRequestCheckContexts {
637 export type Result = typeof PullRequestCheckContexts.result.Type
638 }
639
614 -/** A user is an individual's account on GitHub that owns repositories and can make new content. */
615 -export const PullRequestPreviewRepositoryPullRequestAuthorUser = Schema.Struct({
616 - __typename: Schema.Literal("User"),
617 - /** The username used to login. */
618 - login: Schema.String,
619 - /** A URL pointing to the user's public avatar. */
620 - avatarUrl: Shared.URI,
621 - /** The user's public profile name. */
622 - name: Schema.NullOr(Schema.String)
623 -})
624 -export interface PullRequestPreviewRepositoryPullRequestAuthorUser extends Schema.Struct.Type<typeof PullRequestPreviewRepositoryPullRequestAuthorUser.fields> {}
625 -
640 /** A repository pull request. */
641 export const PullRequestPreviewRepositoryPullRequestPullRequest = Schema.Struct({
642 /** Identifies the pull request number. */
@@ -639,7 +653,7 @@ export const PullRequestPreviewRepositoryPullRequestPullRequest = Schema.Struct(
653 createdAt: Shared.DateTime,
654 /** The actor who authored the comment. */
655 author: Schema.NullOr(Schema.Union([
642 - PullRequestPreviewRepositoryPullRequestAuthorUser,
656 + MergedByUser,
657 ActorOther
658 ]))
659 })
@@ -762,7 +776,7 @@ export const NodesIssueComment = Schema.Struct({
776 isMinimized: Schema.Boolean,
777 /** The actor who authored the comment. */
778 author: Schema.NullOr(Schema.Union([
765 - PullRequestPreviewRepositoryPullRequestAuthorUser,
779 + MergedByUser,
780 ActorOther
781 ]))
782 })
@@ -795,7 +809,7 @@ export const NodesPullRequestReview = Schema.Struct({
809 isMinimized: Schema.Boolean,
810 /** The actor who authored the comment. */
811 author: Schema.NullOr(Schema.Union([
798 - PullRequestPreviewRepositoryPullRequestAuthorUser,
812 + MergedByUser,
813 ActorOther
814 ]))
815 })
@@ -814,7 +828,7 @@ export interface PullRequestReviewConnection extends Schema.Struct.Type<typeof P
828 export const PullRequestActivityRepositoryPullRequestPullRequest = Schema.Struct({
829 /** The actor who authored the comment. */
830 author: Schema.optionalKey(Schema.NullOr(Schema.Union([
817 - PullRequestPreviewRepositoryPullRequestAuthorUser,
831 + MergedByUser,
832 ActorOther
833 ]))),
834 /** A list of commits present in this pull request's head branch not present in the base branch. */
@@ -1198,7 +1212,7 @@ export interface Actor extends Schema.Struct.Type<typeof Actor.fields> {}
1212 export const ReviewerCandidatesRepositoryPullRequestReviewRequestsNodesReviewRequest = Schema.Struct({
1213 /** The reviewer that is requested. */
1214 requestedReviewer: Schema.NullOr(Schema.Union([
1201 - PullRequestPreviewRepositoryPullRequestAuthorUser,
1215 + MergedByUser,
1216 Team,
1217 NodesBot,
1218 RequestedReviewerOther