Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/agent/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ func (a *EnhancedAgent) Stop() error {
log.Printf("🛑 Stopping enhanced agent: %s", a.config.Name)

a.running = false
a.cancel()

// Cancel all active tasks
a.taskCoordinator.CancelAllTasks()
Expand All @@ -368,16 +367,21 @@ func (a *EnhancedAgent) Stop() error {
log.Printf("⚠️ Error disconnecting from network: %v", err)
}


// NOW cancel the context
a.cancel()
// Close cache connection
if a.agentCache != nil {
if err := a.agentCache.Close(); err != nil {
log.Printf("⚠️ Error closing cache connection: %v", err)
}
}

// Cleanup agent handler if it supports cleanup
// Cleanup agent handler with fresh context
if cleaner, ok := a.agentHandler.(types.AgentCleaner); ok {
if err := cleaner.Cleanup(a.ctx); err != nil {
cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cleanupCancel()
if err := cleaner.Cleanup(cleanupCtx); err != nil {
log.Printf("⚠️ Error cleaning up agent handler: %v", err)
}
}
Expand Down