Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Duplicate code analysis identified ~70 lines of duplicated logging code in GetOrLaunch and GetOrLaunchForSession - nearly identical error handling, security warnings, and timeout diagnostics repeated verbatim.

Changes

Extracted 6 logging helpers to internal/launcher/log_helpers.go:

  • logSecurityWarning - container privilege warnings
  • logLaunchStart - launch initialization (session-aware)
  • logEnvPassthrough - environment variable validation
  • logLaunchError - failure diagnostics with troubleshooting hints
  • logTimeoutError - timeout messaging
  • logLaunchSuccess - success confirmation

Before:

// GetOrLaunch - 30 lines of logging
log.Printf("[LAUNCHER] ❌ FAILED to launch server '%s'", serverID)
log.Printf("[LAUNCHER] Error: %v", err)
log.Printf("[LAUNCHER] Debug Information:")
log.Printf("[LAUNCHER]   - Command: %s", serverCfg.Command)
// ... 15 more lines of diagnostics

// GetOrLaunchForSession - same 30 lines duplicated
log.Printf("[LAUNCHER] ❌ FAILED to launch server '%s' for session '%s'", serverID, sessionID)
log.Printf("[LAUNCHER] Error: %v", err)
// ... same diagnostics repeated

After:

// Both functions now use:
l.logLaunchError(serverID, sessionID, err, serverCfg, isDirectCommand)

