TypeScript
test(server): stopped-queue steering test no longer races queue promotion (#22529)
Tristan Knightba49642a3bf1
diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.tsindex c09b7401df7..32971198522 100644--- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts+++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts@@ -448,6 +448,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*name: string,canRestart = false,canSteer = true,+ interruptTurn: Effect.Effect<void> = Effect.void,) {const cwd = yield* checkpointWorkspace(name);const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();@@ -538,7 +539,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*interruptTurn: ({ providerTurnId }) =>Effect.sync(() => {interrupted.push(providerTurnId);- }),+ }).pipe(Effect.andThen(interruptTurn)),respondToRuntimeRequest: () => Effect.void,readThreadSnapshot: () => Effect.die("unused"),rollbackThread: () => Effect.die("unused"),@@ -1233,8 +1234,16 @@ it.effect("keeps a queued message queued when promoted into a run that Stop reacit.effect("queues a plain send behind the stopped queue and releases its hold", () =>Effect.scoped(Effect.gen(function* () {- const { started, steered, layer, startFirstTurn } =- yield* nextTurnSelectionHarness("plain-send-after-stop");+ const interruptReached = yield* Deferred.make<void>();+ const releaseInterrupt = yield* Deferred.make<void>();+ const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(+ "plain-send-after-stop",+ false,+ true,+ Deferred.succeed(interruptReached, undefined).pipe(+ Effect.andThen(Deferred.await(releaseInterrupt)),+ ),+ );yield* Effect.gen(function* () {const orchestrator = yield* Orchestrator.OrchestratorV2;const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;@@ -1264,10 +1273,12 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",});// The provider has not stopped yet, so a plain send still resolves to a steer.yield* send("sent", "auto");- yield* worker.drain();+ // Once the stop settles, the run-update reactor promotes the queue on+ // its own fiber, so read the queue while the provider is still stopping.+ const draining = yield* worker.drain().pipe(Effect.forkScoped);+ yield* Deferred.await(interruptReached);const projection = yield* orchestrator.getThreadProjection(threadId);- assert.deepEqual(steered, []);assert.equal(started.length, 1);const queued = projection.runs.filter((run) => run.status === "queued")@@ -1280,6 +1291,9 @@ it.effect("queues a plain send behind the stopped queue and releases its hold",);// The user sent it, so the queue they stopped runs again once the provider stops.assert.isFalse(queued.some((run) => run.queueHeld === true));+ yield* Deferred.succeed(releaseInterrupt, undefined);+ yield* Fiber.join(draining);+ assert.deepEqual(steered, []);}).pipe(Effect.provide(layer));}),),