Skip to content

Modern Docker Management, Designed for Everyone

fix: mark direct agents online when the dashboard reaches them (#4362)

Kyle Mendell8b3756c8feb6
diff --git a/backend/internal/dashboard/handler.go b/backend/internal/dashboard/handler.go
index 4297abd9e..64de7c45d 100644
--- a/backend/internal/dashboard/handler.go
+++ b/backend/internal/dashboard/handler.go
@@ -3,6 +3,7 @@ package dashboard
import (
"context"
"errors"
+ "log/slog"
"net/http"
"net/url"
"time"
@@ -248,6 +249,15 @@ func (h *DashboardHandler) runRemoteDashboardStreamPollerInternal(ctx context.Co
return
}
lastError = ""
+ // A successful snapshot proves the manager reaches this direct agent; edge liveness comes from the tunnel.
+ if !currentEnvironment.IsEdge {
+ // Legacy snapshots may succeed after the fetch deadline.
+ heartbeatCtx, cancelHeartbeat := context.WithTimeout(ctx, 5*time.Second)
+ defer cancelHeartbeat()
+ if heartbeatErr := h.environmentService.UpdateEnvironmentHeartbeat(heartbeatCtx, environmentID); heartbeatErr != nil {
+ slog.WarnContext(ctx, "Failed to update environment heartbeat", "environmentId", environmentID, "error", heartbeatErr)
+ }
+ }
publish(dashboard.StreamEvent{
Type: "snapshot",
EnvironmentID: environmentID,
diff --git a/backend/internal/environment/service.go b/backend/internal/environment/service.go
index 32b3e59bf..2adeba10b 100644
--- a/backend/internal/environment/service.go
+++ b/backend/internal/environment/service.go
@@ -1213,7 +1213,9 @@ func (s *EnvironmentService) TestConnection(ctx context.Context, id string, cust
}
status, err := s.health.Probe(ctx, id, apiURL, envRecord.IsEdge, customApiUrl != nil)
if customApiUrl == nil {
- _ = s.updateEnvironmentStatusInternal(ctx, id, status)
+ if updateErr := s.updateEnvironmentStatusInternal(ctx, id, status); updateErr != nil {
+ slog.WarnContext(ctx, "Failed to persist environment status", "environmentId", id, "status", status, "error", updateErr)
+ }
return status, err
}
if err != nil {
@@ -1261,13 +1263,13 @@ func (s *EnvironmentService) UpdateEnvironmentHeartbeat(ctx context.Context, id
now := time.Now()
// Use Exec with raw SQL for better performance
- // Only update if last_seen is NULL or older than 30 seconds to reduce write frequency
+ // Throttle unchanged online status to one write every 30 seconds.
result := s.db.WithContext(ctx).Exec(`
UPDATE environments
SET last_seen = ?, status = ?, updated_at = ?
WHERE id = ?
- AND (last_seen IS NULL OR last_seen < ?)
- `, new(now), string(EnvironmentStatusOnline), new(now), id, now.Add(-30*time.Second))
+ AND (status != ? OR last_seen IS NULL OR last_seen < ?)
+ `, new(now), string(EnvironmentStatusOnline), new(now), id, string(EnvironmentStatusOnline), now.Add(-30*time.Second))
if result.Error != nil {
// The 30s throttle above doubles as the notify throttle: a no-op heartbeat