Skip to content

Commit 65cafe5

Browse files
Zeus-Deusclaude
andcommitted
fix(server): keep linked threads out of the branch pull request lookup
Threads with only already-merged links went to the branch lookup, which reads the legacy linkedPullRequest reference first. When that reference was one of the excluded links, its merged summary still settled the thread. Linked threads skip the lookup again, as before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 7fff5d5 commit 65cafe5

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,64 @@ describe("ThreadSettlementServiceV2 worker", () => {
880880
),
881881
);
882882

883+
it.effect("does not look up a pull request that was already merged when linked", () =>
884+
Effect.scoped(
885+
Effect.gen(function* () {
886+
yield* TestClock.setTime(Date.parse(NOW));
887+
const reference = {
888+
projectId: PROJECT_ID,
889+
repository: "owner/repository",
890+
number: 42,
891+
url: "https://example.test/owner/repository/pull/42",
892+
};
893+
const fixture = yield* makeHarness({
894+
snapshot: makeSnapshot([
895+
makeThread("merged-then-linked", {
896+
linkedPullRequest: reference,
897+
pullRequests: [
898+
{
899+
host: "example.test",
900+
repository: reference.repository,
901+
number: reference.number,
902+
url: reference.url,
903+
source: "agent",
904+
linkedAt: "2026-08-28T00:00:00.000Z",
905+
snapshot: {
906+
state: "merged",
907+
title: "Pull request",
908+
headBranch: "feature",
909+
baseBranch: "main",
910+
isDraft: false,
911+
updatedAt: "2026-08-27T00:00:00.000Z",
912+
syncedAt: "2026-08-28T00:00:00.000Z",
913+
mergedAt: "2026-08-27T00:00:00.000Z",
914+
},
915+
stack: null,
916+
},
917+
],
918+
}),
919+
]),
920+
settings: {
921+
...DEFAULT_SERVER_SETTINGS,
922+
sidebarAutoSettleAfterDays: null,
923+
sidebarAutoSettleOnMerge: true,
924+
},
925+
pullRequestSummary: (input) =>
926+
Effect.succeed({
927+
...makePullRequestSummary({ ...input, state: "merged" }),
928+
mergedAt: "2026-08-27T00:00:00.000Z",
929+
}),
930+
});
931+
yield* Effect.gen(function* () {
932+
const reactor = yield* ThreadSettlementService.ThreadSettlementServiceV2;
933+
yield* startHarness(reactor, fixture.activation, fixture.snapshotReads);
934+
assert.deepStrictEqual(yield* Ref.get(fixture.commands), []);
935+
assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []);
936+
}).pipe(Effect.provide(fixture.layer));
937+
}),
938+
),
939+
);
940+
883941
it.effect("reevaluates immediately after a pull request merge", () =>
884942
Effect.scoped(
885943
Effect.gen(function* () {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export const make = Effect.gen(function* () {
398398
{ concurrency: 8 },
399399
))
400400
.filter((thread) => thread !== null)
401-
.filter((thread) => settlementPullRequestLinks(thread.pullRequests ?? []).length === 0);
401+
.filter((thread) => visibleThreadPullRequests(thread.pullRequests ?? []).length === 0);
402402
// Use the same cwd as the sidebar so both paths share GitManager's PR cache.
403403
const lookupCwdByThreadId = new Map<string, string>();
404404
yield* Effect.forEach(

0 commit comments

Comments
 (0)