Skip to content

[duplicate-code] Duplicate Code Analysis Report #13965

Closed as not planned
2 of 2 issues completed
Closed as not planned

Description

@github-actions

Analysis of commit ed65db4

Summary

Semantic analysis of the internal/server, internal/logger, and internal/sanitize packages (centered on the enclave payload-redaction logic touched by the latest commit, internal/server/sdk_logging.go) found 2 significant duplication patterns worth tracking. Both relate to the enclave-scoped payload/error redaction mechanism (sanitize.ShouldRedactPayload / sanitize.RedactedPayloadText / sanitize.RedactErrorForLog / sanitize.KeyedDigest), which is deliberately repeated at many call sites by design (per the extensive doc comments in internal/sanitize/payload_redaction.go). Most of that repetition is intentional and not flagged here. However, two spots cross from "consistent idiom" into literal, refactorable duplication.

Detected Patterns

  1. Duplicate error-redaction helper functions - Severity: Medium - See sub-issue #aw_dupfn0001aa22
  2. Repeated redact-or-sanitize payload-string branch - Severity: Medium - See sub-issue #aw_dupbr0002bb33

Overall Impact

  • Total Duplicated Lines: ~35 (12 lines exact-duplicate function bodies + ~23 lines of repeated branching logic across 5 sites)
  • Affected Files: 4 (internal/server/backend_call.go, internal/server/sdk_logging.go, internal/server/http_helpers.go, internal/server/tool_registry.go)
  • Maintainability Risk: Medium — the logic is security-sensitive (enclave data-leak prevention), so divergent copies risk silently diverging redaction behavior between call sites over time
  • Refactoring Priority: Medium — low implementation risk, meaningful reduction in copy-paste surface area for security-critical code

Next Steps

  1. Review individual pattern sub-issues for detailed analysis
  2. Consolidate both patterns into shared helpers in internal/sanitize
  3. Add unit tests asserting all call sites route through the shared helper

Analysis Metadata

  • Analyzed Files: internal/server/sdk_logging.go (new in this commit), plus cross-referenced existing files: internal/server/backend_call.go, internal/server/http_helpers.go, internal/server/tool_registry.go, internal/logger/rpc_logger.go, internal/sanitize/payload_redaction.go
  • Detection Method: Semantic pattern search for redaction call sites (ShouldRedactPayload, RedactedPayloadText, RedactErrorForLog, KeyedDigest) plus manual review of surrounding branch structure
  • Commit: ed65db4
  • Analysis Date: 2026-09-27

Generated by Duplicate Code Detector · copilot · auto · 76.5 AIC · ⊞ 13.4K · ◷

  • expires on Oct 4, 2026, 2:48 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions