@devries-cameron20 / t3code-1 / commits / d29c56a5c4
Fork 0

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

fix(server): resolve project identity before legacy pr relinks (#11045)

t3-code[bot] committed Sep 10, 2026 at 02:54 UTC d29c56a5c404cb0f58d3b2ac41762fa0d0ac28d4
2 files changed +30 -1
apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts
+7 -1
@@ -27,7 +27,7 @@ import * as Option from "effect/Option";
27 import * as Queue from "effect/Queue";
28 import * as Stream from "effect/Stream";
29 import { TestClock } from "effect/testing";
30 -import { describe, expect, it } from "vite-plus/test";
30 +import { describe, expect, it, vi } from "vite-plus/test";
31
32 import { PersistenceSqlError } from "../../persistence/Errors.ts";
33 import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
@@ -1039,6 +1039,8 @@ describe("OrchestrationEngine", () => {
1039 },
1040 }),
1041 });
1042 + // Same-tick links must replace the old PR, not rely on timestamp ordering.
1043 + const clock = vi.spyOn(Date, "now").mockReturnValue(Date.parse(now()));
1044 try {
1045 const projectId = ProjectId.make("pr-race-project");
1046 const threadId = ThreadId.make("pr-race-thread");
@@ -1141,6 +1143,9 @@ describe("OrchestrationEngine", () => {
1143 if (change === "delete") return;
1144 const current = (await system.readModel()).threads[0];
1145 expect(current?.branchPullRequest ?? null).toBeNull();
1146 + expect(current?.pullRequests.map((link) => link.number)).toEqual(
1147 + change === "unlink" ? [] : change === "relink" ? [3] : [1],
1148 + );
1149 expect(current?.linkedPullRequest ?? null).toEqual(
1150 change === "unlink"
1151 ? null
@@ -1149,6 +1154,7 @@ describe("OrchestrationEngine", () => {
1154 : previous,
1155 );
1156 } finally {
1157 + clock.mockRestore();
1158 await system.dispose();
1159 }
1160 },
apps/server/src/orchestration/Layers/OrchestrationEngine.ts
+23
@@ -212,6 +212,29 @@ const makeOrchestrationEngine = Effect.gen(function* () {
212 });
213 }
214
215 + // New and moved projects do not carry a resolved identity in the event-derived
216 + // command model. Legacy PR edits need it to identify the link they replace.
217 + if (
218 + envelope.command.type === "thread.meta.update" &&
219 + envelope.command.linkedPullRequest !== undefined
220 + ) {
221 + const threadId = envelope.command.threadId;
222 + const thread = commandReadModel.threads.find((thread) => thread.id === threadId);
223 + if (thread !== undefined) {
224 + const project = yield* projectionSnapshotQuery.getProjectShellById(thread.projectId);
225 + if (Option.isSome(project)) {
226 + commandReadModel = {
227 + ...commandReadModel,
228 + projects: commandReadModel.projects.map((entry) =>
229 + entry.id === thread.projectId
230 + ? { ...entry, repositoryIdentity: project.value.repositoryIdentity }
231 + : entry,
232 + ),
233 + };
234 + }
235 + }
236 + }
237 +
238 // Command snapshots omit activities at startup and cap them while running.
239 // Read this request's durable state before deciding how to send the answer.
240 const userInputActivity =