Skip to content

Commit 60d7238

Browse files
fix(server): clear the derived branch PR when a thread's branch changes
A thread.metadata.update that moved a thread to a new branch kept the previous branch's auto-discovered PR, so the thread paired the new branch with the old PR until discovery succeeded again. Clear branchPullRequest in the same event when the branch actually changes; explicit PR links are untouched. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5ef8249 commit 60d7238

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4077,7 +4077,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
40774077
Date.parse(thread.limitRecovery.resetAt)
40784078
? { snoozedUntil: null, snoozedAt: null, lastSnoozeWakeAt: now }
40794079
: {}),
4080-
...(command.branch === undefined ? {} : { branch: command.branch }),
4080+
...(command.branch === undefined || command.branch === thread.branch
4081+
? {}
4082+
: { branch: command.branch, branchPullRequest: null }),
40814083
...(command.worktreePath === undefined ? {} : { worktreePath: command.worktreePath }),
40824084
...(command.linkedPullRequest === undefined
40834085
? {}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,18 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
29342934
.map((link) => link.url),
29352935
[21353, 21354].map((number) => `https://git.cafe/pingdotgg/t3code/pulls/${number}`),
29362936
);
2937+
const linked = (yield* orchestrator.getThreadShell(threadId))?.pullRequests;
2938+
for (const [index, branch] of ["feature/pr-links", "feature/next"].entries()) {
2939+
yield* orchestrator.dispatch({
2940+
type: "thread.metadata.update",
2941+
commandId: CommandId.make(`branch-pr-switch-${index}`),
2942+
threadId,
2943+
branch,
2944+
});
2945+
const thread = (yield* orchestrator.getThreadProjection(threadId)).thread;
2946+
assert.equal(thread.branchPullRequest?.number ?? null, index === 0 ? 1 : null);
2947+
assert.deepEqual(thread.pullRequests, linked);
2948+
}
29372949
}),
29382950
);
29392951

0 commit comments

Comments
 (0)