@@ -25,6 +25,7 @@ import * as SecretRequests from "../secrets/SecretRequests.ts";
2525import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts" ;
2626import * as GitVcsDriver from "../vcs/GitVcsDriver.ts" ;
2727import * as RemoteDelegation from "../peer/RemoteDelegation.ts" ;
28+ import * as Orchestrator from "../orchestration-v2/Orchestrator.ts" ;
2829import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts" ;
2930import type * as McpInvocationContext from "./McpInvocationContext.ts" ;
3031import * as OrchestratorMcpService from "./OrchestratorMcpService.ts" ;
@@ -116,7 +117,8 @@ function makeRun(input: {
116117 } ;
117118}
118119
119- it ( "readThread prefers activity-run status over a newer cancelled queued run" , async ( ) => {
120+ it ( "readThread preserves caller access errors and prefers activity-run status over a newer cancelled queued run" , async ( ) => {
121+ let callerUnavailable = false ;
120122 const projection = {
121123 thread : baseThread ( {
122124 threadId : parentThreadId ,
@@ -142,15 +144,24 @@ it("readThread prefers activity-run status over a newer cancelled queued run", a
142144 Layer . mock ( ThreadManagementService . ThreadManagementService ) ( {
143145 getTimelinePage : ( ) => Effect . succeed ( { items : [ ] , totalItems : 0 , hasMore : false } ) ,
144146 getThreadRecords : ( threadId ) =>
145- threadId === parentThreadId
146- ? Effect . succeed ( projection )
147- : Effect . die ( `unexpected thread ${ threadId } ` ) ,
147+ callerUnavailable
148+ ? Effect . fail (
149+ new Orchestrator . OrchestratorProjectionError ( {
150+ threadId,
151+ cause : "Caller unavailable" ,
152+ } ) ,
153+ )
154+ : threadId === parentThreadId
155+ ? Effect . succeed ( projection )
156+ : Effect . die ( `unexpected thread ${ threadId } ` ) ,
148157 getThreadShell : ( threadId ) =>
149- Effect . succeed (
150- threadId === parentThreadId
151- ? ( projection . thread as unknown as OrchestrationV2ThreadShell )
152- : null ,
153- ) ,
158+ callerUnavailable
159+ ? Effect . die ( "A failed caller read must not reach the target" )
160+ : Effect . succeed (
161+ threadId === parentThreadId
162+ ? ( projection . thread as unknown as OrchestrationV2ThreadShell )
163+ : null ,
164+ ) ,
154165 getProjectThreadRecords : ( input ) =>
155166 input . threadId === parentThreadId
156167 ? Effect . succeed ( projection )
@@ -180,6 +191,17 @@ it("readThread prefers activity-run status over a newer cancelled queued run", a
180191 expect ( result . thread . status ) . toBe ( "running" ) ;
181192 expect ( result . thread . latestRunId ) . toBe ( cancelledRunId ) ;
182193 expect ( result . thread . activeRunId ) . toBe ( activeRunId ) ;
194+
195+ callerUnavailable = true ;
196+ const denied = yield * service
197+ . readThread ( { ...makeScope ( ) , capabilities : new Set ( ) } , { threadId : parentThreadId } )
198+ . pipe ( Effect . flip ) ;
199+ expect ( denied . code ) . toBe ( "capability_denied" ) ;
200+ const missingCaller = yield * service
201+ . readThread ( makeScope ( ) , { threadId : parentThreadId } )
202+ . pipe ( Effect . flip ) ;
203+ expect ( missingCaller . code ) . toBe ( "orchestration_error" ) ;
204+ expect ( missingCaller . message ) . toContain ( `Unable to read thread ${ parentThreadId } :` ) ;
183205 } ) . pipe ( Effect . provide ( layer ) , Effect . runPromise ) ;
184206} ) ;
185207
0 commit comments