@@ -44,6 +44,14 @@ private enum TransportProtocol
4444 private Button testConnectionButton ;
4545
4646 private bool connectionToggleInProgress ;
47+ private Task verificationTask ;
48+ private string lastHealthStatus ;
49+
50+ // Health status constants
51+ private const string HealthStatusUnknown = "Unknown" ;
52+ private const string HealthStatusHealthy = "Healthy" ;
53+ private const string HealthStatusPingFailed = "Ping Failed" ;
54+ private const string HealthStatusUnhealthy = "Unhealthy" ;
4755
4856 // Events
4957 public event Action OnManualConfigUpdateRequested ;
@@ -173,7 +181,7 @@ public void UpdateConnectionStatus()
173181 statusIndicator . AddToClassList ( "disconnected" ) ;
174182 connectionToggleButton . text = "Start Session" ;
175183
176- healthStatusLabel . text = "Unknown" ;
184+ healthStatusLabel . text = HealthStatusUnknown ;
177185 healthIndicator . RemoveFromClassList ( "healthy" ) ;
178186 healthIndicator . RemoveFromClassList ( "warning" ) ;
179187 healthIndicator . AddToClassList ( "unknown" ) ;
@@ -408,15 +416,33 @@ private async void OnTestConnectionClicked()
408416 }
409417
410418 public async Task VerifyBridgeConnectionAsync ( )
419+ {
420+ // Prevent concurrent verification calls
421+ if ( verificationTask != null && ! verificationTask . IsCompleted )
422+ {
423+ return ;
424+ }
425+
426+ verificationTask = VerifyBridgeConnectionInternalAsync ( ) ;
427+ await verificationTask ;
428+ }
429+
430+ private async Task VerifyBridgeConnectionInternalAsync ( )
411431 {
412432 var bridgeService = MCPServiceLocator . Bridge ;
413433 if ( ! bridgeService . IsRunning )
414434 {
415- healthStatusLabel . text = "Disconnected" ;
435+ healthStatusLabel . text = HealthStatusUnknown ;
416436 healthIndicator . RemoveFromClassList ( "healthy" ) ;
417437 healthIndicator . RemoveFromClassList ( "warning" ) ;
418438 healthIndicator . AddToClassList ( "unknown" ) ;
419- McpLog . Warn ( "Cannot verify connection: Bridge is not running" ) ;
439+
440+ // Only log if state changed
441+ if ( lastHealthStatus != HealthStatusUnknown )
442+ {
443+ McpLog . Warn ( "Cannot verify connection: Bridge is not running" ) ;
444+ lastHealthStatus = HealthStatusUnknown ;
445+ }
420446 return ;
421447 }
422448
@@ -426,23 +452,45 @@ public async Task VerifyBridgeConnectionAsync()
426452 healthIndicator . RemoveFromClassList ( "warning" ) ;
427453 healthIndicator . RemoveFromClassList ( "unknown" ) ;
428454
455+ string newStatus ;
429456 if ( result . Success && result . PingSucceeded )
430457 {
431- healthStatusLabel . text = "Healthy" ;
458+ newStatus = HealthStatusHealthy ;
459+ healthStatusLabel . text = newStatus ;
432460 healthIndicator . AddToClassList ( "healthy" ) ;
433- McpLog . Debug ( $ "Connection verification successful: { result . Message } ") ;
461+
462+ // Only log if state changed
463+ if ( lastHealthStatus != newStatus )
464+ {
465+ McpLog . Debug ( $ "Connection verification successful: { result . Message } ") ;
466+ lastHealthStatus = newStatus ;
467+ }
434468 }
435469 else if ( result . HandshakeValid )
436470 {
437- healthStatusLabel . text = "Ping Failed" ;
471+ newStatus = HealthStatusPingFailed ;
472+ healthStatusLabel . text = newStatus ;
438473 healthIndicator . AddToClassList ( "warning" ) ;
439- McpLog . Warn ( $ "Connection verification warning: { result . Message } ") ;
474+
475+ // Log once per distinct warning state
476+ if ( lastHealthStatus != newStatus )
477+ {
478+ McpLog . Warn ( $ "Connection verification warning: { result . Message } ") ;
479+ lastHealthStatus = newStatus ;
480+ }
440481 }
441482 else
442483 {
443- healthStatusLabel . text = "Unhealthy" ;
484+ newStatus = HealthStatusUnhealthy ;
485+ healthStatusLabel . text = newStatus ;
444486 healthIndicator . AddToClassList ( "warning" ) ;
445- McpLog . Error ( $ "Connection verification failed: { result . Message } ") ;
487+
488+ // Log once per distinct error state
489+ if ( lastHealthStatus != newStatus )
490+ {
491+ McpLog . Error ( $ "Connection verification failed: { result . Message } ") ;
492+ lastHealthStatus = newStatus ;
493+ }
446494 }
447495 }
448496 }
0 commit comments