fix(orchestrator): Prevent redundant delegated completion turns (#5311)

This commit is contained in:
Mike Olson authored and Julius Marminge committed 2026-08-15 16:51:18 +02:00
1 parent a6216cf3dc
commit 5133fdbed5
28 files changed
+4784 -255

No files matched your search

@@ -0,0 +1,69 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vite-plus/test";
const state = vi.hoisted(() => ({
projection: null as unknown,
workflow: null as unknown,
}));
vi.mock("@t3tools/client-runtime/environment", () => ({
scopeThreadRef: () => ({}) as never,
}));
vi.mock("@t3tools/client-runtime/state/thread-workflows", () => ({
deriveThreadQueueWorkflowState: () => state.workflow,
}));
vi.mock("../../state/entities", () => ({
useThreadProjection: () => state.projection,
}));
vi.mock("../../state/threads", () => ({
threadEnvironment: {
cancelQueuedRun: Symbol("cancelQueuedRun"),
editQueuedRun: Symbol("editQueuedRun"),
promoteQueuedRun: Symbol("promoteQueuedRun"),
reorderQueuedRun: Symbol("reorderQueuedRun"),
},
}));
vi.mock("../../state/use-atom-command", () => ({
useAtomCommand: () => async () => undefined,
}));
import { QueuedRunsControl } from "./QueuedRunsControl";
describe("QueuedRunsControl automatic completion delivery", () => {
it("does not render a queue control when only hidden delivery remains", () => {
state.projection = {
projection: {
messages: [
{
delegatedCompletion: {
parentRunId: "run:parent",
generation: 1,
taskIds: ["task:child"],
},
id: "message:completion",
},
],
},
};
state.workflow = {
activeRun: { id: "run:active" },
canPromoteToSteer: true,
canReorder: true,
queuedRuns: [],
};
const html = renderToStaticMarkup(
<QueuedRunsControl
environmentId={"environment:test" as never}
optimisticMessages={[]}
threadId={"thread:test" as never}
/>,
);
expect(html).toBe("");
});
});
@@ -211,7 +211,9 @@ export function QueuedRunsControl(props: {
className="size-6 text-muted-foreground"
disabled={item.runId === null || busyRunId !== null}
onClick={() => {
if (item.runId !== null) setEditing({ runId: item.runId, draft: item.text });
if (item.runId !== null) {
setEditing({ runId: item.runId, draft: item.text });
}
}}
>
<PencilIcon className="size-3" />
@@ -229,7 +231,9 @@ export function QueuedRunsControl(props: {
item.serverIndex === 0
}
onClick={() => {
if (item.runId === null || item.serverIndex === null) return;
if (item.runId === null || item.serverIndex === null) {
return;
}
void move(item.runId, queued[item.serverIndex - 1]?.run.id ?? null);
}}
>
@@ -248,7 +252,9 @@ export function QueuedRunsControl(props: {
item.serverIndex === queued.length - 1
}
onClick={() => {
if (item.runId === null || item.serverIndex === null) return;
if (item.runId === null || item.serverIndex === null) {
return;
}
void move(item.runId, queued[item.serverIndex + 2]?.run.id ?? null);
}}
>
@@ -267,7 +273,9 @@ export function QueuedRunsControl(props: {
: "Send as a steer instead"
}
onClick={() => {
if (item.runId !== null) void steer(item.runId);
if (item.runId !== null) {
void steer(item.runId);
}
}}
>
<CornerUpRightIcon className="size-3" />