Skip to content

Commit a73a170

Browse files
committed
test(server): keep the run execution layer open until ingestion settles
1 parent 0a209e3 commit a73a170

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

‎apps/server/src/orchestration-v2/RunExecutionService.test.ts‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ it.effect("ingests new member threads of an owned child after the root turn term
16181618
} as ProviderAdapter.ProviderAdapterV2Event,
16191619
];
16201620

1621-
yield* Effect.gen(function* () {
1621+
const observed = yield* Effect.gen(function* () {
16221622
const runExecution = yield* RunExecutionService.RunExecutionServiceV2;
16231623
yield* runExecution.startRootRun({
16241624
commandId: CommandId.make("command:run-execution-late-child"),
@@ -1669,11 +1669,8 @@ it.effect("ingests new member threads of an owned child after the root turn term
16691669
},
16701670
},
16711671
});
1672+
return yield* Deferred.await(childMessageIngested).pipe(Effect.timeoutOption("2 seconds"));
16721673
}).pipe(Effect.provide(layerTest));
1673-
1674-
const observed = yield* Deferred.await(childMessageIngested).pipe(
1675-
Effect.timeoutOption("2 seconds"),
1676-
);
16771674
assert.isTrue(Option.isSome(observed), "child message was not ingested after root terminal");
16781675
assert.deepEqual(yield* Ref.get(order), ["root-finalized", "member-thread", "child-message"]);
16791676
// The run's message started the root; the parent agent started the child's turn.
@@ -1784,7 +1781,7 @@ it.effect("ends a nested native subagent and its thread when the root run is int
17841781
},
17851782
];
17861783

1787-
yield* Effect.gen(function* () {
1784+
const finalizedEvents = yield* Effect.gen(function* () {
17881785
const runExecution = yield* RunExecutionService.RunExecutionServiceV2;
17891786
yield* runExecution.startRootRun({
17901787
commandId: CommandId.make(`command:${key}`),
@@ -1819,9 +1816,10 @@ it.effect("ends a nested native subagent and its thread when the root run is int
18191816
sandboxPolicy: { type: "readOnly", access: { type: "fullAccess" }, networkAccess: false },
18201817
},
18211818
});
1819+
return yield* Deferred.await(finalized);
18221820
}).pipe(Effect.provide(layerTest));
18231821

1824-
const ended = (yield* Deferred.await(finalized)).flatMap((event) =>
1822+
const ended = finalizedEvents.flatMap((event) =>
18251823
event.type === "subagent.updated" || event.type === "node.updated"
18261824
? [[event.type, event.payload.id, event.payload.status]]
18271825
: [],
@@ -2265,7 +2263,7 @@ it.effect(
22652263
nodeId: unrelatedChildNode.id,
22662264
};
22672265

2268-
yield* Effect.gen(function* () {
2266+
const closed = yield* Effect.gen(function* () {
22692267
const runExecution = yield* RunExecutionService.RunExecutionServiceV2;
22702268
yield* runExecution.startRootRun({
22712269
commandId: CommandId.make("command:subagent-interrupt-cascade"),
@@ -2408,9 +2406,8 @@ it.effect(
24082406
},
24092407
},
24102408
});
2409+
return yield* Deferred.await(ingestionDone).pipe(Effect.timeoutOption("2 seconds"));
24112410
}).pipe(Effect.provide(layerTest));
2412-
2413-
const closed = yield* Deferred.await(ingestionDone).pipe(Effect.timeoutOption("2 seconds"));
24142411
assert.isTrue(Option.isSome(closed), "event ingestion fiber did not finish");
24152412

24162413
const events = yield* Ref.get(written);
@@ -3930,11 +3927,11 @@ function runBackgroundItemScenario(
39303927
},
39313928
},
39323929
});
3930+
// The run's ingestion lives in the service scope, so await it before the layer closes.
3931+
// No timeout: tests advance the TestClock, which would fire it early.
3932+
yield* Deferred.await(ingestionDone);
39333933
}).pipe(Effect.provide(layerTest));
39343934

3935-
// No timeout: tests advance the TestClock, which would fire it early.
3936-
yield* Deferred.await(ingestionDone);
3937-
39383935
return yield* Ref.get(observed);
39393936
});
39403937
}

0 commit comments

Comments
 (0)