@@ -224,24 +224,28 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
224224 if ( string . IsNullOrWhiteSpace ( fqdn ) )
225225 continue ;
226226
227- #pragma warning disable CS8602 // Protobuf will always set this value, so we can safely dereference them.
228- var lastHandshakeAgo = DateTime . UtcNow . Subtract ( agent . LastHandshake . ToDateTime ( ) ) ;
229- #pragma warning restore CS8602
230-
231- // For compatibility with older deployments, we assume that if the
232- // last ping is null, the agent is healthy.
233- var isLatencyAcceptable = agent . LastPing == null || agent . LastPing . Latency . ToTimeSpan ( ) < HealthyPingThreshold ;
234227 var connectionStatus = AgentConnectionStatus . Healthy ;
235- if ( lastHandshakeAgo > TimeSpan . FromMinutes ( 5 ) )
228+
229+ if ( agent . LastHandshake != null && agent . LastHandshake . ToDateTime ( ) != default && agent . LastHandshake . ToDateTime ( ) < DateTime . UtcNow )
236230 {
237- connectionStatus = AgentConnectionStatus . NoRecentHandshake ;
231+ // For compatibility with older deployments, we assume that if the
232+ // last ping is null, the agent is healthy.
233+ var isLatencyAcceptable = agent . LastPing == null || agent . LastPing . Latency . ToTimeSpan ( ) < HealthyPingThreshold ;
234+
235+ var lastHandshakeAgo = DateTime . UtcNow . Subtract ( agent . LastHandshake . ToDateTime ( ) ) ;
236+
237+ if ( lastHandshakeAgo > TimeSpan . FromMinutes ( 5 ) )
238+ connectionStatus = AgentConnectionStatus . NoRecentHandshake ;
239+ else if ( ! isLatencyAcceptable )
240+ connectionStatus = AgentConnectionStatus . Unhealthy ;
238241 }
239- else if ( ! isLatencyAcceptable )
242+ else
240243 {
241- connectionStatus = AgentConnectionStatus . Unhealthy ;
244+ // If the last handshake is not correct (null, default or in the future),
245+ // we assume the agent is connecting (yellow status icon).
246+ connectionStatus = AgentConnectionStatus . Connecting ;
242247 }
243248
244-
245249 workspacesWithAgents . Add ( agent . WorkspaceId ) ;
246250 var workspace = rpcModel . Workspaces . FirstOrDefault ( w => w . Id == agent . WorkspaceId ) ;
247251
@@ -257,7 +261,7 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
257261 agent . LastPing ? . PreferredDerp ,
258262 agent . LastPing ? . Latency ? . ToTimeSpan ( ) ,
259263 agent . LastPing ? . PreferredDerpLatency ? . ToTimeSpan ( ) ,
260- agent . LastHandshake ? . ToDateTime ( ) ) ) ;
264+ agent . LastHandshake != null && agent . LastHandshake . ToDateTime ( ) != default ? agent . LastHandshake ? . ToDateTime ( ) : null ) ) ;
261265 }
262266
263267 // For every stopped workspace that doesn't have any agents, add a
0 commit comments