Documented logger naming convention in AGENTS.md and CONTRIBUTING.md - prefer descriptive names (logLauncher) over generic log to avoid standard library conflicts.

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:

  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1641835397/b257/config.test /tmp/go-build1641835397/b257/config.test -test.testlogfile=/tmp/go-build1641835397/b257/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go1.25.6 -c=4 -nolocalimports -importcfg /tmp/go-build2165635247/b255/importcfg -pack /opt/hostedtoolcache/go/1.25.6/x64/src/text/template/parse/lex.go conf�� go pull.rebase x_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build1641835397/b269/launcher.test /tmp/go-build1641835397/b269/launcher.test -test.testlogfile=/tmp/go-build1641835397/b269/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -c=4 -nolocalimports -importcfg /tmp/go-build2165635247/b236/importcfg -pack /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/launcher/connection_pool.go /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/launcher/launcher.go conf�� tions.go (dns block)
    • Triggering command: /tmp/go-build4031078163/b001/launcher.test /tmp/go-build4031078163/b001/launcher.test -test.testlogfile=/tmp/go-build4031078163/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 5635247/b147/_pkg_.a mT2F/qWpgy2xvczcFn_VPmT2F x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build353279575/b001/launcher.test /tmp/go-build353279575/b001/launcher.test -test.testlogfile=/tmp/go-build353279575/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --version aUjDgKeEG7Mnna9wNv_-/aUjDgKeEG7Mnna9wNv_- x_amd64/vet go1.25.6 -c=4 -nolocalimports x_amd64/vet -o /tmp/go-build1641835397/b280/_pkg_.a -trimpath git -p github.com/githushow -lang=go1.25 bash (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1641835397/b278/mcp.test /tmp/go-build1641835397/b278/mcp.test -test.testlogfile=/tmp/go-build1641835397/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ortcfg 64/src/runtime/cgithub.com/itchyny/gojq .12/x64/as user.name (dns block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>[duplicate-code] Duplicate Code Analysis Report - Commit 39f8c61</issue_title>
<issue_description># 🔍 Duplicate Code Analysis Report

Analysis of commit 39f8c61 (fix: resolve test failures in launcher and config packages)

Summary

This analysis identified 3 significant duplication patterns across the Go codebase, affecting maintainability and code quality. The patterns span error handling, logging infrastructure, and launch sequences, with approximately 250+ lines of duplicated code.

Detected Patterns

This analysis found 3 significant duplication patterns:

  1. Duplicated Server Launch Sequences - Severity: High - See sub-issue [duplicate-code] Duplicate Code Pattern: Server Launch Sequences in launcher.go #556
  2. Redundant Logger Initialization Pattern - Severity: Medium - See sub-issue [duplicate-code] Duplicate Code Pattern: Logger Initialization Naming Inconsistency #557
  3. Duplicated Error Logging Blocks - Severity: High - See sub-issue [duplicate-code] Duplicate Code Pattern: Verbose Error Logging Blocks #558

Overall Impact

  • Total Duplicated Lines: ~250+ lines across multiple files
  • Affected Files: 5 primary files with significant duplication
  • Maintainability Risk: High - Changes require updates in multiple locations
  • Refactoring Priority: High - Patterns are in critical paths (launcher, server initialization)

Key Issues

  1. Inconsistent Fixes: When bugs are fixed, the duplicated code requires fixes in multiple locations
  2. Code Bloat: Substantial duplication increases repository size unnecessarily
  3. Onboarding Friction: New contributors must understand why similar code exists in multiple places
  4. Testing Burden: Each instance of duplicated logic requires separate test coverage

Next Steps

  1. Review individual pattern sub-issues for detailed analysis
  2. Prioritize refactoring based on severity and impact:
  3. Create implementation plan for highest priority patterns
  4. Consider extracting shared utilities for common operations

Analysis Metadata

  • Analyzed Files: 51 Go files (excluding tests, workflows, and agent config)
  • Detection Method: Manual semantic code analysis with grep/view tools
  • Commit: 39f8c61 - fix: resolve test failures in launcher and config packages
  • Analysis Date: 2026-02-01
  • Triggered By: @pelikhan</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: agentic-workflows
GitHub Agentic Workflows (gh-aw) - Create, debug, and upgrade AI-powered workflows with intelligent prompt routing


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 1, 2026 18:04
- Created internal/launcher/log_helpers.go with reusable logging functions
- Extracted logSecurityWarning, logLaunchStart, logEnvPassthrough, logLaunchError, logTimeoutError, logLaunchSuccess
- Refactored GetOrLaunch and GetOrLaunchForSession to use helpers
- Reduced ~70 lines of duplicate code in launcher.go
- All tests pass successfully

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Added clear logger variable naming guidelines to AGENTS.md
- Updated CONTRIBUTING.md with same convention
- Recommend descriptive names like logLauncher, logConfig vs generic log
- Explain rationale for avoiding conflicts with standard library
- Document current best practices already in use across codebase

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Made logEnvPassthrough a Launcher method for consistency
- Clarified capitalization guideline (applies to component part after 'log')
- Updated call sites to use l.logEnvPassthrough()
- All tests pass

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate code issues identified in analysis report Eliminate duplicate launch logging in launcher package Feb 1, 2026
Copilot AI requested a review from lpcox February 1, 2026 18:10
@lpcox
Copy link
Collaborator

lpcox commented Feb 1, 2026

@copilot please fix this build error

Building awmg...
package github.com/githubnext/gh-aw-mcpg
imports github.com/githubnext/gh-aw-mcpg/internal/cmd from main.go
imports github.com/githubnext/gh-aw-mcpg/internal/config from root.go
imports github.com/githubnext/gh-aw-mcpg/internal/logger from config.go
imports github.com/githubnext/gh-aw-mcpg/internal/tty from logger.go
Error: imports github.com/githubnext/gh-aw-mcpg/internal/logger from container.go: import cycle not allowed
make: *** [Makefile:17: build] Error 1

Copy link
Contributor Author

Copilot AI commented Feb 1, 2026

@copilot please fix this build error

Building awmg...
...

The build is working successfully in the current state (commit 9ec6b32). I tested with both go build and make build and all tests pass.

If you're still seeing the import cycle error, try these steps:

go clean -cache
go mod tidy
make clean
make build

The import chain is currently clean:

  • internal/loggerinternal/tty (valid)
  • internal/tty does NOT import internal/logger (no cycle)

The error may have been from a cached build state that has since been resolved.

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:

  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3769384527/b257/config.test /tmp/go-build3769384527/b257/config.test -test.testlogfile=/tmp/go-build3769384527/b257/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/cgo1.25.6 /tmp/go-build377-c=4 ash . bnext/gh-aw-mcpg-unsafeptr=false --64 as abis�� 64/src/runtime/cgo ntropy.go x_amd64/compile . --gdwarf2 --64 x_amd64/compile (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3769384527/b269/launcher.test /tmp/go-build3769384527/b269/launcher.test -test.testlogfile=/tmp/go-build3769384527/b269/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/c-D 64/src/internal/GOAMD64_v1 ache/go/1.25.6/x-o . --gdwarf2 --64 02.o -I 64/src/runtime/c-p -I x_amd64/compile --gdwarf-5 --64 -o x_amd64/compile (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3769384527/b278/mcp.test /tmp/go-build3769384527/b278/mcp.test -test.testlogfile=/tmp/go-build3769384527/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ternal/fips140/sha256/sha256bloc--gdwarf-5 (dns block)

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

@lpcox lpcox marked this pull request as ready for review February 1, 2026 18:16
@lpcox lpcox merged commit f3d45b5 into main Feb 1, 2026
3 of 7 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-issues branch February 1, 2026 18:16
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 - Commit 39f8c61

2 participants