[sergo] Sergo Report: Code Duplication & Error Handling in mcp_scripts_parser - 2026-04-27 #28799
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #28980. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Date: 2026-04-27
Strategy: Code Duplication & Error Handling (first run — no cache)
Success Score: 7/10
Run ID: §25018127451
Executive Summary
This is the first Sergo run on this repository. The codebase is a substantial Go project (727 non-test
.gofiles, ~168K LOC acrosspkg/) implementing a GitHub Actions workflow compiler and agentic execution framework. Thepkg/workflowpackage is the largest and most complex, containing the core compiler, engine definitions, MCP configuration, and runtime tooling.Analysis focused on
pkg/workflow/mcp_scripts_parser.gousing Serena's semantic symbol search and pattern matching. Three actionable findings were identified: a significant code duplication (tool-config parsing logic duplicated across two functions), a silent error suppression inconsistency (timeout string parsing discards the parse error), and a dead function parameter left in the public-internal API. Three GitHub issues were created.Serena's LSP server disconnected mid-session; analysis was completed using native Grep/Read tools with no reduction in finding quality.
Serena Tools Update
Tools Snapshot
Tool Capabilities Used Today
activate_projectget_symbols_overviewengine.go,compiler.go,mcp_scripts_parser.go,tools_parser.go)find_symbolparseMCPScriptsMap,parseMCPScriptToolConfig,parseTimeoutTool,SafeUint64ToInt,IsMCPScriptsEnabledsearch_for_pattern_ =,fmt.Sscanf,panic(,TODO/FIXME, context usagelist_dirpkg/workflow,pkg/,cmd/structureStrategy Selection
This is Run #1 (No Cache Available)
Since no prior strategy cache exists, 100% of this run used a new exploration approach. The baseline will seed the 50% cached / 50% new split for future runs.
New Exploration: Code Quality & Error Handling Audit
Approach: Start from well-tested parser files that handle user-supplied config (high blast radius), cross-reference against codebase patterns to identify inconsistencies.
Tools employed: Symbol overview → pattern search (
_ =,fmt.Sscanf,panic() → symbol body inspection → cross-reference via Grep.Hypothesis: Configuration parsing code tends to accumulate debt: silent error handling, copy-paste duplication when features are added, and API parameters that outlive their purpose. The
mcp_scripts_parser.gofile, being relatively new and containing two similar functions, was a good candidate.Target areas:
pkg/workflow/mcp_scripts_parser.go,pkg/workflow/tools_parser.go,pkg/typeutil/convert.goAnalysis Execution
Codebase Context
pkg/domains.go(1011 LOC),compiler_jobs.go(995 LOC),compiler_yaml_main_job.go(917 LOC)pkg/workflow/mcp_scripts_parser.go(366 LOC),pkg/workflow/tools_parser.go(543 LOC)anthropic-sdk-go,rhysd/actionlint,securego/gosec,modelcontextprotocol/go-sdkFindings Summary
Detailed Findings
Medium Priority: Code Duplication in
mcp_scripts_parser.goLocation:
pkg/workflow/mcp_scripts_parser.go:72–191and259–357Both
parseMCPScriptsMapand the inner loop of(*Compiler).mergeMCPScriptsparse amap[string]anyinto a*MCPScriptToolConfig. The logic — description, inputs (with nested param fields), script/run/py/go strings, env map, and a 4-case timeout type switch — is copy-pasted verbatim between the two functions.Evidence of independent patching: the
uint64overflow safety fix references alert#414inparseMCPScriptsMapand alert#413inmergeMCPScripts, suggesting the two sites were patched in separate PRs.Impact: Medium — any future
MCPScriptToolConfigfield addition requires two edits and two test updates. Divergence risk increases over time.Recommendation: Extract
parseMCPScriptToolConfig(toolName string, toolMap map[string]any) *MCPScriptToolConfigand call it from both sites.Medium Priority: Silent Timeout Parse Error in
mcp_scripts_parser.goLocation:
pkg/workflow/mcp_scripts_parser.go:184and355Both the count and the error from
fmt.Sscanfare discarded. A string value like"5m","two minutes", or"abc"will silently leavetoolConfig.Timeoutat its 60-second default.This is the only place in
pkg/wherefmt.Sscanferrors are suppressed — all 14 other call sites check the error. The parallel pattern intime_delta.go:432logs a warning on failure.Impact: Medium — user configuration mistakes in
mcp-scriptstimeout fields produce no diagnostic output.Recommendation: Replace with
strconv.Atoiand log a warning viamcpScriptsLogwhen parsing fails.Low Priority: Dead Parameter on IsMCPScriptsEnabled
Location:
pkg/workflow/mcp_scripts_parser.go:56The function body ignores
workflowDataentirely. The "backward compatibility" comment is misleading — this is internal-only code with no external API contract. Thirteen production call sites are forced to passworkflowDataunnecessarily.Recommendation: Remove the parameter (or inline
IsMCPScriptsEnabledentirely asHasMCPScripts).Improvement Tasks Generated
Task 1: Extract
parseMCPScriptToolConfighelperIssue Type: Code Duplication
Problem: ~90 lines of tool-config parsing logic duplicated in
parseMCPScriptsMapandmergeMCPScripts.Locations:
pkg/workflow/mcp_scripts_parser.go:83–186(inparseMCPScriptsMap)pkg/workflow/mcp_scripts_parser.go:259–357(inmergeMCPScripts)Severity: Medium | Effort: Small
Before (duplicated in two places):
After:
Task 2: Fix silent error suppression in timeout string parsing
Issue Type: Error Handling
Problem:
_, _ = fmt.Sscanf(t, "%d", &toolConfig.Timeout)hides invalid timeout values.Location:
pkg/workflow/mcp_scripts_parser.go:184,355Severity: Medium | Effort: Small
Before:
After:
Task 3: Remove dead
workflowDataparameter fromIsMCPScriptsEnabledIssue Type: API Hygiene / Dead Code
Problem: Unused parameter on a function called from 13 internal sites.
Location:
pkg/workflow/mcp_scripts_parser.go:56+ 13 call sitesSeverity: Low | Effort: Small
Success Metrics
This Run
Reasoning for Score
Cumulative Statistics (Run 1/1)
Recommendations
Immediate Actions
parseMCPScriptToolConfig— eliminates dual-maintenance of MCP script tool parsing; prerequisite for Task 2 to only need one fix location.fmt.Sscanfsuppression — adds user-visible diagnostics for misconfiguredmcp-scriptstimeouts.workflowDataparameter — reduces API noise across 13 call sites.Long-term Improvements
mcp_scripts_parser.goandtools_parser.gofiles follow similarmap[string]any → structparsing patterns. A future exploration pass could audittools_parser.go'sparseWebFetchTool/parseWebSearchTool/parseEditToolfunctions, all of which ignore theirval anyparameter — potentially silently discarding user config.pkg/workflow/compiler_jobs.go(995 LOC) andpkg/workflow/compiler_yaml_main_job.go(917 LOC) are large files that may benefit from a complexity/function-length analysis in a future run.Next Run Preview
Suggested Focus Areas
domains.go(1011 LOC),compiler_jobs.go(995 LOC) — function-length and cyclomatic complexity analysispkg/cli/audit.go,pkg/parser/remote_fetch.go— both >900 LOC and not yet analyzedparseWebFetchTool/parseWebSearchTool/parseEditTool: These ignore theirvalparameter; verify no config is silently droppedStrategy Evolution
pkg/cli/orpkg/parser/) + 50% new (complexity / large-file analysis using LOC metrics as the entry point).Generated by Sergo — The Serena Go Expert
Run ID: §25018127451
Strategy: code-duplication-and-error-handling (first run)
Beta Was this translation helpful? Give feedback.
All reactions