diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index 2dad1fe68ee6d..f7b8483aee591 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -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>([]); - const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe( - Effect.provide( - service( - masterRepository, - yield* Ref.make>([]), - { - ...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>([]); + const threadId = ThreadId.make("thread:scheduled-base"); + const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe( + Effect.provide( + service( + masterRepository, + yield* Ref.make>([]), + { ...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", () => diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 7b8c99877d974..d4591a0d4175a 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -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 @@ -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)