Skip to content

Commit 1571e72

Browse files
t3dotggclaude
andcommitted
fix(server): a queued /goal sent during compaction also skips it
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1eea3c7 commit 1571e72

2 files changed

Lines changed: 89 additions & 104 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8363,11 +8363,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
83638363
);
83648364
// A compacting turn cannot take steering input, so steering skips the compaction instead.
83658365
if (
8366-
goalCommand === null &&
83678366
target !== undefined &&
83688367
targetMessage !== undefined &&
83698368
isCompactionCommandMessage(targetMessage)
83708369
) {
8370+
if (goalCommand !== null) {
8371+
yield* ensureGoalCommandSupported(command, queuedMessage, queuedRun.providerInstanceId);
8372+
}
83718373
yield* emitEvent({
83728374
type: "run.updated",
83738375
threadId: command.threadId,

‎apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts‎

Lines changed: 86 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,111 +1169,94 @@ it.effect("promotes a queued goal by stopping the running turn", () =>
11691169
),
11701170
);
11711171

1172-
it.effect("promoting a queued message into a compaction stops it and sends that message next", () =>
1173-
Effect.scoped(
1174-
Effect.gen(function* () {
1175-
const { events, layer, send, read, started, steered, startFirstTurn } =
1176-
yield* goalHarness("compaction-promote");
1177-
yield* Effect.gen(function* () {
1178-
const orchestrator = yield* Orchestrator.OrchestratorV2;
1179-
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
1180-
const threadId = yield* startFirstTurn;
1181-
yield* send("compact", "/compact", "queue");
1182-
yield* send("queued", "queued", "queue");
1183-
yield* send("next", "next", "queue");
1184-
const settled = yield* orchestrator.streamDomainEvents.pipe(
1185-
Stream.filter(
1186-
(event) =>
1187-
event.type === "run.updated" &&
1188-
event.payload.id === started[0]!.runId &&
1189-
event.payload.status === "waiting",
1190-
),
1191-
Stream.take(1),
1192-
Stream.runDrain,
1193-
Effect.forkScoped,
1194-
);
1195-
const compacting = yield* orchestrator.streamDomainEvents.pipe(
1196-
Stream.filter(
1197-
(event) =>
1198-
event.type === "provider-turn.updated" &&
1199-
event.payload.status === "running" &&
1200-
event.payload.runAttemptId !== started[0]!.attemptId,
1201-
),
1202-
Stream.take(1),
1203-
Stream.runDrain,
1204-
Effect.forkScoped,
1172+
it.effect.each(["next", "/goal ship it"])(
1173+
"promoting %s into a compaction stops it and sends it next",
1174+
(promoted) =>
1175+
Effect.scoped(
1176+
Effect.gen(function* () {
1177+
const { events, layer, send, read, started, steered, startFirstTurn } = yield* goalHarness(
1178+
`compaction-promote-${promoted.length}`,
12051179
);
1206-
const turn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!;
1207-
yield* Queue.offer(events, {
1208-
type: "provider_turn.updated",
1209-
driver,
1210-
providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now },
1211-
});
1212-
yield* Queue.offer(events, {
1213-
type: "turn.terminal",
1214-
driver,
1215-
providerThreadId: turn.providerThreadId,
1216-
providerTurnId: turn.id,
1217-
runOrdinal: started[0]!.runOrdinal,
1218-
status: "completed",
1219-
failure: null,
1220-
threadDisposition: "reusable",
1221-
});
1222-
yield* Fiber.join(settled);
1223-
yield* worker.drain();
1224-
yield* orchestrator.resumeQueuedRuns;
1225-
yield* worker.drain();
1226-
yield* Fiber.join(compacting);
1227-
const compactRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1228-
(run) => run.userMessageId === MessageId.make("message:compact"),
1229-
)!;
1230-
const nextRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1231-
(run) => run.userMessageId === MessageId.make("message:next"),
1232-
)!;
1233-
yield* orchestrator.dispatch({
1234-
type: "queued-message.promote-to-steer",
1235-
commandId: CommandId.make("promote"),
1236-
threadId,
1237-
queuedRunId: nextRun.id,
1238-
targetRunId: compactRun.id,
1239-
});
1240-
yield* worker.drain();
1241-
// The provider confirms the stop, which frees the queue.
1242-
const compactTurn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns.find(
1243-
(candidate) => candidate.runAttemptId === started[1]!.attemptId,
1244-
)!;
1245-
yield* Queue.offer(events, {
1246-
type: "provider_turn.updated",
1247-
driver,
1248-
providerTurn: { ...compactTurn, status: "interrupted", completedAt: yield* DateTime.now },
1249-
});
1250-
yield* Queue.offer(events, {
1251-
type: "turn.terminal",
1252-
driver,
1253-
providerThreadId: compactTurn.providerThreadId,
1254-
providerTurnId: compactTurn.id,
1255-
runOrdinal: compactRun.ordinal,
1256-
status: "interrupted",
1257-
failure: null,
1258-
threadDisposition: "reusable",
1259-
});
1260-
yield* worker.drain();
1180+
yield* Effect.gen(function* () {
1181+
const orchestrator = yield* Orchestrator.OrchestratorV2;
1182+
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
1183+
const threadId = yield* startFirstTurn;
1184+
yield* send("compact", "/compact", "queue");
1185+
yield* send("queued", "queued", "queue");
1186+
yield* send("next", promoted, "queue");
1187+
const settled = yield* orchestrator.streamDomainEvents.pipe(
1188+
Stream.filter(
1189+
(event) =>
1190+
event.type === "run.updated" &&
1191+
event.payload.id === started[0]!.runId &&
1192+
event.payload.status === "waiting",
1193+
),
1194+
Stream.take(1),
1195+
Stream.runDrain,
1196+
Effect.forkScoped,
1197+
);
1198+
const compacting = yield* orchestrator.streamDomainEvents.pipe(
1199+
Stream.filter(
1200+
(event) =>
1201+
event.type === "provider-turn.updated" &&
1202+
event.payload.status === "running" &&
1203+
event.payload.runAttemptId !== started[0]!.attemptId,
1204+
),
1205+
Stream.take(1),
1206+
Stream.runDrain,
1207+
Effect.forkScoped,
1208+
);
1209+
const turn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!;
1210+
yield* Queue.offer(events, {
1211+
type: "provider_turn.updated",
1212+
driver,
1213+
providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now },
1214+
});
1215+
yield* Queue.offer(events, {
1216+
type: "turn.terminal",
1217+
driver,
1218+
providerThreadId: turn.providerThreadId,
1219+
providerTurnId: turn.id,
1220+
runOrdinal: started[0]!.runOrdinal,
1221+
status: "completed",
1222+
failure: null,
1223+
threadDisposition: "reusable",
1224+
});
1225+
yield* Fiber.join(settled);
1226+
yield* worker.drain();
1227+
yield* orchestrator.resumeQueuedRuns;
1228+
yield* worker.drain();
1229+
yield* Fiber.join(compacting);
1230+
const compactRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1231+
(run) => run.userMessageId === MessageId.make("message:compact"),
1232+
)!;
1233+
const nextRun = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
1234+
(run) => run.userMessageId === MessageId.make("message:next"),
1235+
)!;
1236+
yield* orchestrator.dispatch({
1237+
type: "queued-message.promote-to-steer",
1238+
commandId: CommandId.make("promote"),
1239+
threadId,
1240+
queuedRunId: nextRun.id,
1241+
targetRunId: compactRun.id,
1242+
});
1243+
yield* worker.drain();
12611244

1262-
const projection = yield* orchestrator.getThreadProjection(threadId);
1263-
assert.deepEqual(steered, []);
1264-
assert.isTrue(
1265-
projection.turnItems.some(
1266-
(item) => item.type === "run_interrupt_request" && item.runId === compactRun.id,
1267-
),
1268-
);
1269-
assert.deepEqual((yield* read(threadId)).queue, ["queued"]);
1270-
assert.deepEqual(
1271-
started.map((turn) => turn.message.text),
1272-
["first", "/compact", "next"],
1273-
);
1274-
}).pipe(Effect.provide(layer));
1275-
}),
1276-
),
1245+
const projection = yield* orchestrator.getThreadProjection(threadId);
1246+
assert.deepEqual(steered, []);
1247+
assert.isTrue(
1248+
projection.turnItems.some(
1249+
(item) => item.type === "run_interrupt_request" && item.runId === compactRun.id,
1250+
),
1251+
);
1252+
assert.deepEqual((yield* read(threadId)).queue, ["queued"]);
1253+
assert.deepEqual(
1254+
started.map((turn) => turn.message.text),
1255+
["first", "/compact", promoted],
1256+
);
1257+
}).pipe(Effect.provide(layer));
1258+
}),
1259+
),
12771260
);
12781261

12791262
it.effect("stops a turn that is still starting when a goal is sent into it", () =>

0 commit comments

Comments
 (0)