Skip to content

Commit a8777e4

Browse files
mkantautasmaria-rcksjuliusmarminge
authored
fix(server): held agent messages no longer block settling (#24891)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent d530d96 commit a8777e4

2 files changed

Lines changed: 38 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4272,7 +4272,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
42724272
.filter(
42734273
(message) =>
42744274
message.role === "user" &&
4275-
(message.notification !== undefined || message.delegatedCompletion !== undefined),
4275+
(message.createdBy !== "user" ||
4276+
message.scheduledTaskId !== undefined ||
4277+
message.notification !== undefined ||
4278+
message.delegatedCompletion !== undefined),
42764279
)
42774280
.map((message) => message.id),
42784281
);

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6400,7 +6400,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
64006400
}),
64016401
);
64026402

6403-
it.effect("settles past held automatic runs but not held user messages", () =>
6403+
it.effect("settles past held automatic messages but preserves a held user queue", () =>
64046404
Effect.gen(function* () {
64056405
const orchestrator = yield* Orchestrator.OrchestratorV2;
64066406
const eventSink = yield* EventSink.EventSinkV2;
@@ -6432,20 +6432,33 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
64326432
modelSelection,
64336433
dispatchMode: { type: "start_immediately" },
64346434
});
6435-
const queueMessage = (id: string, automatic: boolean) =>
6435+
const queueMessage = (id: string, sender: "notification" | "agent" | "scheduled" | "user") =>
64366436
orchestrator.dispatch({
64376437
type: "message.dispatch",
6438-
createdBy: automatic ? "agent" : "user",
6439-
creationSource: automatic ? "provider" : "web",
6440-
...(automatic
6441-
? {
6438+
...(
6439+
{
6440+
notification: {
6441+
createdBy: "agent",
6442+
creationSource: "provider",
64426443
notification: {
6443-
source: { kind: "background_task" as const },
6444-
outcome: "updated" as const,
6444+
source: { kind: "background_task" },
6445+
outcome: "updated",
64456446
summary: "Background activity updated",
64466447
},
6447-
}
6448-
: {}),
6448+
},
6449+
agent: {
6450+
createdBy: "agent",
6451+
creationSource: "mcp",
6452+
senderThreadId: ThreadId.make("settle-automatic-sender"),
6453+
},
6454+
scheduled: {
6455+
createdBy: "user",
6456+
creationSource: "web",
6457+
scheduledTaskId: ScheduledTaskId.make("settle-automatic-schedule"),
6458+
},
6459+
user: { createdBy: "user", creationSource: "web" },
6460+
} as const
6461+
)[sender],
64496462
commandId: CommandId.make(id),
64506463
threadId,
64516464
messageId: MessageId.make(id),
@@ -6454,7 +6467,9 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
64546467
modelSelection,
64556468
dispatchMode: { type: "queue_after_active" },
64566469
});
6457-
yield* queueMessage("settle-automatic-notification", true);
6470+
yield* queueMessage("settle-automatic-notification", "notification");
6471+
yield* queueMessage("settle-automatic-agent", "agent");
6472+
yield* queueMessage("settle-automatic-scheduled", "scheduled");
64586473

64596474
const holdQueueAfterRestart = (commandId: string) =>
64606475
Effect.gen(function* () {
@@ -6528,7 +6543,8 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
65286543
modelSelection,
65296544
dispatchMode: { type: "start_immediately" },
65306545
});
6531-
yield* queueMessage("settle-automatic-user-queued", false);
6546+
yield* queueMessage("settle-automatic-user-queued", "user");
6547+
yield* queueMessage("settle-automatic-agent-queued-2", "agent");
65326548
yield* holdQueueAfterRestart("settle-automatic-restart-2");
65336549
const error = yield* orchestrator
65346550
.dispatch({
@@ -6542,6 +6558,12 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
65426558
error.cause,
65436559
`Thread ${threadId} has a queued message. Send it or remove it from the queue before settling.`,
65446560
);
6561+
const blocked = yield* orchestrator.getThreadProjection(threadId);
6562+
assert.isNull(blocked.thread.settledAt);
6563+
assert.deepEqual(
6564+
blocked.runs.filter((run) => run.status === "queued").map((run) => run.userMessageId),
6565+
["settle-automatic-user-queued", "settle-automatic-agent-queued-2"],
6566+
);
65456567
}),
65466568
);
65476569

0 commit comments

Comments
 (0)