Skip to content

Commit 331ffff

Browse files
committed
test(orchestration): verify open-cohort sibling preservation on interrupted wake
1 parent 32e45fc commit 331ffff

2 files changed

Lines changed: 90 additions & 2 deletions

File tree

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

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ const seedParentWithTerminalTask = (input: {
158158
readonly runId: RunId;
159159
readonly rootNodeId: NodeId;
160160
readonly taskId: NodeId;
161-
readonly deliveryState: "delivered" | "claimed" | "acknowledged" | "disposed";
161+
readonly deliveryState: "delivered" | "claimed" | "acknowledged" | "disposed" | "pending";
162162
readonly completionWake?: "always" | "settled_only";
163163
readonly deliveryTaskIds?: ReadonlyArray<NodeId>;
164164
readonly parentRunStatus?: "running" | "completed";
165165
readonly siblingTasks?: ReadonlyArray<{
166166
readonly id: NodeId;
167-
readonly deliveryState: "delivered" | "claimed";
167+
readonly deliveryState: "delivered" | "claimed" | "pending";
168168
}>;
169169
readonly now: DateTime.Utc;
170170
}) =>
@@ -458,6 +458,93 @@ it.layer(layerTest)("delegated completion delivery repairs", (it) => {
458458
}),
459459
);
460460

461+
it.effect(
462+
"an interrupted wake with an open cohort preserves undelivered sibling tasks for successor delivery",
463+
() =>
464+
Effect.gen(function* () {
465+
const orchestrator = yield* Orchestrator.OrchestratorV2;
466+
const sink = yield* EventSink.EventSinkV2;
467+
const now = yield* DateTime.now;
468+
const threadId = ThreadId.make("open-cohort-wake-parent");
469+
const originRunId = RunId.make("open-cohort-wake-origin");
470+
const carriedTaskId = NodeId.make("open-cohort-wake-carried");
471+
const siblingTaskId = NodeId.make("open-cohort-wake-sibling");
472+
473+
yield* seedParentWithTerminalTask({
474+
threadId,
475+
projectId: ProjectId.make("open-cohort-wake-project"),
476+
runId: originRunId,
477+
rootNodeId: NodeId.make("open-cohort-wake-root"),
478+
taskId: carriedTaskId,
479+
deliveryState: "claimed",
480+
deliveryTaskIds: [carriedTaskId],
481+
completionWake: "always",
482+
siblingTasks: [
483+
{
484+
id: siblingTaskId,
485+
deliveryState: "pending",
486+
},
487+
],
488+
now,
489+
});
490+
491+
const origin = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
492+
yield* sink.write({
493+
events: [
494+
{
495+
...runEvent({ threadId, runId: originRunId, ordinal: 1, status: "completed", now }),
496+
payload: { ...origin, status: "completed", completedAt: now },
497+
},
498+
],
499+
});
500+
501+
const delivery = origin.delegatedCompletion!.delivery!;
502+
yield* orchestrator.dispatch({
503+
type: "message.dispatch",
504+
createdBy: "agent",
505+
creationSource: "server",
506+
commandId: CommandId.make("open-cohort-wake-start"),
507+
threadId,
508+
messageId: delivery.messageId,
509+
text: "Delegated task completed",
510+
attachments: [],
511+
modelSelection,
512+
dispatchMode: { type: "queue_after_active" },
513+
delegatedCompletion: {
514+
parentRunId: originRunId,
515+
generation: delivery.generation,
516+
taskIds: delivery.taskIds,
517+
},
518+
});
519+
yield* orchestrator.resumeQueuedRuns;
520+
521+
const wake = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
522+
(run) => run.userMessageId === delivery.messageId,
523+
)!;
524+
525+
yield* orchestrator.dispatch({
526+
type: "run.interrupt",
527+
commandId: CommandId.make("open-cohort-wake-interrupt"),
528+
threadId,
529+
runId: wake.id,
530+
});
531+
532+
const projection = yield* orchestrator.getThreadProjection(threadId);
533+
const interruptedWake = projection.runs.find((run) => run.id === wake.id)!;
534+
assert.equal(interruptedWake.status, "interrupted");
535+
536+
const parentRun = projection.runs.find((run) => run.id === originRunId)!;
537+
assert.equal(parentRun.delegatedCompletion?.disposition, "open");
538+
539+
const carried = projection.subagents.find((task) => task.id === carriedTaskId)!;
540+
assert.equal(carried.completionDelivery?.state, "disposed");
541+
542+
const sibling = projection.subagents.find((task) => task.id === siblingTaskId)!;
543+
assert.equal(sibling.completionDelivery?.state, "claimed");
544+
assert.deepEqual(parentRun.delegatedCompletion?.delivery?.taskIds, [siblingTaskId]);
545+
}),
546+
);
547+
461548
it.effect("acceptance batches pending siblings without acknowledging their results", () =>
462549
Effect.gen(function* () {
463550
const orchestrator = yield* Orchestrator.OrchestratorV2;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ export const layer: Layer.Layer<
13241324
// Serializes routing and ingestion with idle flushes, so a flushed snapshot can never land
13251325
// after a newer or final one, or after its child moved to another run.
13261326
const ingestLock = yield* Semaphore.make(1);
1327+
// Untraced: runs per provider event and per idle flush, so a span per call would add noise.
13271328
const ingestDelivered = Effect.fnUntraced(function* (
13281329
event: ProviderAdapter.ProviderAdapterV2Event,
13291330
deliveredEvent: ProviderAdapter.ProviderAdapterV2Event,

0 commit comments

Comments
 (0)