@@ -224,24 +224,28 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
224
224
if ( string . IsNullOrWhiteSpace ( fqdn ) )
225
225
continue ;
226
226
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 ;
234
227
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 )
236
230
{
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 ;
238
241
}
239
- else if ( ! isLatencyAcceptable )
242
+ else
240
243
{
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 ;
242
247
}
243
248
244
-
245
249
workspacesWithAgents . Add ( agent . WorkspaceId ) ;
246
250
var workspace = rpcModel . Workspaces . FirstOrDefault ( w => w . Id == agent . WorkspaceId ) ;
247
251
@@ -257,7 +261,7 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
257
261
agent . LastPing ? . PreferredDerp ,
258
262
agent . LastPing ? . Latency ? . ToTimeSpan ( ) ,
259
263
agent . LastPing ? . PreferredDerpLatency ? . ToTimeSpan ( ) ,
260
- agent . LastHandshake ? . ToDateTime ( ) ) ) ;
264
+ agent . LastHandshake != null && agent . LastHandshake . ToDateTime ( ) != default ? agent . LastHandshake ? . ToDateTime ( ) : null ) ) ;
261
265
}
262
266
263
267
// For every stopped workspace that doesn't have any agents, add a
0 commit comments