The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
test(server): pin post-commit outbox settle boundary (#27560)
Narayan Joshi committed
Nov 6, 2026 at 01:49 UTC
09618245039b09ad3fe97c0ae593254a3af55978
1 file changed
+59
apps/server/src/orchestration-v2/FoundationPersistence.test.ts
+59
@@ -1862,6 +1862,65 @@ it.layer(layerTest)("orchestration V2 foundation persistence", (it) => {
1862
}),
1863
);
1864
1865
+ it.effect("does not resolve awaitSettled waiters until the cancel is signalled", () =>
1866
+ Effect.gen(function* () {
1867
+ const outbox = yield* EffectOutbox.EffectOutboxV2;
1868
+ const commandId = CommandId.make("command:foundation-settle-on-cancel");
1869
+ const threadId = ThreadId.make("thread:foundation-settle-on-cancel");
1870
+ const effectId = "effect:foundation-settle-on-cancel";
1871
+ yield* outbox.enqueue([
1872
+ {
1873
+ id: effectId,
1874
+ commandId,
1875
+ threadId,
1876
+ request: {
1877
+ type: "provider-turn.start",
1878
+ runId: RunId.make("run:foundation-settle-on-cancel"),
1879
+ },
1880
+ },
1881
+ ]);
1882
+
1883
+ const waiterRegistered = yield* Deferred.make<void>();
1884
+ const waiterFiber = yield* Deferred.succeed(waiterRegistered, undefined).pipe(
1885
+ Effect.andThen(outbox.awaitSettled(effectId)),
1886
+ Effect.forkChild,
1887
+ );
1888
+ yield* Deferred.await(waiterRegistered);
1889
+
1890
+ // Padding enqueues keep the waiter running so its row read lands before
1891
+ // the cancel: registration is synchronous and the read dispatches first.
1892
+ // A stronger milestone would need a test-only seam in the service, which
1893
+ // the codebase avoids.
1894
+ const paddingCommandId = CommandId.make("command:foundation-settle-on-cancel:padding");
1895
+ yield* Effect.forEach(
1896
+ Array.from({ length: 100 }, (_, index) => index),
1897
+ (index) =>
1898
+ outbox.enqueue([
1899
+ {
1900
+ id: `effect:foundation-settle-on-cancel:padding-${index}`,
1901
+ commandId: paddingCommandId,
1902
+ threadId: ThreadId.make("thread:foundation-settle-on-cancel:padding"),
1903
+ request: { type: "terminal.cleanup" as const },
1904
+ },
1905
+ ]),
1906
+ { discard: true },
1907
+ );
1908
+
1909
+ const cancelledEffectIds = yield* outbox.cancelUnsettled({
1910
+ threadId,
1911
+ effectTypes: ["provider-turn.start"],
1912
+ reason: "Test settle on cancel.",
1913
+ });
1914
+ assert.deepEqual(cancelledEffectIds, [effectId]);
1915
+ // The cancel runs inside the commit transaction; waiters resolve only via
1916
+ // the post-commit signalCancellations, never from the cancel itself.
1917
+ yield* Effect.yieldNow;
1918
+ assert.isUndefined(waiterFiber.pollUnsafe());
1919
+ yield* outbox.signalCancellations(cancelledEffectIds);
1920
+ yield* Fiber.join(waiterFiber);
1921
+ }).pipe(Effect.provide(Layer.fresh(layerEffectOutboxProvided))),
1922
+ );
1923
+
1924
it.effect("does not start an effect that was cancelled during claim registration", () =>
1925
Effect.gen(function* () {
1926
const effectId = "effect:foundation-cancelled-during-claim";