Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4299,35 +4299,30 @@ describe("OrchestratorMcpService provider resolution", () => {
}),
);

it.effect(
"refuses unbinding into fresh sessions in one call, which would keep the thread",
() =>
Effect.gen(function* () {
const inputs = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
Effect.provide(
service(
masterRepository,
yield* Ref.make<ReadonlyArray<ScheduledTask["workspaceStrategy"]>>([]),
{
...existing,
threadId: ThreadId.make("thread:scheduled-base"),
threadMode: "continue",
},
inputs,
),
it.effect("moves a bound task to fresh sessions in a first-run thread", () =>
Effect.gen(function* () {
const inputs = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
const threadId = ThreadId.make("thread:scheduled-base");
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
Effect.provide(
service(
masterRepository,
yield* Ref.make<ReadonlyArray<ScheduledTask["workspaceStrategy"]>>([]),
{ ...existing, threadId, threadMode: "continue" },
inputs,
),
);
const refused = yield* mcp
.updateScheduledTask(client, {
scheduledTaskId: existing.id,
bindToCurrentThread: false,
freshSession: true,
})
.pipe(Effect.flip);
assert.include(refused.message, "first unbind it");
assert.deepEqual(yield* Ref.get(inputs), []);
}),
),
);
yield* mcp.updateScheduledTask(client, {
scheduledTaskId: existing.id,
bindToCurrentThread: false,
freshSession: true,
});
const [input] = yield* Ref.get(inputs);
assert.equal(input?.threadId, null);
assert.equal(input?.unbindThread, true);
assert.equal(input?.threadMode, "fresh_session");
}),
);

it.effect("follows the default branch when a task is unbound from its thread", () =>
Expand Down
15 changes: 3 additions & 12 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2456,18 +2456,6 @@ const make = Effect.gen(function* () {
: "bindToCurrentThread binds to this thread, which belongs to a different project.",
);
}
// A save keeps a bound thread unless the task goes back to new threads, so this pair
// would leave runs in the old thread.
if (
input.bindToCurrentThread === false &&
input.freshSession === true &&
existing.threadId !== null
) {
return yield* failure(
"invalid_request",
"To move this task to a new thread with fresh sessions, first unbind it with bindToCurrentThread: false, then set freshSession: true in a second call.",
);
}
const threadId =
input.bindToCurrentThread === undefined
? existing.threadId
Expand All @@ -2487,6 +2475,9 @@ const make = Effect.gen(function* () {
schedule: input.schedule ?? existing.schedule,
projectId: existing.projectId,
threadId,
...(input.bindToCurrentThread === false && existing.threadId !== null
? { unbindThread: true }
: {}),
threadMode:
input.freshSession === undefined && input.bindToCurrentThread === undefined
? scheduledTaskThreadMode(existing)
Expand Down
Loading