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 }