Skip to content

Duplicate code already eliminated - close issue#817

Merged
lpcox merged 1 commit intomainfrom
copilot/fix-duplicate-code-issues
Feb 7, 2026
Merged

Duplicate code already eliminated - close issue#817
lpcox merged 1 commit intomainfrom
copilot/fix-duplicate-code-issues

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

Automated analysis reported ~200 lines of duplicate code across 3 patterns. Investigation shows all significant duplication already eliminated through prior refactoring.

Findings

Pattern 1: Logger initialization (~120 lines) ✅ Resolved

  • Generic helpers: initGlobalLogger[T](), closeGlobalLogger[T]() in global_helpers.go
  • Generic file init: initLogger[T]() with customizable fallback in common.go
  • Handles all 4 logger types (FileLogger, JSONLLogger, MarkdownLogger, ServerFileLogger)

Pattern 2: Flag env getters (~40 lines) ✅ Resolved

Pattern 3: Global log functions (~96 lines) ⚠️ By design

  • Thin public API wrappers (8 lines each, 119+ call sites)
  • markdown_logger.go already uses logWithMarkdown() helper
  • server_file_logger.go has different signature and dual-logging behavior
  • Standard Go idiom for stable APIs

Result

160 lines of actual duplication eliminated. Remaining "duplication" is intentional thin wrappers following Go best practices. No code changes required.

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-build1073420489/b275/launcher.test /tmp/go-build1073420489/b275/launcher.test -test.testlogfile=/tmp/go-build1073420489/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go --global 64/pkg/tool/linux_amd64/asm pull.rebase (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1073420489/b260/config.test /tmp/go-build1073420489/b260/config.test -test.testlogfile=/tmp/go-build1073420489/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go ternal/fips140/d--64 64/pkg/tool/linu-o user.name (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build1073420489/b275/launcher.test /tmp/go-build1073420489/b275/launcher.test -test.testlogfile=/tmp/go-build1073420489/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go --global 64/pkg/tool/linux_amd64/asm pull.rebase (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build1073420489/b275/launcher.test /tmp/go-build1073420489/b275/launcher.test -test.testlogfile=/tmp/go-build1073420489/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go --global 64/pkg/tool/linux_amd64/asm pull.rebase (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1073420489/b284/mcp.test /tmp/go-build1073420489/b284/mcp.test -test.testlogfile=/tmp/go-build1073420489/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a ternal/fips140/ed25519/cast.go 64/pkg/tool/linux_amd64/compile (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</issue_title>
<issue_description># 🔍 Duplicate Code Analysis Report

Analysis of commit db3ff1f

Summary

This analysis identified 3 significant duplication patterns in the codebase that impact maintainability and create opportunities for refactoring. The patterns span multiple packages including internal/logger and internal/cmd, with a total of ~200+ lines of duplicated or highly similar code.

Detected Patterns

This analysis found 3 significant duplication patterns:

  1. Logger Initialization Boilerplate - Severity: High - See sub-issue #aw_abc123def456
  2. Flag Environment Variable Getters - Severity: Medium - See sub-issue #aw_789ghi012jkl
  3. Global Logging Function Repetition - Severity: Medium - See sub-issue #aw_345mno678pqr

Overall Impact

  • Total Duplicated Lines: ~200+ lines of similar/duplicated code
  • Affected Files: 8 Go files across 2 packages (logger, cmd)
  • Maintainability Risk: High - Changes to patterns require updates across multiple files
  • Refactoring Priority: High for Pattern 1, Medium for Patterns 2-3

Key Findings

1. Logger Package (High Priority)

  • 4 logger files share nearly identical initialization patterns
  • Each logger reimplements: file opening, error handling, mutex setup, global state management
  • Total duplication: ~120+ lines across FileLogger, JSONLLogger, MarkdownLogger, ServerFileLogger

2. Flag Package (Medium Priority)

  • 3 getDefault functions* with identical structure in flags_logging.go
  • Additional similar function in flags_difc.go
  • Pattern: Check env var → parse/validate → fallback to default
  • Total duplication: ~40+ lines

3. Global Logging Functions (Medium Priority)

  • 4 LogLevel functions (Info/Warn/Error/Debug) repeated across 3 logger files
  • Each set: 4 functions × ~8 lines = ~32 lines per file
  • Total duplication: ~96+ lines across file_logger.go, markdown_logger.go, server_file_logger.go

Next Steps

  1. Review individual pattern sub-issues for detailed analysis
  2. Prioritize refactoring based on severity and impact (start with Pattern 1)
  3. Create implementation plan for highest priority patterns
  4. Consider extracting common utilities to shared helper functions

Analysis Metadata

AI generated by Duplicate Code Detector

  • expires on Feb 14, 2026, 10:13 AM UTC

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 changed the title [WIP] Fix duplicate code analysis report findings Duplicate code already eliminated - close issue Feb 7, 2026
Copilot AI requested a review from lpcox February 7, 2026 18:38
@lpcox lpcox marked this pull request as ready for review February 7, 2026 18:41
Copilot AI review requested due to automatic review settings February 7, 2026 18:41
Copy link
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.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lpcox lpcox merged commit c5df5c6 into main Feb 7, 2026
3 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-issues branch February 7, 2026 18:41
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

2 participants