diff --git a/pkg/cli/mcp_inspect.go b/pkg/cli/mcp_inspect.go index 27a55d1837f..14ae867fe15 100644 --- a/pkg/cli/mcp_inspect.go +++ b/pkg/cli/mcp_inspect.go @@ -22,6 +22,9 @@ import ( var mcpInspectLog = logger.New("cli:mcp_inspect") +// mcpScriptsServerShutdownDelay gives the embedded mcp-scripts server a brief window to stop gracefully. +const mcpScriptsServerShutdownDelay = 500 * time.Millisecond + // InspectWorkflowMCP inspects MCP servers used by a workflow and lists available tools, resources, and roots func InspectWorkflowMCP(workflowFile string, serverFilter string, toolFilter string, verbose bool, useActionsSecrets bool) error { mcpInspectLog.Printf("Inspecting workflow MCP: workflow=%s, serverFilter=%s, toolFilter=%s", @@ -131,7 +134,7 @@ func InspectWorkflowMCP(workflowFile string, serverFilter string, toolFilter str fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to send interrupt signal: %v", err))) } // Wait a moment for graceful shutdown - time.Sleep(500 * time.Millisecond) + time.Sleep(mcpScriptsServerShutdownDelay) // Attempt force kill (may fail if process already exited gracefully, which is fine) _ = mcpScriptsServerCmd.Process.Kill() } diff --git a/pkg/cli/mcp_inspect_inspector.go b/pkg/cli/mcp_inspect_inspector.go index 54ec6b07e65..3c6e9165958 100644 --- a/pkg/cli/mcp_inspect_inspector.go +++ b/pkg/cli/mcp_inspect_inspector.go @@ -17,6 +17,13 @@ import ( var mcpInspectorLog = logger.New("cli:mcp_inspect_inspector") +const ( + // mcpStdioServerStartupDelay gives stdio MCP servers time to start accepting connections. + mcpStdioServerStartupDelay = 2 * time.Second + // mcpProcessCleanupDelay spaces cleanup signals so each MCP process can exit cleanly. + mcpProcessCleanupDelay = 100 * time.Millisecond +) + // spawnMCPInspector launches the official @modelcontextprotocol/inspector tool // and spawns any stdio MCP servers beforehand func spawnMCPInspector(workflowFile string, serverFilter string, verbose bool) error { @@ -154,7 +161,7 @@ func spawnMCPInspector(workflowFile string, serverFilter string, verbose bool) e } // Give servers a moment to start up - time.Sleep(2 * time.Second) + time.Sleep(mcpStdioServerStartupDelay) fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("All stdio servers started successfully")) } @@ -198,7 +205,7 @@ func spawnMCPInspector(workflowFile string, serverFilter string, verbose bool) e } // Give each process a chance to clean up if i < len(serverProcesses)-1 { - time.Sleep(100 * time.Millisecond) + time.Sleep(mcpProcessCleanupDelay) } } // Wait for all background goroutines to finish (with timeout) diff --git a/pkg/cli/mcp_inspect_mcp_scripts_server.go b/pkg/cli/mcp_inspect_mcp_scripts_server.go index d4657cd41d3..15a19368c57 100644 --- a/pkg/cli/mcp_inspect_mcp_scripts_server.go +++ b/pkg/cli/mcp_inspect_mcp_scripts_server.go @@ -20,6 +20,8 @@ const ( // Port range for mcp-scripts HTTP server mcpScriptsStartPort = 3000 mcpScriptsPortRange = 10 + // mcpScriptsServerStartupDelay paces readiness checks while the mcp-scripts server boots. + mcpScriptsServerStartupDelay = 200 * time.Millisecond ) // findAvailablePort finds an available port starting from the given port @@ -59,7 +61,7 @@ func waitForServerReady(port int, timeout time.Duration, verbose bool) bool { } return true } - time.Sleep(200 * time.Millisecond) + time.Sleep(mcpScriptsServerStartupDelay) } mcpInspectLog.Printf("Server did not become ready within timeout") diff --git a/pkg/cli/run_workflow_execution.go b/pkg/cli/run_workflow_execution.go index 32e29071e0e..861149d46ee 100644 --- a/pkg/cli/run_workflow_execution.go +++ b/pkg/cli/run_workflow_execution.go @@ -25,6 +25,9 @@ var executionLog = logger.New("cli:run_workflow_execution") // workflowCompletionWaitTimeoutMinutes matches the GitHub Actions maximum job runtime. const workflowCompletionWaitTimeoutMinutes = 6 * 60 +// betweenWorkflowsDelay paces sequential workflow triggers to avoid overwhelming the GitHub API. +const betweenWorkflowsDelay = 1 * time.Second + // RunOptions contains all configuration options for running workflows type RunOptions struct { Enable bool // Enable the workflow if it's disabled @@ -568,7 +571,7 @@ func RunWorkflowsOnGitHub(ctx context.Context, workflowNames []string, opts RunO // Add a small delay between workflows to avoid overwhelming GitHub API if i < len(workflowNames)-1 { - time.Sleep(1 * time.Second) + time.Sleep(betweenWorkflowsDelay) } } diff --git a/pkg/cli/trial_repository.go b/pkg/cli/trial_repository.go index 463f7d08a0a..a111361c57e 100644 --- a/pkg/cli/trial_repository.go +++ b/pkg/cli/trial_repository.go @@ -19,6 +19,9 @@ import ( var trialRepoLog = logger.New("cli:trial_repository") +// trialRepoInitDelay gives GitHub time to finish initializing a newly created repository. +const trialRepoInitDelay = 2 * time.Second + // checkoutActionPattern matches actions/checkout step lines with leading indentation var checkoutActionPattern = regexp.MustCompile(`^(\s*)(uses: actions/checkout@[^\s]*)(.*)$`) @@ -150,7 +153,7 @@ func ensureTrialRepository(repoSlug string, cloneRepoSlug string, forceDeleteHos } // Give GitHub a moment to fully initialize the repository - time.Sleep(2 * time.Second) + time.Sleep(trialRepoInitDelay) return nil }