🔍 Duplicate Code Detected: Identical timeout tool parsers
Analysis of commit 3fd44f8
Assignee: @copilot
Summary
parseTimeoutTool and parseStartupTimeoutTool in pkg/workflow/tools_parser.go have byte-for-byte identical bodies (25 lines each). They differ only in their name and doc comment; the parsing logic for TemplatableInt32 is copy-pasted.
Duplication Details
Pattern: Identical any -> *TemplatableInt32 conversion
- Severity: Medium
- Occurrences: 2 (exact duplicate)
- Locations:
pkg/workflow/tools_parser.go (lines 591-616, parseTimeoutTool)
pkg/workflow/tools_parser.go (lines 620-645, parseStartupTimeoutTool)
- Code Sample:
func parseTimeoutTool(val any) *TemplatableInt32 {
switch v := val.(type) {
case int:
t := TemplatableInt32(strconv.Itoa(v))
return &t
case int64:
t := TemplatableInt32(strconv.FormatInt(v, 10))
return &t
// ... uint, uint64, float64, string(isExpression) cases ...
}
return nil
}
parseStartupTimeoutTool is identical except for the name.
Call sites (tools_parser.go:176 and :179) both already dispatch on the field key, so a single shared parser is a drop-in replacement.
Impact Analysis
- Maintainability: Any change to accepted timeout types/expression handling must be applied in two places; easy to let them drift.
- Bug Risk: A fix applied to one parser but not the other would silently produce inconsistent behavior between
timeout and startup-timeout.
- Code Bloat: ~25 redundant lines.
Refactoring Recommendations
- Collapse into one parser
- Delete
parseStartupTimeoutTool and point the startup-timeout branch at parseTimeoutTool (or rename it to a neutral parseTemplatableInt32Tool).
- Estimated effort: ~15 min, trivial.
- Benefits: single source of truth, −25 lines.
Implementation Checklist
Analysis Metadata
- Analyzed Files: pkg/ (1435 non-test .go files)
- Detection Method: Serena semantic code analysis + function-body fingerprinting
- Commit: 3fd44f8
- Analysis Date: 2026-10-06
Generated by 🔍 Duplicate Code Detector · pi · opus48 · 74.5 AIC · ⌖ 41.3 AIC · ⊞ 1.5K · ◷
🔍 Duplicate Code Detected: Identical timeout tool parsers
Analysis of commit 3fd44f8
Assignee:
@copilotSummary
parseTimeoutToolandparseStartupTimeoutToolinpkg/workflow/tools_parser.gohave byte-for-byte identical bodies (25 lines each). They differ only in their name and doc comment; the parsing logic forTemplatableInt32is copy-pasted.Duplication Details
Pattern: Identical
any -> *TemplatableInt32conversionpkg/workflow/tools_parser.go(lines 591-616,parseTimeoutTool)pkg/workflow/tools_parser.go(lines 620-645,parseStartupTimeoutTool)parseStartupTimeoutToolis identical except for the name.Call sites (
tools_parser.go:176and:179) both already dispatch on the field key, so a single shared parser is a drop-in replacement.Impact Analysis
timeoutandstartup-timeout.Refactoring Recommendations
parseStartupTimeoutTooland point thestartup-timeoutbranch atparseTimeoutTool(or rename it to a neutralparseTemplatableInt32Tool).Implementation Checklist
tools_parser.go:176,:179)make fmtandmake test-unitAnalysis Metadata