feat: remove executor healthcheck (#263)

This commit is contained in:
Carlos Florêncio
2026-02-22 12:22:36 +00:00
committed by GitHub
parent d82aec1c0e
commit 66ba91ca3f
2 changed files with 3 additions and 96 deletions
@@ -4,7 +4,6 @@ package lifecycle
import (
"sync"
"time"
"go.uber.org/zap"
@@ -66,10 +65,9 @@ type Manager struct {
// from agentctl instances through the agent stream.
mcpHandler agentctl.MCPHandler
// Background cleanup
cleanupInterval time.Duration
stopCh chan struct{}
wg sync.WaitGroup
// Background goroutine coordination
stopCh chan struct{}
wg sync.WaitGroup
}
// NewManager creates a new lifecycle manager.
@@ -125,7 +123,6 @@ func NewManager(
eventPublisher: eventPublisher,
containerManager: containerManager,
historyManager: historyManager,
cleanupInterval: 30 * time.Second,
stopCh: stopCh,
}
@@ -87,18 +87,6 @@ func (m *Manager) Start(ctx context.Context) error {
m.logger.Info("recovered executions", zap.Int("count", len(recovered)))
}
// Start cleanup loop when container manager is available (Docker mode)
if m.containerManager != nil {
m.wg.Add(1)
go m.cleanupLoop(ctx)
m.logger.Info("cleanup loop started")
}
// Start health check loop for registered executor backends
m.wg.Add(1)
go m.healthCheckLoop(ctx)
m.logger.Info("health check loop started")
// Set up callbacks for passthrough mode (using standalone runtime)
if standaloneRT, err := m.executorRegistry.GetBackend(executor.NameStandalone); err == nil {
if interactiveRunner := standaloneRT.GetInteractiveRunner(); interactiveRunner != nil {
@@ -151,39 +139,6 @@ func (m *Manager) Stop() error {
return nil
}
// healthCheckLoop periodically checks the health of all registered executor backends.
func (m *Manager) healthCheckLoop(ctx context.Context) {
defer m.wg.Done()
ticker := time.NewTicker(60 * time.Second)
defer ticker.Stop()
for {
select {
case <-m.stopCh:
return
case <-ctx.Done():
return
case <-ticker.C:
m.runHealthChecks(ctx)
}
}
}
// runHealthChecks runs health checks on all registered executor backends.
func (m *Manager) runHealthChecks(ctx context.Context) {
if m.executorRegistry == nil {
return
}
results := m.executorRegistry.HealthCheckAll(ctx)
for name, err := range results {
if err != nil {
m.logger.Warn("executor backend health check failed",
zap.String("executor", string(name)),
zap.Error(err))
}
}
}
// StopAllAgents attempts a graceful shutdown of all active agents concurrently.
func (m *Manager) StopAllAgents(ctx context.Context) error {
executions := m.executionStore.List()
@@ -217,51 +172,6 @@ func (m *Manager) StopAllAgents(ctx context.Context) error {
return errors.Join(errs...)
}
// cleanupLoop runs periodic cleanup of stale containers
func (m *Manager) cleanupLoop(ctx context.Context) {
defer m.wg.Done()
ticker := time.NewTicker(m.cleanupInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
m.logger.Info("cleanup loop stopped (context cancelled)")
return
case <-m.stopCh:
m.logger.Info("cleanup loop stopped")
return
case <-ticker.C:
m.performCleanup(ctx)
}
}
}
// performCleanup checks for and cleans up stale containers (Docker mode only)
func (m *Manager) performCleanup(ctx context.Context) {
m.logger.Debug("running cleanup check")
// Skip cleanup if container manager is not available
if m.containerManager == nil {
m.logger.Debug("skipping cleanup - no container manager")
return
}
// List all kandev-managed containers
containers, err := m.containerManager.ListManagedContainers(ctx)
if err != nil {
m.logger.Error("failed to list containers for cleanup", zap.Error(err))
return
}
for _, container := range containers {
if container.State == containerStateExited {
m.cleanupExitedContainer(ctx, container.ID)
}
}
}
// cleanupExitedContainer handles cleanup for a single exited container.
func (m *Manager) cleanupExitedContainer(ctx context.Context, containerID string) {
execution, tracked := m.executionStore.GetByContainerID(containerID)