Skip to content
Merged
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
53 changes: 44 additions & 9 deletions apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3375,7 +3375,7 @@ describe("OrchestratorMcpService provider resolution", () => {
git: Partial<GitVcsDriver.GitVcsDriver["Service"]>,
saved: Ref.Ref<ReadonlyArray<ScheduledTask["workspaceStrategy"]>>,
task: ScheduledTask = existing,
modes?: Ref.Ref<ReadonlyArray<ScheduledTaskUpsertInput["threadMode"]>>,
inputs?: Ref.Ref<ReadonlyArray<ScheduledTaskUpsertInput>>,
) =>
OrchestratorMcpService.layer.pipe(
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
Expand Down Expand Up @@ -3407,9 +3407,9 @@ describe("OrchestratorMcpService provider resolution", () => {
upsert: (input) =>
Ref.update(saved, (strategies) => [...strategies, input.workspaceStrategy]).pipe(
Effect.andThen(
modes === undefined
inputs === undefined
? Effect.void
: Ref.update(modes, (all) => [...all, input.threadMode]),
: Ref.update(inputs, (all) => [...all, input]),
),
Effect.as({ task }),
),
Expand Down Expand Up @@ -3438,16 +3438,48 @@ describe("OrchestratorMcpService provider resolution", () => {
}),
);

it.effect.each([
{
name: "drops an emoji the limit splits",
prompt: `${"a".repeat(79)}😀 rest`,
title: "a".repeat(79),
},
{
name: "keeps an emoji that ends at the limit",
prompt: `${"a".repeat(78)}😀 rest`,
title: `${"a".repeat(78)}😀`,
},
])("a prompt-derived title $name", ({ prompt, title }) =>
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,
inputs,
),
),
);
yield* mcp.scheduleTask(client, { projectId, prompt, schedule });
assert.deepEqual(
(yield* Ref.get(inputs)).map((input) => input.title),
[title],
);
}),
);

it.effect("keeps one thread when fresh sessions are turned off before the first run", () =>
Effect.gen(function* () {
const modes = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput["threadMode"]>>([]);
const inputs = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
Effect.provide(
service(
masterRepository,
yield* Ref.make<ReadonlyArray<ScheduledTask["workspaceStrategy"]>>([]),
{ ...existing, threadMode: "fresh_session" },
modes,
inputs,
),
),
);
Expand All @@ -3459,15 +3491,18 @@ describe("OrchestratorMcpService provider resolution", () => {
scheduledTaskId: existing.id,
bindToCurrentThread: false,
});
assert.deepEqual(yield* Ref.get(modes), ["continue", "new_thread"]);
assert.deepEqual(
(yield* Ref.get(inputs)).map((input) => input.threadMode),
["continue", "new_thread"],
);
}),
);

it.effect(
"refuses unbinding into fresh sessions in one call, which would keep the thread",
() =>
Effect.gen(function* () {
const modes = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput["threadMode"]>>([]);
const inputs = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
Effect.provide(
service(
Expand All @@ -3478,7 +3513,7 @@ describe("OrchestratorMcpService provider resolution", () => {
threadId: ThreadId.make("thread:scheduled-base"),
threadMode: "continue",
},
modes,
inputs,
),
),
);
Expand All @@ -3490,7 +3525,7 @@ describe("OrchestratorMcpService provider resolution", () => {
})
.pipe(Effect.flip);
assert.include(refused.message, "first unbind it");
assert.deepEqual(yield* Ref.get(modes), []);
assert.deepEqual(yield* Ref.get(inputs), []);
}),
);

Expand Down
8 changes: 5 additions & 3 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2161,9 +2161,11 @@ const make = Effect.gen(function* () {
}
const modelSelection =
parent?.thread.modelSelection ?? (yield* projectDefaultModelSelection(project));
const derivedTitle = input.prompt.split("\n")[0]?.trim() ?? "";
const title =
input.title ?? (derivedTitle.length > 0 ? derivedTitle.slice(0, 80) : "Scheduled task");
// Never end on a lone high surrogate, which renders as a broken character.
const derivedTitle = (input.prompt.split("\n")[0]?.trim() ?? "")
.slice(0, 80)
.replace(/[\uD800-\uDBFF]$/, "");
const title = input.title ?? (derivedTitle.length > 0 ? derivedTitle : "Scheduled task");
const upsertInput: ScheduledTaskUpsertInput = {
title,
prompt: input.prompt,
Expand Down
Loading