Skip to content

Commit ba49642

Browse files
authored
test(server): stopped-queue steering test no longer races queue promotion (pingdotgg#22529)
1 parent ad38be3 commit ba49642

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"),
@@ -1233,8 +1234,16 @@ it.effect("keeps a queued message queued when promoted into a run that Stop reac
12331234
it.effect("queues a plain send behind the stopped queue and releases its hold", () =>
12341235
Effect.scoped(
12351236
Effect.gen(function* () {
1236-
const { started, steered, layer, startFirstTurn } =
1237-
yield* nextTurnSelectionHarness("plain-send-after-stop");
1237+
const interruptReached = yield* Deferred.make<void>();
1238+
const releaseInterrupt = yield* Deferred.make<void>();
1239+
const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
1240+
"plain-send-after-stop",
1241+
false,
1242+
true,
1243+
Deferred.succeed(interruptReached, undefined).pipe(
1244+
Effect.andThen(Deferred.await(releaseInterrupt)),
1245+
),
1246+
);
12381247
yield* Effect.gen(function* () {
12391248
const orchestrator = yield* Orchestrator.OrchestratorV2;
12401249
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
@@ -1264,10 +1273,12 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",
12641273
});
12651274
// The provider has not stopped yet, so a plain send still resolves to a steer.
12661275
yield* send("sent", "auto");
1267-
yield* worker.drain();
1276+
// Once the stop settles, the run-update reactor promotes the queue on
1277+
// its own fiber, so read the queue while the provider is still stopping.
1278+
const draining = yield* worker.drain().pipe(Effect.forkScoped);
1279+
yield* Deferred.await(interruptReached);
12681280

12691281
const projection = yield* orchestrator.getThreadProjection(threadId);
1270-
assert.deepEqual(steered, []);
12711282
assert.equal(started.length, 1);
12721283
const queued = projection.runs
12731284
.filter((run) => run.status === "queued")
@@ -1280,6 +1291,9 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",
12801291
);
12811292
// The user sent it, so the queue they stopped runs again once the provider stops.
12821293
assert.isFalse(queued.some((run) => run.queueHeld === true));
1294+
yield* Deferred.succeed(releaseInterrupt, undefined);
1295+
yield* Fiber.join(draining);
1296+
assert.deepEqual(steered, []);
12831297
}).pipe(Effect.provide(layer));
12841298
}),
12851299
),

0 commit comments

Comments
 (0)