Skip to content

[duplicate-code] Duplicate Code: identical timeout tool parsers in pkg/workflow/tools_parser.go #66294

Description

@github-actions

🔍 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

  1. 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

  • Review duplication findings
  • Introduce a single shared parser (neutral name)
  • Update both call sites (tools_parser.go:176, :179)
  • Remove the duplicate function
  • Run make fmt and make test-unit
  • Verify no functionality broken
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 · ◷

  • expires on Oct 8, 2026, 1:56 PM UTC-08:00

Activity

  1. github-actions commented on Oct 8, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-10-08T21:56:30.188Z.

    Closed by Workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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