supervisor: fix panic crash and add recover
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
8ccd524f7d
commit
62319aef68
|
|
@ -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).
|
||||
|
|
|
|||
Reference in New Issue