Skip to content

refactor: deduplicate reconnect telemetry and SSE deprecation logging in connection.go#3660

Merged
lpcox merged 2 commits intomainfrom
copilot/duplicate-code-analysis-report
Apr 12, 2026
Merged

refactor: deduplicate reconnect telemetry and SSE deprecation logging in connection.go#3660
lpcox merged 2 commits intomainfrom
copilot/duplicate-code-analysis-report

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Three duplicate logging patterns in internal/mcp/connection.go created maintainability risk: reconnect lifecycle logs were copy-pasted verbatim across two sibling functions, and SSE deprecation connected with a 5-line near-identical warning burst.

Changes

  • Reconnect telemetry helpers — extracted logReconnectStart() and logReconnectResult(err error) methods; both reconnectPlainJSON() and reconnectSDKTransport() now delegate to them instead of duplicating three logger.Log* call sites each:

    func (c *Connection) logReconnectStart() {
        logger.LogWarn("backend", "MCP session expired for %s, attempting to reconnect...", c.serverID)
    }
    func (c *Connection) logReconnectResult(err error) {
        if err != nil {
            logger.LogError("backend", "Session reconnect failed for %s: %v", c.serverID, err)
        } else {
            logger.LogInfo("backend", "Session successfully reconnected for %s", c.serverID)
        }
    }
  • SSE deprecation warning — collapsed 5 overlapping LogWarn calls (all saying "SSE is deprecated, please migrate") into one LogWarn with the URL + spec version, plus one LogInfo for the connection confirmation. Issue [duplicate-code] Duplicate Code Pattern: Mixed log.Printf / logger.LogInfo Parallel Logging in connection.go #3633 (redundant log.Printf / logger.LogInfo pairs) was already resolved prior to this PR.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build3844589215/b514/launcher.test /tmp/go-build3844589215/b514/launcher.test -test.testlogfile=/tmp/go-build3844589215/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s -W .cfg elemetry.io/otel-ifaceassert x_amd64/vet ache/go/1.25.8/x/usr/libexec/docker/cli-plugins/docker-compose --gdwarf2 --64 x_amd64/vet -I .cfg om/yosida95/uritemplate/v3@v3.0.2/equals.go x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet (dns block)
  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh issue close 3634 --comment Fixed in PR #3660: Consolidated the 5-line SSE deprecation warning burst into 2 concise log calls ��� one LogWarncontaining the URL, spec version, and migration ask, and oneLogInfo` confirming the connection. This eliminates the near-duplicate messag ock
  • Extract logReconnectStart() and logReconnectResult(err) helpers to
    deduplicate the three identical logger.Log* call sites shared by
    reconnectPlainJSON() and reconne` (http block)
  • Triggering command: /usr/bin/gh gh issue close 3632 --comment Fixed in PR #3660: Extracted logReconnectStart()andlogReconnectResult(err)helper methods intoconnection.go. Both reconnectPlainJSON()andreconnectSDKTransport()now delegate their three sharedlogger.Log* call sites to these helpers, elim iVcYPCLQvuKP by/fbd8401427f0fc669ca1ec4ad2768json D8KssBkgN 059210538/b288///opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/go/tools/autobuild.sh (http block)
  • Triggering command: /usr/bin/gh gh issue comment 3634 --body Fixed in PR #3660: Consolidated the 5-line SSE deprecation warning burst into 2 concise log calls ��� one LogWarncontaining the URL, spec version, and migration ask, and oneLogInfo confirming the connection. --repo github/gh-aw-mcpg ntime.v2.task/mogit om/tetratelabs/w-c x_amd64/vet egration/start_glog 4589�� .go y /bin/java ntime.v2.task/mogit rg/x/net@v0.52.0add x_amd64/vet /bin/java (http block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3844589215/b496/config.test /tmp/go-build3844589215/b496/config.test -test.testlogfile=/tmp/go-build3844589215/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3844589215/b396/vet.cfg @v1.1.3/cpu/cpu.-errorsas om/tetratelabs/w-ifaceassert x_amd64/vet --gdwarf-5 nal/encoding/def-atomic -o x_amd64/vet -I hB8eipdrZ -I x_amd64/vet --gdwarf-5 9210538/b239/ -o x_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3844589215/b514/launcher.test /tmp/go-build3844589215/b514/launcher.test -test.testlogfile=/tmp/go-build3844589215/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s -W .cfg elemetry.io/otel-ifaceassert x_amd64/vet ache/go/1.25.8/x/usr/libexec/docker/cli-plugins/docker-compose --gdwarf2 --64 x_amd64/vet -I .cfg om/yosida95/uritemplate/v3@v3.0.2/equals.go x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3844589215/b514/launcher.test /tmp/go-build3844589215/b514/launcher.test -test.testlogfile=/tmp/go-build3844589215/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s -W .cfg elemetry.io/otel-ifaceassert x_amd64/vet ache/go/1.25.8/x/usr/libexec/docker/cli-plugins/docker-compose --gdwarf2 --64 x_amd64/vet -I .cfg om/yosida95/uritemplate/v3@v3.0.2/equals.go x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3844589215/b523/mcp.test /tmp/go-build3844589215/b523/mcp.test -test.testlogfile=/tmp/go-build3844589215/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3844589215/b517/_pkg_.a 64/src/os/signal/sig.s -I x_amd64/vet --gdwarf-5 g/grpc/credentiainspect -o x_amd64/vet -W /auth/apikey.go /auth/header.go x_amd64/vet . --gdwarf2 --64 x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
…recation block

- Extract logReconnectStart() and logReconnectResult(err) helpers to
  deduplicate the three identical logger.Log* call sites shared by
  reconnectPlainJSON() and reconnectSDKTransport() (issue #3632)
- Consolidate the 5-line SSE deprecation warning burst into 2 concise
  log calls: one LogWarn with URL and spec info, one LogInfo for the
  connection confirmation (issue #3634)
- Issue #3633 (Mixed log.Printf / logger.LogInfo) was already resolved

Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/adc38ef8-8512-47c3-805e-582ed80d5993

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze and resolve duplicate code issues refactor: deduplicate reconnect telemetry and SSE deprecation logging in connection.go Apr 12, 2026
Copilot AI requested a review from lpcox April 12, 2026 16:38
@lpcox lpcox marked this pull request as ready for review April 12, 2026 16:39
Copilot AI review requested due to automatic review settings April 12, 2026 16:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors internal/mcp/connection.go to reduce duplicated structured logging around reconnect flows and to simplify the SSE deprecation log burst, improving maintainability of connection/transport telemetry.

Changes:

  • Extracted shared reconnect lifecycle logging into (*Connection).logReconnectStart() and (*Connection).logReconnectResult(err).
  • Consolidated the SSE deprecation warning burst into a single LogWarn plus a single connection confirmation LogInfo.
Show a summary per file
File Description
internal/mcp/connection.go Deduplicates reconnect telemetry logs and collapses SSE deprecation logging into fewer, clearer structured log calls.

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: 0

@lpcox lpcox merged commit df79a19 into main Apr 12, 2026
30 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-analysis-report branch April 12, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Analysis Report

3 participants