@@ -11,6 +11,7 @@ import * as Effect from "effect/Effect";
1111import * as Layer from "effect/Layer" ;
1212import * as Ref from "effect/Ref" ;
1313
14+ import { OrchestratorProjectionError } from "../orchestration-v2/Orchestrator.ts" ;
1415import { ThreadManagementService } from "../orchestration-v2/ThreadManagementService.ts" ;
1516import type { McpInvocationScope } from "./McpInvocationContext.ts" ;
1617import * as ConversationTransfer from "./ConversationTransferMcpService.ts" ;
@@ -50,11 +51,12 @@ function testLayer(input: {
5051 readonly parent : OrchestrationV2ThreadProjection ;
5152 readonly source : OrchestrationV2ThreadProjection ;
5253 readonly dispatch : ThreadManagementService [ "Service" ] [ "dispatch" ] ;
54+ readonly getThreadProjection ?: ThreadManagementService [ "Service" ] [ "getThreadProjection" ] ;
5355} ) {
5456 return ConversationTransfer . layer . pipe (
5557 Layer . provide (
5658 Layer . mock ( ThreadManagementService ) ( {
57- getThreadProjection : ( ) => Effect . succeed ( input . parent ) ,
59+ getThreadProjection : input . getThreadProjection ?? ( ( ) => Effect . succeed ( input . parent ) ) ,
5860 getProjectThread : ( { threadId } ) =>
5961 Effect . succeed ( threadId === parentThreadId ? input . parent : input . source ) ,
6062 dispatch : input . dispatch ,
@@ -171,4 +173,49 @@ describe("ConversationTransferMcpService", () => {
171173 assert . equal ( error . code , "capability_denied" ) ;
172174 } ) ,
173175 ) ;
176+
177+ it . effect (
178+ "does not treat an operational target projection failure as an absent fork target" ,
179+ ( ) =>
180+ Effect . gen ( function * ( ) {
181+ const dispatched = yield * Ref . make ( 0 ) ;
182+ const parent = projection ( {
183+ threadId : parentThreadId ,
184+ runtimeMode : "full-access" ,
185+ interactionMode : "default" ,
186+ } ) ;
187+ const error = yield * Effect . gen ( function * ( ) {
188+ const service = yield * ConversationTransfer . ConversationTransferMcpService ;
189+ return yield * service
190+ . fork ( scope ( ) , {
191+ sourcePoint : { type : "latest_stable" } ,
192+ clientRequestId : "projection-read-failure" ,
193+ } )
194+ . pipe ( Effect . flip ) ;
195+ } ) . pipe (
196+ Effect . provide (
197+ testLayer ( {
198+ parent,
199+ source : parent ,
200+ getThreadProjection : ( threadId ) =>
201+ threadId === parentThreadId
202+ ? Effect . succeed ( parent )
203+ : Effect . fail (
204+ new OrchestratorProjectionError ( {
205+ threadId,
206+ cause : new Error ( "storage unavailable" ) ,
207+ } ) ,
208+ ) ,
209+ dispatch : ( ) =>
210+ Ref . update ( dispatched , ( count ) => count + 1 ) . pipe (
211+ Effect . andThen ( Effect . die ( "dispatch must not run after a failed target read" ) ) ,
212+ ) ,
213+ } ) ,
214+ ) ,
215+ ) ;
216+
217+ assert . equal ( error . code , "orchestration_error" ) ;
218+ assert . equal ( yield * Ref . get ( dispatched ) , 0 ) ;
219+ } ) ,
220+ ) ;
174221} ) ;
0 commit comments