Show agent liveness, stuck/zombie detection and parse errors in admin

This commit is contained in:
Ian Gulliver
2026-10-14 22:35:53 -07:00
parent 33e682a9d5
commit 1dc09c77e0
21 changed files with 1072 additions and 114 deletions
+11
View File
@@ -50,6 +50,9 @@ type Manager struct {
deliverMu sync.Mutex
capMu sync.Mutex
bad *badLines
watchStop chan struct{}
}
type live struct {
@@ -82,6 +85,8 @@ func New(st *store.Store, limits Limits, worktreeRoot string) *Manager {
live: map[string]*live{},
rateLimits: map[api.AgentSessionVendor]map[string]any{},
merges: map[string]string{},
bad: newBadLines(),
watchStop: make(chan struct{}),
}
}
@@ -262,6 +267,8 @@ func (m *Manager) Recover(ctx context.Context) error {
}
func (m *Manager) Close() {
close(m.watchStop)
m.mu.Lock()
m.closing = true
all := []*live{}
@@ -559,6 +566,7 @@ func (m *Manager) ensureLive(ctx context.Context, sess api.AgentSession, task ap
"UserPromptSubmit": {{Func: remindGuidance}},
"Stop": {{Func: m.bounceProseQuestion(l)}},
},
OnBadLine: func(line []byte, reason string) { m.recordBadLine(l, line, reason) },
}
started, err := m.store.SessionStarted(ctx, sess.Id)
if err != nil {
@@ -595,6 +603,9 @@ func (m *Manager) pump(l *live) {
if err != nil {
slog.Error("record agent event", "session", l.id, "type", ev.Type, "err", err)
}
if isDecodeError(err) {
m.recordBadLine(l, ev.Raw, fmt.Sprintf("decode %s: %s", ev.Type, err))
}
if took := time.Since(start); took > 200*time.Millisecond {
slog.Info("agent event slow", "session", l.id, "type", ev.Type, "took", took)
}