Conversation
…fix <\= 0 guard Addresses #3933. - Define package-level unexported constant defaultConnectTimeout = 30 * time.Second to serve as the single source of truth for the connect-timeout default in this package. - Replace inline '30 * time.Second' literals in NewHTTPConnection and reconnectSDKTransport with the named constant. - Fix inconsistent guard in reconnectSDKTransport: '== 0' → '<= 0' so that negative values (which are invalid) also fall back to the default, consistent with the guard in NewHTTPConnection. No functional change for valid inputs; negative connectTimeout values are now treated the same as zero (both → defaultConnectTimeout). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors MCP HTTP connection timeout defaults in internal/mcp to remove duplicated magic literals and aligns reconnect behavior with the existing “non-positive means default” semantics used elsewhere.
Changes:
- Introduce a package-local
defaultConnectTimeoutconstant (30s) to replace hardcoded30 * time.Secondusages without importinginternal/config. - Apply the constant in
NewHTTPConnectionandreconnectSDKTransport. - Fix reconnect timeout guard from
== 0to<= 0to correctly default negative durations.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/connection.go | Centralizes the 30s connect-timeout fallback and makes reconnect timeout validation consistent (<= 0). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is a Repo Assist automated pull request.
Summary
Closes #3933.
Two locations in
internal/mcp/connection.goused the magic literal30 * time.Secondfor the HTTP connect-timeout fallback. A canonical constantconfig.DefaultConnectTimeout = 30already exists ininternal/config/config_core.go, but importing that package intointernal/mcpwould pull ininit()functions with side effects. Instead, this PR introduces a local unexported constant to be the single source of truth within the package.It also fixes a latent bug:
reconnectSDKTransportguarded with== 0, which left negative values through as-is. The guard is now<= 0, consistent withNewHTTPConnection.Root cause
Issue #3933 (Duplicate Code Detector) identified:
NewHTTPConnection(line ~202):if connectTimeout <= 0 { connectTimeout = 30 * time.Second }reconnectSDKTransport(line ~386):if timeout == 0 { timeout = 30 * time.Second }— note inconsistent guardBoth hardcode 30 s instead of using a named constant, and the guards differ.
Changes
internal/mcp/connection.goconst defaultConnectTimeout = 30 * time.Second; replace both magic literals with the constant; fix== 0→<= 0guard inreconnectSDKTransportTrade-offs
config?internal/confighasinit()functions that register flags and load schemas. Importing it intointernal/mcpjust for one constant would be a heavyweight dependency and could cause ordering surprises. A comment on the constant explicitly documents the sync requirement.connectTimeoutpassed toreconnectSDKTransportpreviously slipped through; it now falls back to 30 s. This is the correct behaviour (negative durations are invalid) and consistent withNewHTTPConnection.Test Status
proxy.golang.orgis blocked by the environment firewall, preventinggo testfrom downloading the required Go toolchain (go1.25.0). The change is a pure constant-introduction refactor with no logic change for valid inputs; the== 0→<= 0guard fix is covered by the companion PR adding dedicated tests (repo-assist/test-connect-timeout-defaults).Warning
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.