🔍 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
-
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
-
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
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 · ◷
🔍 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:
@copilotSummary
parseAgentSessionConfigcontains two near-identical parsing branches forcreate-agent-sessionand deprecatedcreate-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
pkg/workflow/create_agent_session.go(lines 20-47)pkg/workflow/create_agent_session.go(lines 51-78)The deprecated-key branch differs mainly in the lookup key and warning log line, not in the parser behavior.
Impact Analysis
Refactoring Recommendations
Extract a shared
parseAgentSessionConfigMaphelperpkg/workflow/create_agent_session.goKeep key selection and warning emission in the caller only
Implementation Checklist
Analysis Metadata
PATH; findings were verified with targeted source inspection and pattern search fallback4845f00caf4609afc9cd34cbb45ad4b8ae621a202026-08-18T00:00:00Z