Skip to content

Commit 594693b

Browse files
some-du6eclaude
andcommitted
fix(server): project moves refuse parents and background work, and drop PR watches
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 623d670 commit 594693b

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,13 +2966,35 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
29662966
});
29672967
}
29682968
const records = yield* projectionStore
2969-
.getThreadRecords(command.threadId, ["runs", "runtimeRequests"])
2969+
.getThreadRecords(
2970+
command.threadId,
2971+
["runs", "runtimeRequests", "subagents", "providerThreads", "turnItems"],
2972+
{
2973+
turnItemTypes: ["command_execution", "dynamic_tool", "subagent"],
2974+
turnItemStatuses: ["pending", "running", "waiting"],
2975+
},
2976+
)
29702977
.pipe(mapDispatchError(command));
2978+
// Children inherit the parent's project and workspace; moving only the parent would strand them.
2979+
if (records.subagents.some((task) => task.childThreadId !== null)) {
2980+
return yield* new OrchestratorDispatchError({
2981+
commandId: command.commandId,
2982+
commandType: command.type,
2983+
cause: `Thread ${command.threadId} has child threads and cannot move to another project.`,
2984+
});
2985+
}
29712986
if (
29722987
records.runs.some((run) =>
29732988
["preparing", "queued", "starting", "running", "waiting"].includes(run.status),
29742989
) ||
2975-
records.runtimeRequests.some((request) => request.status === "pending")
2990+
records.runtimeRequests.some((request) => request.status === "pending") ||
2991+
derivePendingBackgroundWork({
2992+
latestRun: records.runs.findLast((run) => run.status !== "queued"),
2993+
providerThreads: records.providerThreads,
2994+
turnItems: records.turnItems,
2995+
activeProviderThreadId: thread.activeProviderThreadId,
2996+
runs: records.runs,
2997+
}).length > 0
29762998
) {
29772999
return yield* new OrchestratorDispatchError({
29783000
commandId: command.commandId,
@@ -3409,7 +3431,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
34093431
snooze: command.limitRecovery.snooze ?? previousRecovery?.snooze ?? false,
34103432
requestId: command.commandId,
34113433
};
3412-
return {
3434+
const updated: OrchestrationV2AppThread = {
34133435
...thread,
34143436
...(command.title === undefined ? {} : { title: command.title }),
34153437
...(command.limitRecovery === undefined ? {} : { limitRecovery }),
@@ -3471,6 +3493,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
34713493
: {}),
34723494
updatedAt: now,
34733495
};
3496+
// Watches read through the project's checkout, which no longer holds these links.
3497+
return movesProject
3498+
? {
3499+
...updated,
3500+
pullRequests: updated.pullRequests?.map((link) =>
3501+
withPullRequestWatch(link, undefined),
3502+
),
3503+
}
3504+
: updated;
34743505
}
34753506
case "thread.pull-request.link":
34763507
case "thread.pull-request.unlink":

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,20 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
19051905
worktreePath: "/workspace/move-from-worktree",
19061906
});
19071907

1908+
yield* orchestrator.dispatch({
1909+
type: "thread.pull-request.watch",
1910+
commandId: CommandId.make("runtime-layer-move-watch"),
1911+
threadId,
1912+
host: "github.com",
1913+
repository: "pingdotgg/t3code",
1914+
number: 1,
1915+
watching: true,
1916+
link: { url: "https://github.com/pingdotgg/t3code/pull/1", source: "manual" },
1917+
});
1918+
assert.isDefined(
1919+
(yield* orchestrator.getThreadProjection(threadId)).thread.pullRequests?.[0]?.watch,
1920+
);
1921+
19081922
const missingProject = yield* orchestrator
19091923
.dispatch({
19101924
type: "thread.metadata.update",
@@ -1925,6 +1939,8 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
19251939
assert.equal(moved.projectId, toProjectId);
19261940
assert.isNull(moved.branch);
19271941
assert.isNull(moved.worktreePath);
1942+
assert.lengthOf(moved.pullRequests ?? [], 1);
1943+
assert.isUndefined(moved.pullRequests?.[0]?.watch);
19281944
const shell = yield* orchestrator.getShellSnapshot();
19291945
assert.equal(
19301946
shell.threads.find((candidate) => candidate.id === threadId)?.projectId,

0 commit comments

Comments
 (0)