fix(orchestrator): Prevent redundant delegated completion turns (#5311)
This commit is contained in:
1 parent
a6216cf3dc
commit
5133fdbed5
28 files changed
+4784
-255
No files matched your search
@@ -85,6 +85,47 @@ describe("thread workflows", () => {
|
||||
expect(state.canPromoteToSteer).toBe(true);
|
||||
});
|
||||
|
||||
it("hides automatic completion delivery from the visible queue", () => {
|
||||
const state = deriveThreadQueueWorkflowState({
|
||||
thread: { id: "thread", activeProviderThreadId: null },
|
||||
runs: [
|
||||
{
|
||||
id: "automatic",
|
||||
status: "queued",
|
||||
userMessageId: "message-automatic",
|
||||
ordinal: 2,
|
||||
queuePosition: 1,
|
||||
},
|
||||
{
|
||||
id: "visible",
|
||||
status: "queued",
|
||||
userMessageId: "message-visible",
|
||||
ordinal: 3,
|
||||
queuePosition: 2,
|
||||
},
|
||||
],
|
||||
messages: [
|
||||
{
|
||||
id: "message-automatic",
|
||||
text: "A delegated task reached a terminal state.",
|
||||
delegatedCompletion: {
|
||||
generation: 1,
|
||||
parentRunId: "run:parent",
|
||||
taskIds: ["task:child"],
|
||||
},
|
||||
},
|
||||
{ id: "message-visible", text: "Visible queued message" },
|
||||
],
|
||||
providerTurns: [],
|
||||
providerThreads: [],
|
||||
providerSessions: [],
|
||||
} as never);
|
||||
|
||||
expect(state.queuedRuns.map(({ run, text }) => [run.id, text])).toEqual([
|
||||
["visible", "Visible queued message"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("removes only the promoted head from the visible queue", () => {
|
||||
const state = deriveThreadQueueWorkflowState({
|
||||
thread: { id: "thread", activeProviderThreadId: "provider-thread" },
|
||||
|
||||
@@ -90,8 +90,15 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
|
||||
projection.providerTurns.some(
|
||||
(turn) => turn.runAttemptId === activeRun.activeAttemptId && turn.status === "running",
|
||||
);
|
||||
const automaticCompletionMessageIds = new Set(
|
||||
projection.messages
|
||||
.filter((message) => message.delegatedCompletion !== undefined)
|
||||
.map((message) => message.id),
|
||||
);
|
||||
const queuedRuns = copySorted(
|
||||
projection.runs.filter((run) => run.status === "queued"),
|
||||
projection.runs.filter(
|
||||
(run) => run.status === "queued" && !automaticCompletionMessageIds.has(run.userMessageId),
|
||||
),
|
||||
(left, right) =>
|
||||
(left.queuePosition ?? left.ordinal) - (right.queuePosition ?? right.ordinal) ||
|
||||
left.ordinal - right.ordinal,
|
||||
|
||||
Reference in new issue
Block a user