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:
2026-05-22 21:31:41 +02:00
parent 98839cd8a8
commit b3cf8b41aa
2 changed files with 15 additions and 4 deletions
+13 -2
View File
@@ -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
+2 -2
View File
@@ -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
}