Skip to content

[duplicate-code] Duplicate Code Analysis Report #3735

@github-actions

Description

@github-actions

Analysis of commit b950a22

Summary

Analysis of the 97 non-test Go files changed in the latest commit found 3 significant duplication patterns across the internal/logger, internal/cmd, and related packages. All patterns are medium-to-low severity but actionable.

Detected Patterns

This analysis found 3 significant duplication patterns:

  1. Identical withLock methods in logger structs — Severity: Low — See sub-issue [duplicate-code] Duplicate Code Pattern: Identical withLock methods in logger structs #3736
  2. Manual truncation logic bypassing established strutil/sanitize utilities — Severity: Medium — See sub-issue [duplicate-code] Duplicate Code Pattern: Manual truncation bypassing strutil/sanitize utilities #3737
  3. Duplicated write-and-sync core in file-based Log methods — Severity: Low — See sub-issue [duplicate-code] Duplicate Code Pattern: Duplicated write-and-sync logic in FileLogger and ServerFileLogger #3738

Overall Impact

  • Total Duplicated Lines: ~30 lines across the 3 patterns
  • Affected Files: 6 Go files (file_logger.go, jsonl_logger.go, markdown_logger.go, tools_logger.go, rpc_helpers.go, root.go, server_file_logger.go)
  • Maintainability Risk: Low overall — the logger package already has excellent generic helpers (withGlobalLogger, initGlobalLogger, etc.); remaining duplication is consistent noise rather than dangerous drift
  • Refactoring Priority: Medium — Pattern 2 (manual truncation) carries a higher risk of future bugs; the withLock and Log write-sync patterns are safe to defer

Next Steps

  1. Review individual pattern sub-issues for detailed analysis
  2. Address Pattern 2 (manual truncation) first — consistency with sanitize.TruncateSecret matters for security logging
  3. Address Pattern 1 (withLock embedding) as a low-effort follow-up cleanup

Analysis Metadata

  • Analyzed Files: 97 Go files (non-test, non-workflow)
  • Detection Method: Semantic code analysis + grep/diff pattern matching
  • Commit: b950a22d36a149b523c440baad83585349007783
  • Analysis Date: 2026-04-14

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions