From b3cf8b41aaa74fd57b6e20a774b1663d03116c85 Mon Sep 17 00:00:00 2001 From: Egutierrez Date: Fri, 22 May 2026 21:31:41 +0200 Subject: [PATCH] fix(api): autodetect unified vs multi-process status for running field handlers + poller llamaban Manager.StatusAll() siempre. En unified mode (launcher arranca todos los agents como goroutines bajo 1 PID) no existen PID files por agente, asi que StatusAll devolvia Running=false aunque los agents estaban operativos. Anade Server.statusAllAuto() que chequea IsUnifiedRunning() y delega a StatusAllUnified() o StatusAll() segun corresponda. Reemplaza las 3 llamadas directas en handlers.go (handleListAgents, handleGetAgent) y poller.go (pollStatus seed + checkAndPublishDiffs). Sin esto el frontend (0129) mostraria running=false universal. Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/api/handlers.go | 15 +++++++++++++-- internal/api/poller.go | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 3ae2d43..6e18f68 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -51,10 +51,21 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, map[string]string{"status": "ok", "time": time.Now().UTC().Format(time.RFC3339)}) } +// statusAllAuto chooses unified vs multi-process status based on runtime mode. +// In unified mode all agents run as goroutines under one launcher process — per-agent +// PID files do not exist, so StatusAll reports Running=false. StatusAllUnified +// reflects the real state. +func (s *Server) statusAllAuto() ([]process.AgentStatus, error) { + if s.mgr.IsUnifiedRunning() { + return s.mgr.StatusAllUnified() + } + return s.mgr.StatusAll() +} + // --- List agents --- func (s *Server) handleListAgents(w http.ResponseWriter, r *http.Request) { - statuses, err := s.mgr.StatusAll() + statuses, err := s.statusAllAuto() if err != nil { writeError(w, http.StatusInternalServerError, fmt.Sprintf("scan: %v", err)) return @@ -70,7 +81,7 @@ func (s *Server) handleListAgents(w http.ResponseWriter, r *http.Request) { func (s *Server) handleGetAgent(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") - statuses, err := s.mgr.StatusAll() + statuses, err := s.statusAllAuto() if err != nil { writeError(w, http.StatusInternalServerError, fmt.Sprintf("scan: %v", err)) return diff --git a/internal/api/poller.go b/internal/api/poller.go index e3082a6..c57fcf1 100644 --- a/internal/api/poller.go +++ b/internal/api/poller.go @@ -22,7 +22,7 @@ func (s *Server) pollStatus(ctx context.Context) { // Seed the previous state map. prev := make(map[string]bool) - if statuses, err := s.mgr.StatusAll(); err == nil { + if statuses, err := s.statusAllAuto(); err == nil { for _, st := range statuses { prev[st.ID] = st.Running } @@ -39,7 +39,7 @@ func (s *Server) pollStatus(ctx context.Context) { } func (s *Server) checkAndPublishDiffs(prev map[string]bool) { - statuses, err := s.mgr.StatusAll() + statuses, err := s.statusAllAuto() if err != nil { return }