Skip to content

Commit a60f38e

Browse files
committed
fix(orchestration): Hide automatic completion queue entries
1 parent 677c2d7 commit a60f38e

16 files changed

Lines changed: 500 additions & 214 deletions

‎apps/mobile/src/features/threads/ThreadQueueControl.tsx‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { useAtomCommand } from "../../state/use-atom-command";
1212
import { useThreadProjection } from "../../state/use-thread-detail";
1313
import {
1414
buildCancelQueuedRunCommand,
15-
collectAutomaticCompletionMessageIds,
1615
resolveThreadQueueRowControls,
1716
} from "./threadQueueControlPresentation";
1817

@@ -25,10 +24,6 @@ export function ThreadQueueControl(props: {
2524
() => (scoped ? deriveThreadQueueWorkflowState(scoped.projection) : null),
2625
[scoped],
2726
);
28-
const automaticCompletionMessageIds = useMemo(
29-
() => collectAutomaticCompletionMessageIds(scoped?.projection.messages ?? []),
30-
[scoped],
31-
);
3227
const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun, "reorder queued message");
3328
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message");
3429
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "cancel queued message");
@@ -87,14 +82,12 @@ export function ThreadQueueControl(props: {
8782
<ScrollView style={{ maxHeight: 156 }} contentContainerStyle={{ paddingVertical: 4 }}>
8883
{workflow.queuedRuns.map(({ run, text }, index) => {
8984
const controls = resolveThreadQueueRowControls({
90-
automaticCompletionMessageIds,
9185
busy: busyRunId !== null,
9286
canPromoteToSteer: workflow.canPromoteToSteer,
9387
canReorder: workflow.canReorder,
9488
index,
9589
queuedCount: workflow.queuedRuns.length,
9690
text,
97-
userMessageId: run.userMessageId,
9891
});
9992

10093
return (

‎apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts‎

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,22 @@
11
import { describe, expect, it } from "vite-plus/test";
22

33
import {
4-
AUTOMATIC_COMPLETION_DELIVERY_LABEL,
5-
DISMISS_AUTOMATIC_COMPLETION_ACCESSIBILITY_LABEL,
64
REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
75
buildCancelQueuedRunCommand,
8-
collectAutomaticCompletionMessageIds,
96
resolveThreadQueueRowControls,
107
} from "./threadQueueControlPresentation";
118

12-
const automaticIds = collectAutomaticCompletionMessageIds([
13-
{
14-
delegatedCompletion: {
15-
generation: 1,
16-
parentRunId: "run:parent",
17-
taskIds: ["task:child"],
18-
},
19-
id: "message:completion",
20-
},
21-
{
22-
id: "message:ordinary",
23-
},
24-
]);
25-
269
describe("threadQueueControlPresentation", () => {
27-
it("detects automatic completion message ownership", () => {
28-
expect(automaticIds.has("message:completion")).toBe(true);
29-
expect(automaticIds.has("message:ordinary")).toBe(false);
30-
});
31-
32-
it("locks mutation controls for automatic completion rows while enabling dismissal", () => {
33-
const controls = resolveThreadQueueRowControls({
34-
automaticCompletionMessageIds: automaticIds,
35-
busy: false,
36-
canPromoteToSteer: true,
37-
canReorder: true,
38-
index: 1,
39-
queuedCount: 3,
40-
text: "A delegated task reached a terminal state.",
41-
userMessageId: "message:completion",
42-
});
43-
44-
expect(controls.automaticCompletion).toBe(true);
45-
expect(controls.displayText).toBe(AUTOMATIC_COMPLETION_DELIVERY_LABEL);
46-
expect(controls.canMoveUp).toBe(false);
47-
expect(controls.canMoveDown).toBe(false);
48-
expect(controls.canSteer).toBe(false);
49-
expect(controls.canDismiss).toBe(true);
50-
expect(controls.dismissAccessibilityLabel).toBe(
51-
DISMISS_AUTOMATIC_COMPLETION_ACCESSIBILITY_LABEL,
52-
);
53-
});
54-
55-
it("preserves ordinary queue reorder and steer controls with removal", () => {
10+
it("preserves queue reorder and steer controls with removal", () => {
5611
const controls = resolveThreadQueueRowControls({
57-
automaticCompletionMessageIds: automaticIds,
5812
busy: false,
5913
canPromoteToSteer: true,
6014
canReorder: true,
6115
index: 1,
6216
queuedCount: 3,
6317
text: "Please review the follow-up change.",
64-
userMessageId: "message:ordinary",
6518
});
6619

67-
expect(controls.automaticCompletion).toBe(false);
6820
expect(controls.displayText).toBe("Please review the follow-up change.");
6921
expect(controls.canMoveUp).toBe(true);
7022
expect(controls.canMoveDown).toBe(true);
@@ -74,46 +26,42 @@ describe("threadQueueControlPresentation", () => {
7426
});
7527

7628
it("disables edge reorder controls and busy dismissal", () => {
77-
const firstOrdinary = resolveThreadQueueRowControls({
78-
automaticCompletionMessageIds: automaticIds,
29+
const first = resolveThreadQueueRowControls({
7930
busy: false,
8031
canPromoteToSteer: false,
8132
canReorder: true,
8233
index: 0,
8334
queuedCount: 2,
8435
text: "First",
85-
userMessageId: "message:ordinary",
8636
});
87-
const busyAutomatic = resolveThreadQueueRowControls({
88-
automaticCompletionMessageIds: automaticIds,
37+
const busy = resolveThreadQueueRowControls({
8938
busy: true,
9039
canPromoteToSteer: true,
9140
canReorder: true,
9241
index: 0,
9342
queuedCount: 1,
94-
text: "A delegated task reached a terminal state.",
95-
userMessageId: "message:completion",
43+
text: "Queued message",
9644
});
9745

98-
expect(firstOrdinary.canMoveUp).toBe(false);
99-
expect(firstOrdinary.canMoveDown).toBe(true);
100-
expect(firstOrdinary.canSteer).toBe(false);
101-
expect(busyAutomatic.canDismiss).toBe(false);
102-
expect(busyAutomatic.canMoveUp).toBe(false);
103-
expect(busyAutomatic.canSteer).toBe(false);
46+
expect(first.canMoveUp).toBe(false);
47+
expect(first.canMoveDown).toBe(true);
48+
expect(first.canSteer).toBe(false);
49+
expect(busy.canDismiss).toBe(false);
50+
expect(busy.canMoveUp).toBe(false);
51+
expect(busy.canSteer).toBe(false);
10452
});
10553

106-
it("builds cancelQueuedRun command arguments for dismissal", () => {
54+
it("builds cancelQueuedRun command arguments for removal", () => {
10755
expect(
10856
buildCancelQueuedRunCommand({
10957
environmentId: "environment:test" as never,
110-
runId: "run:completion" as never,
58+
runId: "run:queued" as never,
11159
threadId: "thread:test" as never,
11260
}),
11361
).toEqual({
11462
environmentId: "environment:test",
11563
input: {
116-
runId: "run:completion",
64+
runId: "run:queued",
11765
threadId: "thread:test",
11866
},
11967
});

‎apps/mobile/src/features/threads/threadQueueControlPresentation.ts‎

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
import type { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
22

3-
export const AUTOMATIC_COMPLETION_DELIVERY_LABEL = "Automatic completion delivery";
4-
export const DISMISS_AUTOMATIC_COMPLETION_ACCESSIBILITY_LABEL =
5-
"Dismiss automatic completion delivery";
63
export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message";
74

8-
export function collectAutomaticCompletionMessageIds(
9-
messages: ReadonlyArray<{
10-
readonly id: string;
11-
readonly delegatedCompletion?: unknown;
12-
}>,
13-
): ReadonlySet<string> {
14-
return new Set(
15-
messages
16-
.filter((message) => message.delegatedCompletion !== undefined)
17-
.map((message) => message.id),
18-
);
19-
}
20-
215
export interface ThreadQueueRowControls {
22-
readonly automaticCompletion: boolean;
236
readonly canDismiss: boolean;
247
readonly canMoveDown: boolean;
258
readonly canMoveUp: boolean;
@@ -29,28 +12,22 @@ export interface ThreadQueueRowControls {
2912
}
3013

3114
export function resolveThreadQueueRowControls(input: {
32-
readonly automaticCompletionMessageIds: ReadonlySet<string>;
3315
readonly busy: boolean;
3416
readonly canPromoteToSteer: boolean;
3517
readonly canReorder: boolean;
3618
readonly index: number;
3719
readonly queuedCount: number;
3820
readonly text: string;
39-
readonly userMessageId: string;
4021
}): ThreadQueueRowControls {
41-
const automaticCompletion = input.automaticCompletionMessageIds.has(input.userMessageId);
42-
const mutationEnabled = !input.busy && !automaticCompletion;
22+
const mutationEnabled = !input.busy;
4323

4424
return {
45-
automaticCompletion,
4625
canDismiss: !input.busy,
4726
canMoveDown: mutationEnabled && input.canReorder && input.index < input.queuedCount - 1,
4827
canMoveUp: mutationEnabled && input.canReorder && input.index > 0,
4928
canSteer: mutationEnabled && input.canPromoteToSteer,
50-
dismissAccessibilityLabel: automaticCompletion
51-
? DISMISS_AUTOMATIC_COMPLETION_ACCESSIBILITY_LABEL
52-
: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
53-
displayText: automaticCompletion ? AUTOMATIC_COMPLETION_DELIVERY_LABEL : input.text,
29+
dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
30+
displayText: input.text,
5431
};
5532
}
5633

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,84 @@ import { ThreadManagementService } from "../orchestration-v2/ThreadManagementSer
1616
import { ProviderRegistry } from "../provider/Services/ProviderRegistry.ts";
1717
import { ScheduledTaskService } from "../scheduledTasks/ScheduledTaskService.ts";
1818
import type { McpInvocationScope } from "./McpInvocationContext.ts";
19-
import { layer, OrchestratorMcpService } from "./OrchestratorMcpService.ts";
19+
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
2020

2121
describe("OrchestratorMcpService", () => {
22+
it.effect("retries terminal acknowledgement with a fresh command id", () =>
23+
Effect.gen(function* () {
24+
const parentThreadId = ThreadId.make("thread:mcp-ack-parent");
25+
const childThreadId = ThreadId.make("thread:mcp-ack-child");
26+
const childRunId = RunId.make("run:mcp-ack-child");
27+
const taskId = NodeId.make("node:mcp-ack-task");
28+
const acknowledgementCommandIds = yield* Ref.make<ReadonlyArray<string>>([]);
29+
const acknowledgementAttempts = yield* Ref.make(0);
30+
const parentProjection = {
31+
thread: { id: parentThreadId },
32+
runs: [],
33+
contextTransfers: [],
34+
subagents: [
35+
{
36+
id: taskId,
37+
threadId: parentThreadId,
38+
origin: "app_owned",
39+
childThreadId,
40+
driver: "codex",
41+
model: "gpt-5.6-terra",
42+
result: "terminal result",
43+
completionDelivery: { state: "pending" },
44+
},
45+
],
46+
} as unknown as OrchestrationV2ThreadProjection;
47+
const childProjection = {
48+
thread: { id: childThreadId },
49+
runs: [{ id: childRunId, ordinal: 1, status: "completed" }],
50+
contextTransfers: [],
51+
} as unknown as OrchestrationV2ThreadProjection;
52+
const dependencies = Layer.mergeAll(
53+
NodeServices.layer,
54+
Layer.mock(ThreadManagementService)({
55+
getThreadProjection: (threadId) =>
56+
Effect.succeed(threadId === parentThreadId ? parentProjection : childProjection),
57+
dispatch: (command) =>
58+
Ref.update(acknowledgementCommandIds, (commandIds) => [
59+
...commandIds,
60+
String(command.commandId),
61+
]).pipe(
62+
Effect.andThen(Ref.updateAndGet(acknowledgementAttempts, (count) => count + 1)),
63+
Effect.flatMap((attempt) =>
64+
attempt === 1
65+
? Effect.fail(new Error("simulated acknowledgement failure") as never)
66+
: Effect.succeed({} as never),
67+
),
68+
),
69+
}),
70+
Layer.mock(ProviderRegistry)({ getProviders: Effect.succeed([]) }),
71+
Layer.mock(ScheduledTaskService)({}),
72+
);
73+
const scope: McpInvocationScope = {
74+
environmentId: EnvironmentId.make("environment:mcp-ack"),
75+
threadId: parentThreadId,
76+
providerSessionId: "provider-session:mcp-ack",
77+
providerInstanceId: ProviderInstanceId.make("codex"),
78+
capabilities: new Set(["orchestration"]),
79+
issuedAt: 1,
80+
};
81+
82+
yield* Effect.gen(function* () {
83+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
84+
const error = yield* service.taskStatus(scope, taskId).pipe(Effect.flip);
85+
assert.equal(error.code, "orchestration_error");
86+
87+
const result = yield* service.taskStatus(scope, taskId);
88+
assert.equal(result.status, "completed");
89+
assert.equal(result.summary, "terminal result");
90+
const commandIds = yield* Ref.get(acknowledgementCommandIds);
91+
assert.equal(commandIds.length, 2);
92+
assert.notEqual(commandIds[0], commandIds[1]);
93+
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(dependencies))));
94+
}),
95+
);
96+
2297
it.effect("does not dispose delivery when a nonterminal task has no active child run", () =>
2398
Effect.gen(function* () {
2499
const parentThreadId = ThreadId.make("thread:mcp-cancel-parent");
@@ -70,13 +145,13 @@ describe("OrchestratorMcpService", () => {
70145
};
71146

72147
yield* Effect.gen(function* () {
73-
const service = yield* OrchestratorMcpService;
148+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
74149
const error = yield* service
75150
.cancelTask(scope, { taskId, clientRequestId: "cancel-unstarted-task" })
76151
.pipe(Effect.flip);
77152
assert.equal(error.code, "task_not_cancellable");
78153
assert.deepEqual(yield* Ref.get(dispatched), []);
79-
}).pipe(Effect.provide(layer.pipe(Layer.provide(dependencies))));
154+
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(dependencies))));
80155
}),
81156
);
82157

@@ -132,7 +207,7 @@ describe("OrchestratorMcpService", () => {
132207
};
133208

134209
yield* Effect.gen(function* () {
135-
const service = yield* OrchestratorMcpService;
210+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
136211
const error = yield* service
137212
.cancelTask(scope, { taskId, clientRequestId: "cancel-failed-task" })
138213
.pipe(Effect.flip);
@@ -141,7 +216,7 @@ describe("OrchestratorMcpService", () => {
141216
(yield* Ref.get(dispatched)).map((command) => (command as { type: string }).type),
142217
["run.interrupt"],
143218
);
144-
}).pipe(Effect.provide(layer.pipe(Layer.provide(dependencies))));
219+
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(dependencies))));
145220
}),
146221
);
147222

@@ -201,7 +276,7 @@ describe("OrchestratorMcpService", () => {
201276
};
202277

203278
yield* Effect.gen(function* () {
204-
const service = yield* OrchestratorMcpService;
279+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
205280
const result = yield* service.cancelTask(scope, {
206281
taskId,
207282
clientRequestId: "cancel-dispose-failed-task",
@@ -211,7 +286,7 @@ describe("OrchestratorMcpService", () => {
211286
(yield* Ref.get(dispatched)).map((command) => (command as { type: string }).type),
212287
["run.interrupt", "delegated_task.completion-delivery.dispose"],
213288
);
214-
}).pipe(Effect.provide(layer.pipe(Layer.provide(dependencies))));
289+
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(dependencies))));
215290
}),
216291
);
217292
});

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,12 +889,13 @@ const make = Effect.gen(function* () {
889889
task.completionDelivery?.state !== "disposed"
890890
) {
891891
const observingRun = latestActiveRun(parentProjection);
892+
const acknowledgementRequestKey = yield* requestKey(undefined);
892893
yield* threadManagement
893894
.dispatch({
894895
type: "delegated_task.completion-delivery.acknowledge",
895896
commandId: stableCommandId({
896897
scope,
897-
requestKey: String(taskId),
898+
requestKey: acknowledgementRequestKey,
898899
operation: acknowledgementOperation,
899900
}),
900901
parentThreadId: scope.threadId,

0 commit comments

Comments
 (0)