From 62319aef685f235da51c084441df56c76a30d4f7 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Sat, 14 Mar 2026 16:08:54 +0100 Subject: [PATCH] supervisor: fix panic crash and add recover MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bead["id"].(string) was an unsafe type assertion — panicked if id was missing or not a string, killing the server process. Use comma-ok form. - Add recover() to Run() to log panics instead of crashing anvilsrv. Co-Authored-By: Claude Sonnet 4.6 --- internal/supervisor/supervisor.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/supervisor/supervisor.go b/internal/supervisor/supervisor.go index 610c4d0..eab6aaf 100644 --- a/internal/supervisor/supervisor.go +++ b/internal/supervisor/supervisor.go @@ -7,9 +7,11 @@ import ( "time" "anvillm/internal/eventbus" + "anvillm/internal/logging" "anvillm/internal/mailbox" "anvillm/internal/p9" "anvillm/internal/session" + "go.uber.org/zap" ) type Supervisor struct { @@ -105,8 +107,11 @@ func (s *Supervisor) assignWork() { continue } - beadID := bead["id"].(string) + beadID, _ := bead["id"].(string) mountName, _ := bead["mount"].(string) + if beadID == "" { + continue + } msg := mailbox.NewMessage("supervisor", botID, mailbox.MessageTypePromptRequest, "work", "Work on bead "+beadID+", mount="+mountName+".") s.mailbox.DeliverToInbox(botID, msg) @@ -116,6 +121,11 @@ func (s *Supervisor) assignWork() { } func (s *Supervisor) Run(ctx context.Context) { + defer func() { + if r := recover(); r != nil { + logging.Logger().Error("supervisor panic", zap.Any("panic", r)) + } + }() events, cancel := s.eventbus.Subscribe() defer cancel() // Fallback ticker: catches anything missed by events (e.g. startup, edge cases).