@@ -2315,3 +2315,79 @@ describe("OrchestratorMcpService provider resolution", () => {
23152315 ) ;
23162316 } ) ;
23172317} ) ;
2318+
2319+ describe ( "OrchestratorMcpService thread lookup" , ( ) => {
2320+ const bareId = ThreadId . make ( "5d0b4a3e-8c1f-4a52-9d37-2f6c7e1b9a04" ) ;
2321+ const launched = liveThreadShell ( ThreadId . make ( `mcp:${ bareId } ` ) ) ;
2322+ const deletedLaunched = { ...launched , deletedAt : DateTime . makeUnsafe ( "2026-10-05T00:00:00Z" ) } ;
2323+ const client : McpInvocationScope = {
2324+ environmentId : EnvironmentId . make ( "environment:thread-lookup" ) ,
2325+ requestNamespace : "client:thread-lookup" ,
2326+ thread : undefined ,
2327+ client : { sessionId : "thread-lookup" , label : "Claude Code" , access : "full-access" } ,
2328+ capabilities : new Set ( [ "orchestration" ] ) ,
2329+ issuedAt : 1 ,
2330+ } ;
2331+ const service = ( shells : ReadonlyArray < OrchestrationV2ThreadShell > , sent : Ref . Ref < number > ) =>
2332+ layerOrchestratorService . pipe (
2333+ Layer . provide (
2334+ Layer . mergeAll (
2335+ NodeServices . layer ,
2336+ Layer . mock ( ThreadManagementService . ThreadManagementService ) ( {
2337+ getThreadShell : ( threadId ) =>
2338+ Effect . succeed ( shells . find ( ( shell ) => shell . id === threadId ) ?? null ) ,
2339+ sendToThread : ( ) => Ref . update ( sent , ( count ) => count + 1 ) . pipe ( Effect . as ( { } as never ) ) ,
2340+ } ) ,
2341+ ServerSettings . layerTest ( ) ,
2342+ Layer . mock ( ProviderRegistry . ProviderRegistry ) ( { getProviders : Effect . succeed ( [ ] ) } ) ,
2343+ Layer . mock ( ProviderAdapterRegistry . ProviderAdapterRegistryV2 ) ( {
2344+ list : ( ) => Effect . succeed ( [ ] ) ,
2345+ } ) ,
2346+ Layer . mock ( ProjectService . ProjectService ) ( { } ) ,
2347+ Layer . mock ( SecretRequests . SecretRequests ) ( { } ) ,
2348+ Layer . mock ( ScheduledTaskService . ScheduledTaskService ) ( { } ) ,
2349+ ) ,
2350+ ) ,
2351+ ) ;
2352+ const failuresFor = ( shells : ReadonlyArray < OrchestrationV2ThreadShell > ) =>
2353+ Effect . gen ( function * ( ) {
2354+ const sent = yield * Ref . make ( 0 ) ;
2355+ return yield * Effect . gen ( function * ( ) {
2356+ const mcp = yield * OrchestratorMcpService . OrchestratorMcpService ;
2357+ const read = yield * mcp . readThread ( client , { threadId : bareId } ) . pipe ( Effect . flip ) ;
2358+ const send = yield * mcp
2359+ . sendToThread ( client , { threadId : bareId , message : "hello" } )
2360+ . pipe ( Effect . flip ) ;
2361+ return { read, send, sends : yield * Ref . get ( sent ) } ;
2362+ } ) . pipe ( Effect . provide ( service ( shells , sent ) ) ) ;
2363+ } ) ;
2364+
2365+ it . effect ( "points a bare uuid at the mcp: thread it belongs to" , ( ) =>
2366+ Effect . gen ( function * ( ) {
2367+ const { read, send, sends } = yield * failuresFor ( [ launched ] ) ;
2368+ for ( const error of [ read , send ] ) {
2369+ assert . equal ( error . code , "thread_not_found" ) ;
2370+ assert . include ( error . message , `mcp:${ bareId } ` ) ;
2371+ }
2372+ assert . equal ( sends , 0 ) ;
2373+ } ) ,
2374+ ) ;
2375+
2376+ it . effect ( "keeps the plain message for an id that matches nothing" , ( ) =>
2377+ Effect . gen ( function * ( ) {
2378+ const { read, send } = yield * failuresFor ( [ ] ) ;
2379+ assert . equal ( read . code , "thread_not_found" ) ;
2380+ assert . equal ( read . message , `Thread ${ bareId } is no longer available.` ) ;
2381+ assert . equal ( send . code , "thread_not_found" ) ;
2382+ assert . equal ( send . message , `Thread ${ bareId } was not found.` ) ;
2383+ } ) ,
2384+ ) ;
2385+
2386+ it . effect ( "does not name an mcp: thread that was deleted" , ( ) =>
2387+ Effect . gen ( function * ( ) {
2388+ const { read, send } = yield * failuresFor ( [ deletedLaunched ] ) ;
2389+ assert . equal ( read . message , `Thread ${ bareId } is no longer available.` ) ;
2390+ assert . equal ( send . message , `Thread ${ bareId } was not found.` ) ;
2391+ } ) ,
2392+ ) ;
2393+ } ) ;
0 commit comments