Skip to content

[duplicate-code] Deduplicate create-agent-session parsing for current and deprecated config keys #53837

Description

@github-actions

🔍 Duplicate Code Detected: create-agent-session Legacy/New Parser Branches

Analysis of commit 4845f00caf4609afc9cd34cbb45ad4b8ae621a20 (current shallow snapshot; parent commit range was unavailable in the runner)

Assignee: @copilot

Summary

parseAgentSessionConfig contains two near-identical parsing branches for create-agent-session and deprecated create-agent-task. The duplication is large enough that future behavior changes can easily land in only one branch.

Duplication Details

Pattern: duplicated config-map parsing for new and deprecated keys

  • Severity: Medium
  • Occurrences: 2 near-identical branches, each ~28 lines
  • Locations:
    • pkg/workflow/create_agent_session.go (lines 20-47)
    • pkg/workflow/create_agent_session.go (lines 51-78)
  • Code Sample:
if configMap, ok := configData.(map[string]any); ok {
    if base, exists := configMap["base"]; exists {
        if baseStr, ok := base.(string); ok {
            agentSessionConfig.Base = baseStr
        }
    }

    targetRepoSlug, isInvalid := parseTargetRepoWithValidation(configMap)
    if isInvalid {
        return nil
    }
    agentSessionConfig.TargetRepoSlug = targetRepoSlug

    c.parseBaseSafeOutputConfig(configMap, &agentSessionConfig.BaseSafeOutputConfig, 1)
} else {
    agentSessionConfig.Max = defaultIntStr(1)
}

The deprecated-key branch differs mainly in the lookup key and warning log line, not in the parser behavior.

Impact Analysis

  • Maintainability: Any new field added to agent-session config must be threaded through two branches.
  • Bug Risk: Legacy and current keys can diverge subtly if only one branch is updated during future changes.
  • Code Bloat: The actual compatibility policy is hard to read because the parsing details are duplicated inline.

Refactoring Recommendations

  1. Extract a shared parseAgentSessionConfigMap helper

    • Extract common functionality to: pkg/workflow/create_agent_session.go
    • Estimated effort: 1-2 hours
    • Benefits: keeps the deprecation logic separate from the config parsing logic
  2. Keep key selection and warning emission in the caller only

    • Extract common functionality to: a thin wrapper that chooses the source key, logs the deprecation warning once, and delegates map parsing to the helper
    • Estimated effort: 1-2 hours
    • Benefits: avoids future field drift between the old and new config names

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken
Analysis Metadata
  • Analyzed Files: 1 directly inspected file for this pattern; repo-wide search across 1,249 non-test Go files in the snapshot
  • Detection Method: Serena activation succeeded, but Go LSP could not start because Go was unavailable in PATH; findings were verified with targeted source inspection and pattern search fallback
  • Commit: 4845f00caf4609afc9cd34cbb45ad4b8ae621a20
  • Analysis Date: 2026-08-18T00:00:00Z

Generated by 🔍 Duplicate Code Detector · gpt54 · 163.8 AIC · ⊞ 13.1K ·

  • expires on Aug 20, 2026, 2:02 PM UTC-08:00

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions