Skip to content

[duplicate-code] Duplicate Code Analysis Report #4075

Description

@github-actions

Analysis of commit ac8733a — "Refactor SendRequestWithServerID to use a single inbound response logging path"

Summary

Analysis of the codebase following the recent SendRequestWithServerID refactor (which resolved the duplication that motivated it) reveals 3 remaining significant duplication patterns across internal/guard/wasm.go, internal/server/guard_init.go, and internal/server/tool_registry.go.

Detected Patterns

  1. Marshal-for-debug-logging block — Severity: Medium — See [duplicate-code] Duplicate Code Pattern: Marshal-for-debug-logging block in guard/wasm.go and server/guard_init.go #4076
    Identical 5-line marshal + conditional log block repeated 3× across two files.

  2. Sys tool handler structural duplication — Severity: Medium — See [duplicate-code] Duplicate Code Pattern: Sys tool handler call-and-log skeleton in tool_registry.go #4077
    sysInitHandler and sysListHandler in registerSysTools() copy the same call → error-handle → marshal → log → return skeleton. Adding a third sys tool requires another copy-paste.

  3. Missing result sanitization in sysListHandler — Severity: High — See [duplicate-code] Duplicate Code Pattern: Missing result sanitization in sysListHandler (copy-paste divergence) #4078
    Direct consequence of Pattern 2: sysListHandler omits sanitize.SanitizeString when logging the JSON result, diverging from sysInitHandler and the backend tool handler and creating a potential secret-leak risk in log output.

Overall Impact

  • Total Duplicated Lines: ~35 lines across 3 patterns
  • Affected Files: internal/guard/wasm.go, internal/server/guard_init.go, internal/server/tool_registry.go
  • Maintainability Risk: Medium — patterns will silently diverge as sys tools are added
  • Refactoring Priority: Pattern 3 (sanitization gap) should be fixed immediately; Patterns 1 & 2 are medium-priority cleanup

Next Steps

  1. Fix the missing sanitization in sysListHandler (Pattern 3) — low-risk, one-line change
  2. Extract a logMarshaledForDebug helper to consolidate Pattern 1
  3. Introduce a shared helper for the sys-tool call-and-log skeleton (Pattern 2)

Analysis Metadata

  • Analyzed Files: internal/guard/wasm.go, internal/server/guard_init.go, internal/server/tool_registry.go (and broad survey of non-test Go sources)
  • Detection Method: Static code inspection — pattern search + manual comparison
  • Commit: ac8733aff67ad6e95c4fef045c8cac6fbcdb9b65
  • Analysis Date: 2026-04-18

Metadata

Metadata

Assignees

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