Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

fix(tools): rebuild the flow primary container when the daemon lost it

Fahad7d675b313a6f
diff --git a/backend/pkg/tools/tools.go b/backend/pkg/tools/tools.go
index a460e15d..c3d8b107 100644
--- a/backend/pkg/tools/tools.go
+++ b/backend/pkg/tools/tools.go
@@ -481,18 +481,24 @@ func (fte *flowToolsExecutor) SetGraphitiClient(client *graphiti.Client) {
func (fte *flowToolsExecutor) Prepare(ctx context.Context) error {
if cnt, err := fte.db.GetFlowPrimaryContainer(ctx, fte.flowID); err == nil {
- switch cnt.Status {
- case database.ContainerStatusRunning:
- fte.primaryID = cnt.ID
- fte.primaryLID = cnt.LocalID.String
- if err := fte.syncMissingFiles(ctx); err != nil {
- containerName := PrimaryTerminalName(fte.cfg.TenantPrefix(), fte.flowID)
- return fmt.Errorf("failed to sync missing files to container '%s': %w", containerName, err)
+ // the stored status goes stale when the container is removed outside pentagi
+ if cnt.Status == database.ContainerStatusRunning {
+ containerName := PrimaryTerminalName(fte.cfg.TenantPrefix(), fte.flowID)
+ running, err := fte.docker.IsContainerRunning(ctx, cnt.LocalID.String)
+ if err != nil {
+ return fmt.Errorf("failed to inspect container '%s': %w", containerName, err)
+ }
+ if running {
+ fte.primaryID = cnt.ID
+ fte.primaryLID = cnt.LocalID.String
+ if err := fte.syncMissingFiles(ctx); err != nil {
+ return fmt.Errorf("failed to sync missing files to container '%s': %w", containerName, err)
+ }
+ return nil
}
- return nil
- default:
- fte.docker.RemoveContainer(ctx, cnt.LocalID.String, cnt.ID)
}
+
+ fte.docker.RemoveContainer(ctx, cnt.LocalID.String, cnt.ID)
}
// Explicit capability allow-list (CapDrop: ALL below): Docker's default 14