Skip to content

Commit 1e1b6c0

Browse files
committed
test(server): stopped-queue steering test no longer races queue promotion
1 parent dd14848 commit 1e1b6c0

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
448448
name: string,
449449
canRestart = false,
450450
canSteer = true,
451+
interruptTurn: Effect.Effect<void> = Effect.void,
451452
) {
452453
const cwd = yield* checkpointWorkspace(name);
453454
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
@@ -538,7 +539,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
538539
interruptTurn: ({ providerTurnId }) =>
539540
Effect.sync(() => {
540541
interrupted.push(providerTurnId);
541-
}),
542+
}).pipe(Effect.andThen(interruptTurn)),
542543
respondToRuntimeRequest: () => Effect.void,
543544
readThreadSnapshot: () => Effect.die("unused"),
544545
rollbackThread: () => Effect.die("unused"),
@@ -1191,8 +1192,16 @@ it.effect("keeps a queued message queued when promoted into a run that Stop reac
11911192
it.effect("queues a plain send behind the stopped queue and releases its hold", () =>
11921193
Effect.scoped(
11931194
Effect.gen(function* () {
1194-
const { started, steered, layer, startFirstTurn } =
1195-
yield* nextTurnSelectionHarness("plain-send-after-stop");
1195+
const interruptReached = yield* Deferred.make<void>();
1196+
const releaseInterrupt = yield* Deferred.make<void>();
1197+
const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
1198+
"plain-send-after-stop",
1199+
false,
1200+
true,
1201+
Deferred.succeed(interruptReached, undefined).pipe(
1202+
Effect.andThen(Deferred.await(releaseInterrupt)),
1203+
),
1204+
);
11961205
yield* Effect.gen(function* () {
11971206
const orchestrator = yield* Orchestrator.OrchestratorV2;
11981207
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
@@ -1222,10 +1231,12 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",
12221231
});
12231232
// The provider has not stopped yet, so a plain send still resolves to a steer.
12241233
yield* send("sent", "auto");
1225-
yield* worker.drain();
1234+
// Once the stop settles, the run-update reactor promotes the queue on
1235+
// its own fiber, so read the queue while the provider is still stopping.
1236+
const draining = yield* worker.drain().pipe(Effect.forkScoped);
1237+
yield* Deferred.await(interruptReached);
12261238

12271239
const projection = yield* orchestrator.getThreadProjection(threadId);
1228-
assert.deepEqual(steered, []);
12291240
assert.equal(started.length, 1);
12301241
const queued = projection.runs
12311242
.filter((run) => run.status === "queued")
@@ -1238,6 +1249,9 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",
12381249
);
12391250
// The user sent it, so the queue they stopped runs again once the provider stops.
12401251
assert.isFalse(queued.some((run) => run.queueHeld === true));
1252+
yield* Deferred.succeed(releaseInterrupt, undefined);
1253+
yield* Fiber.join(draining);
1254+
assert.deepEqual(steered, []);
12411255
}).pipe(Effect.provide(layer));
12421256
}),
12431257
),

0 commit comments

Comments
 (0)