TypeScript
test(server): pin post-commit outbox settle boundary (#27560)
Narayan Joshi09618245039b
diff --git a/apps/server/src/orchestration-v2/FoundationPersistence.test.ts b/apps/server/src/orchestration-v2/FoundationPersistence.test.tsindex 475e0a0e4ae..0b48f82fe1f 100644--- a/apps/server/src/orchestration-v2/FoundationPersistence.test.ts+++ b/apps/server/src/orchestration-v2/FoundationPersistence.test.ts@@ -1862,6 +1862,65 @@ it.layer(layerTest)("orchestration V2 foundation persistence", (it) => {}),);+ it.effect("does not resolve awaitSettled waiters until the cancel is signalled", () =>+ Effect.gen(function* () {+ const outbox = yield* EffectOutbox.EffectOutboxV2;+ const commandId = CommandId.make("command:foundation-settle-on-cancel");+ const threadId = ThreadId.make("thread:foundation-settle-on-cancel");+ const effectId = "effect:foundation-settle-on-cancel";+ yield* outbox.enqueue([+ {+ id: effectId,+ commandId,+ threadId,+ request: {+ type: "provider-turn.start",+ runId: RunId.make("run:foundation-settle-on-cancel"),+ },+ },+ ]);++ const waiterRegistered = yield* Deferred.make<void>();+ const waiterFiber = yield* Deferred.succeed(waiterRegistered, undefined).pipe(+ Effect.andThen(outbox.awaitSettled(effectId)),+ Effect.forkChild,+ );+ yield* Deferred.await(waiterRegistered);++ // Padding enqueues keep the waiter running so its row read lands before+ // the cancel: registration is synchronous and the read dispatches first.+ // A stronger milestone would need a test-only seam in the service, which+ // the codebase avoids.+ const paddingCommandId = CommandId.make("command:foundation-settle-on-cancel:padding");+ yield* Effect.forEach(+ Array.from({ length: 100 }, (_, index) => index),+ (index) =>+ outbox.enqueue([+ {+ id: `effect:foundation-settle-on-cancel:padding-${index}`,+ commandId: paddingCommandId,+ threadId: ThreadId.make("thread:foundation-settle-on-cancel:padding"),+ request: { type: "terminal.cleanup" as const },+ },+ ]),+ { discard: true },+ );++ const cancelledEffectIds = yield* outbox.cancelUnsettled({+ threadId,+ effectTypes: ["provider-turn.start"],+ reason: "Test settle on cancel.",+ });+ assert.deepEqual(cancelledEffectIds, [effectId]);+ // The cancel runs inside the commit transaction; waiters resolve only via+ // the post-commit signalCancellations, never from the cancel itself.+ yield* Effect.yieldNow;+ assert.isUndefined(waiterFiber.pollUnsafe());+ yield* outbox.signalCancellations(cancelledEffectIds);+ yield* Fiber.join(waiterFiber);+ }).pipe(Effect.provide(Layer.fresh(layerEffectOutboxProvided))),+ );+it.effect("does not start an effect that was cancelled during claim registration", () =>Effect.gen(function* () {const effectId = "effect:foundation-cancelled-during-claim";