Skip to content

Commit 6110f02

Browse files
fix(server): a CI rerun keeps a watched thread working until its checks run
ci_rerun left a watch's finished-checks answer in place, so a thread whose agent re-ran checks and ended its turn returned to the inbox with a completion alert until a read saw the checks running. A rerun now clears that answer for the calling thread, as a push from its shell does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a3e399b commit 6110f02

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,46 @@ describe("source control tools", () => {
936936
}),
937937
);
938938

939+
it.effect("re-running checks reopens a watch that saw its checks finish", () =>
940+
Effect.gen(function* () {
941+
const watch = {
942+
startedAt: "2026-08-20T00:00:00.000Z",
943+
headSha: "abc123",
944+
failedChecks: ["test"],
945+
passed: false,
946+
passedChecks: [],
947+
remarksThrough: "2026-08-20T00:00:00.000Z",
948+
remarkIds: [],
949+
conflicting: false,
950+
wakes: 0,
951+
};
952+
const rerun = (checksPending: boolean | undefined, reran: boolean) =>
953+
Effect.gen(function* () {
954+
const harness = yield* makeHarness({
955+
thread: {
956+
...branchThread,
957+
pullRequests: [
958+
makeLink(42, {
959+
watch: checksPending === undefined ? watch : { ...watch, checksPending },
960+
}),
961+
],
962+
},
963+
pullRequests: {
964+
rerunChecks: () => Effect.succeed([{ name: "test", rerun: reran, detail: null }]),
965+
},
966+
});
967+
yield* harness.call("ci_rerun", {});
968+
return yield* Ref.get(harness.commands);
969+
});
970+
expect(yield* rerun(false, true)).toMatchObject([
971+
{ type: "thread.pull-request-watch.checks-reopen", threadId: THREAD_ID },
972+
]);
973+
// Nothing re-ran, or the watch has no answer to clear.
974+
expect(yield* rerun(false, false)).toEqual([]);
975+
expect(yield* rerun(undefined, true)).toEqual([]);
976+
}),
977+
);
978+
939979
it.effect("opens a PR from the thread's worktree and links it even if dismissed", () =>
940980
Effect.gen(function* () {
941981
const opened: Array<{ readonly cwd: string; readonly draft: boolean | undefined }> = [];

‎apps/server/src/mcp/toolkits/pullRequests/handlers.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,28 @@ const make = Effect.gen(function* () {
11201120
),
11211121
ci_rerun: McpToolAccess.writesWithCapability((input) =>
11221122
Effect.gen(function* () {
1123-
const { target, ref } = yield* locate(input);
1123+
const { thread, target, ref } = yield* locate(input);
11241124
const checks = yield* pullRequests
11251125
.rerunChecks({ ...ref, ...(input.check === undefined ? {} : { check: input.check }) })
11261126
.pipe(Effect.mapError(forgeFailure));
1127+
// Like a push, a rerun makes a watch's finished checks stale, so the thread keeps working
1128+
// until a read sees them run. The rerun already happened, so a failed reopen only logs.
1129+
if (
1130+
checks.some((check) => check.rerun) &&
1131+
threadPullRequestsOf(thread).some((link) => link.watch?.checksPending !== undefined)
1132+
) {
1133+
yield* engine
1134+
.dispatch({
1135+
type: "thread.pull-request-watch.checks-reopen",
1136+
commandId: yield* commandId("mcp-ci-rerun-checks", thread.id),
1137+
threadId: thread.id,
1138+
})
1139+
.pipe(
1140+
Effect.catchCause((cause) =>
1141+
Effect.logWarning("reopening a watch's checks after a rerun failed", cause),
1142+
),
1143+
);
1144+
}
11271145
return { ...identityOf(target), checks };
11281146
}),
11291147
),

0 commit comments

Comments
 (0)