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) <noreply@anthropic.com>
This commit is contained in:
@@ -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)})
|
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 ---
|
// --- List agents ---
|
||||||
|
|
||||||
func (s *Server) handleListAgents(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleListAgents(w http.ResponseWriter, r *http.Request) {
|
||||||
statuses, err := s.mgr.StatusAll()
|
statuses, err := s.statusAllAuto()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("scan: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("scan: %v", err))
|
||||||
return
|
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) {
|
func (s *Server) handleGetAgent(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.PathValue("id")
|
id := r.PathValue("id")
|
||||||
statuses, err := s.mgr.StatusAll()
|
statuses, err := s.statusAllAuto()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Sprintf("scan: %v", err))
|
writeError(w, http.StatusInternalServerError, fmt.Sprintf("scan: %v", err))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (s *Server) pollStatus(ctx context.Context) {
|
|||||||
|
|
||||||
// Seed the previous state map.
|
// Seed the previous state map.
|
||||||
prev := make(map[string]bool)
|
prev := make(map[string]bool)
|
||||||
if statuses, err := s.mgr.StatusAll(); err == nil {
|
if statuses, err := s.statusAllAuto(); err == nil {
|
||||||
for _, st := range statuses {
|
for _, st := range statuses {
|
||||||
prev[st.ID] = st.Running
|
prev[st.ID] = st.Running
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ func (s *Server) pollStatus(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) checkAndPublishDiffs(prev map[string]bool) {
|
func (s *Server) checkAndPublishDiffs(prev map[string]bool) {
|
||||||
statuses, err := s.mgr.StatusAll()
|
statuses, err := s.statusAllAuto()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user