@@ -126,6 +126,7 @@ export class DeviceService extends Context.Service<
126126 ) => Effect . Effect < DeviceServiceState , DeviceError > ;
127127 /** Refreshes devices only after device support has been enabled. */
128128 readonly list : Effect . Effect < DeviceServiceState , DeviceError > ;
129+ readonly retryHost : ( hostId : DeviceHostId ) => Effect . Effect < DeviceServiceState , DeviceError > ;
129130 readonly open : ( input : DeviceOpenInput ) => Effect . Effect < DeviceSession , DeviceError > ;
130131 readonly close : ( input : DeviceCloseInput ) => Effect . Effect < void , DeviceError > ;
131132 readonly shutdown : ( input : DeviceShutdownInput ) => Effect . Effect < void , DeviceError > ;
@@ -202,6 +203,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
202203 let publishedHosts = new Map ( hosts ) ;
203204 const stateRef = yield * SynchronizedRef . make < ServiceState > ( {
204205 state : {
206+ supportsHostRetry : true ,
205207 hosts : initialHosts ,
206208 hostStatus : initialSettings . enabled ? "idle" : "disabled" ,
207209 hostStatuses : { } ,
@@ -257,7 +259,9 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
257259 } ) ;
258260 }
259261 const ready = yield * host
260- . ensureReady ( ( status ) => setHostStatus ( host . id , { status } ) . pipe ( Effect . asVoid ) )
262+ . ensureReady ( ( status , detail ) =>
263+ setHostStatus ( host . id , { status, detail } ) . pipe ( Effect . asVoid ) ,
264+ )
261265 . pipe (
262266 Effect . tapError ( ( error ) =>
263267 setHostStatus ( host . id , { status : "failed" , detail : error . message } ) ,
@@ -269,7 +273,9 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
269273 reason :
270274 error . _tag === "NodeRuntimeUnavailableError"
271275 ? nodeRuntimeUnavailableMessage ( "Local device support" )
272- : `Device host ${ error . hostId } failed while ${ error . step } .` ,
276+ : error . step === "probe"
277+ ? "Could not connect to this host over SSH."
278+ : `Device support failed during ${ error . step } .` ,
273279 cause : error ,
274280 } ) ,
275281 ) ,
@@ -308,7 +314,9 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
308314 if ( summary . kind === "local" && ! summary . platforms . some ( ( platform ) => platform . available ) )
309315 return null ;
310316 const ready = yield * host
311- . ensureAgentReady ( ( phase ) => setHostStatus ( host . id , { status : phase } ) . pipe ( Effect . asVoid ) )
317+ . ensureAgentReady ( ( phase , detail ) =>
318+ setHostStatus ( host . id , { status : phase , detail } ) . pipe ( Effect . asVoid ) ,
319+ )
312320 . pipe (
313321 Effect . tapError ( ( error ) =>
314322 setHostStatus ( host . id , { status : "failed" , detail : error . message } ) ,
@@ -321,8 +329,10 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
321329 error . _tag === "NodeRuntimeUnavailableError"
322330 ? nodeRuntimeUnavailableMessage ( "Local device support" )
323331 : error . _tag === "DeviceHostTimeoutError"
324- ? `Device host ${ error . hostId } did not start agent tools within ${ error . timeoutMs } ms.`
325- : `Device host ${ error . hostId } failed while ${ error . step } .` ,
332+ ? `Agent tools did not start within ${ error . timeoutMs } ms.`
333+ : error . step === "probe"
334+ ? "Could not connect to this host over SSH."
335+ : `Device support failed during ${ error . step } .` ,
326336 cause : error ,
327337 } ) ,
328338 ) ,
@@ -444,14 +454,37 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
444454 if ( ready ) yield * refresh ( ready ) ;
445455 } ) . pipe (
446456 Effect . catch ( ( error ) =>
447- setHostStatus ( host . id , { status : "failed" , detail : error . message } ) ,
457+ setHostStatus ( host . id , {
458+ status : "failed" ,
459+ detail : error . _tag === "DeviceHostUnavailableError" ? error . reason : error . message ,
460+ } ) ,
448461 ) ,
449462 ) ,
450463 { concurrency : 4 } ,
451464 ) ;
452465 return ( yield * SynchronizedRef . get ( stateRef ) ) . state ;
453466 } ) . pipe ( Effect . withSpan ( "DeviceService.list" ) ) ;
454467
468+ const retryHost : DeviceService [ "Service" ] [ "retryHost" ] = Effect . fn ( "DeviceService.retryHost" ) (
469+ function * ( hostId ) {
470+ yield * resolveHost ( hostId ) ;
471+ if ( ! ( yield * readDeviceSettings ) . enabled ) return ( yield * SynchronizedRef . get ( stateRef ) ) . state ;
472+ yield * Effect . gen ( function * ( ) {
473+ const ready =
474+ ( yield * agentReadinessIfSupported ( hostId ) ) ?? ( yield * readinessIfSupported ( hostId ) ) ;
475+ if ( ready ) yield * refresh ( ready ) ;
476+ } ) . pipe (
477+ Effect . catch ( ( error ) =>
478+ setHostStatus ( hostId , {
479+ status : "failed" ,
480+ detail : error . _tag === "DeviceHostUnavailableError" ? error . reason : error . message ,
481+ } ) ,
482+ ) ,
483+ ) ;
484+ return ( yield * SynchronizedRef . get ( stateRef ) ) . state ;
485+ } ,
486+ ) ;
487+
455488 const configure : DeviceService [ "Service" ] [ "configure" ] = Effect . fn ( "DeviceService.configure" ) (
456489 function * ( input ) {
457490 const currentSettings = yield * readDeviceSettings ;
@@ -832,6 +865,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
832865 return {
833866 ...DeviceService . of ( {
834867 testHost,
868+ retryHost,
835869 agentCli : Effect . fail (
836870 new DeviceHostUnavailableError ( {
837871 hostId : LOCAL_DEVICE_HOST_ID ,
0 commit comments