ScuttleBot
fix: delay initial bot sync so bridge creates channels first
Commit
e6c41b360806db35e47b2cf61a4c7aa4f518cd2a06cbed428999e45f880e8fd4
Parent
c0cc5deead6d9c3…
1 file changed
+6
-3
+6
-3
| --- cmd/scuttlebot/main.go | ||
| +++ cmd/scuttlebot/main.go | ||
| @@ -278,12 +278,15 @@ | ||
| 278 | 278 | reg.SetOnlineTimeout(time.Duration(p.AgentPolicy.OnlineTimeoutSecs) * time.Second) |
| 279 | 279 | } |
| 280 | 280 | botMgr.Sync(ctx, specs) |
| 281 | 281 | }) |
| 282 | 282 | |
| 283 | - // Initial bot sync from loaded policies. | |
| 284 | - { | |
| 283 | + // Initial bot sync — delayed to let the bridge create channels first. | |
| 284 | + // Bots with join_all_channels need channels to exist before they query | |
| 285 | + // the channel list. The bridge takes ~2s to connect and join. | |
| 286 | + go func() { | |
| 287 | + time.Sleep(5 * time.Second) | |
| 285 | 288 | p := policyStore.Get() |
| 286 | 289 | specs := make([]botmanager.BotSpec, len(p.Behaviors)) |
| 287 | 290 | for i, b := range p.Behaviors { |
| 288 | 291 | specs[i] = botmanager.BotSpec{ |
| 289 | 292 | ID: b.ID, |
| @@ -293,11 +296,11 @@ | ||
| 293 | 296 | RequiredChannels: b.RequiredChannels, |
| 294 | 297 | Config: b.Config, |
| 295 | 298 | } |
| 296 | 299 | } |
| 297 | 300 | botMgr.Sync(ctx, specs) |
| 298 | - } | |
| 301 | + }() | |
| 299 | 302 | |
| 300 | 303 | // Agent reaper — periodically removes stale agents based on policy. |
| 301 | 304 | go func() { |
| 302 | 305 | ticker := time.NewTicker(1 * time.Hour) |
| 303 | 306 | defer ticker.Stop() |
| 304 | 307 |
| --- cmd/scuttlebot/main.go | |
| +++ cmd/scuttlebot/main.go | |
| @@ -278,12 +278,15 @@ | |
| 278 | reg.SetOnlineTimeout(time.Duration(p.AgentPolicy.OnlineTimeoutSecs) * time.Second) |
| 279 | } |
| 280 | botMgr.Sync(ctx, specs) |
| 281 | }) |
| 282 | |
| 283 | // Initial bot sync from loaded policies. |
| 284 | { |
| 285 | p := policyStore.Get() |
| 286 | specs := make([]botmanager.BotSpec, len(p.Behaviors)) |
| 287 | for i, b := range p.Behaviors { |
| 288 | specs[i] = botmanager.BotSpec{ |
| 289 | ID: b.ID, |
| @@ -293,11 +296,11 @@ | |
| 293 | RequiredChannels: b.RequiredChannels, |
| 294 | Config: b.Config, |
| 295 | } |
| 296 | } |
| 297 | botMgr.Sync(ctx, specs) |
| 298 | } |
| 299 | |
| 300 | // Agent reaper — periodically removes stale agents based on policy. |
| 301 | go func() { |
| 302 | ticker := time.NewTicker(1 * time.Hour) |
| 303 | defer ticker.Stop() |
| 304 |
| --- cmd/scuttlebot/main.go | |
| +++ cmd/scuttlebot/main.go | |
| @@ -278,12 +278,15 @@ | |
| 278 | reg.SetOnlineTimeout(time.Duration(p.AgentPolicy.OnlineTimeoutSecs) * time.Second) |
| 279 | } |
| 280 | botMgr.Sync(ctx, specs) |
| 281 | }) |
| 282 | |
| 283 | // Initial bot sync — delayed to let the bridge create channels first. |
| 284 | // Bots with join_all_channels need channels to exist before they query |
| 285 | // the channel list. The bridge takes ~2s to connect and join. |
| 286 | go func() { |
| 287 | time.Sleep(5 * time.Second) |
| 288 | p := policyStore.Get() |
| 289 | specs := make([]botmanager.BotSpec, len(p.Behaviors)) |
| 290 | for i, b := range p.Behaviors { |
| 291 | specs[i] = botmanager.BotSpec{ |
| 292 | ID: b.ID, |
| @@ -293,11 +296,11 @@ | |
| 296 | RequiredChannels: b.RequiredChannels, |
| 297 | Config: b.Config, |
| 298 | } |
| 299 | } |
| 300 | botMgr.Sync(ctx, specs) |
| 301 | }() |
| 302 | |
| 303 | // Agent reaper — periodically removes stale agents based on policy. |
| 304 | go func() { |
| 305 | ticker := time.NewTicker(1 * time.Hour) |
| 306 | defer ticker.Stop() |
| 307 |