[sergo] Sergo Report: function-complexity-and-long-function-hot-spots — 2026-05-10 #31301
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-05-11T05:21:38.654Z.
|
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.
-
Executive Summary
Run 5 of Sergo (2026-05-10) ran a function-complexity scan across all 766 non-test
.gofiles inpkg/, enumerating every function declaration by line count. The scan identified 17 functions over 400 lines, of which two are clear refactor targets:(*Compiler).extractSafeOutputsConfig(637 lines, 45 repeated parse-and-assign blocks) andDownloadWorkflowLogs(508 lines + 26 positional parameters).Three GitHub issues were created — two concrete refactors and one tracking issue surveying the remaining 12 long functions with refactor-potential annotations. Self-assessed success score: 9/10.
Server-side LSP (Serena) was used to confirm body locations on the top two findings (
body_location: {start_line: 54, end_line: 690}and{38, 546}) and to enumerate callers of the second (find_referencing_symbolsreturned 1 production caller + 7 test callers, validating the options-struct case quantitatively).🛠️ Serena Tools Update
Tools Snapshot
Tool Capabilities Used Today
activate_project— activate the Go workspace (one-shot at start)get_symbols_overview— discover the qualified(*Compiler).extractSafeOutputsConfigform when the bare name returned[]find_symbol— confirm body locations ofextractSafeOutputsConfig(54–690) andDownloadWorkflowLogs(38–546)find_referencing_symbols— count callers ofDownloadWorkflowLogs(8 total, 1 prod + 7 test)LSP observation worth caching
find_symbolwith a bare receiver-method name likeextractSafeOutputsConfigreturns an empty list — the qualified form(*Compiler).extractSafeOutputsConfig(the Go pointer-receiver name path) is required.get_symbols_overviewis the easy way to discover that form. Saved tosergo-stats.jsonfor future runs.📊 Strategy Selection
Cached Reuse Component (50%)
Theme adapted: Maintainability/consistency analysis from Runs 1–4.
The common thread across all four runs is code-shape consistency: each run targeted a different axis (errors → naming → constructors → concurrency) but the underlying question is always "is this function/structure pulling its weight, and is it consistent with siblings?" Today's run extends that thread to function shape itself — length and parameter-list size.
New Exploration Component (50%)
Novel approach: A whole-
pkg/function-length enumeration. Past runs zoomed into specific patterns (panics, goroutines, type assertions); this is the first run to ask "sort all 3782 non-test functions by size and look at the head of the distribution." Implementation was a small awk script that emits<lines> <file>:<start> <name>for every^funcdeclaration, sorted descending. Top 50 inspected, top 17 (>400 lines) flagged.Combined Strategy Rationale
The cached half ensures the analysis stays in the proven territory of code-shape findings (where Sergo has scored 7–9). The new half changes the unit of analysis from "specific anti-pattern" to "distribution of function sizes" — this is naturally complementary because long functions are the substrate where most code-shape issues compound.
Hypothesis going in: we'll find 3–5 functions of >500 lines, at least one of which has a clear table-driven shape. Hypothesis confirmed: 5 functions over 500 lines, and
extractSafeOutputsConfigis a near-perfect table-driven candidate (45 repeated blocks).🔍 Analysis Execution
Codebase Context
pkg/: 766pkg/: 3,782pkg/: 181,907Findings Summary
DownloadWorkflowLogs)📋 Detailed Findings
Medium Priority — Refactor Targets (issued)
1.
(*Compiler).extractSafeOutputsConfig— 637 lines, 45 repeated parse-and-assign blockspkg/workflow/safe_outputs_config.go:54–690body_location: {start_line: 54, end_line: 690}xConfig := c.parseXConfig(outputMap); if xConfig != nil { config.Y = xConfig }(verifiedgrep -c 'c\.parse\w*Config(outputMap)' = 45){parse, assign}pairs2.
DownloadWorkflowLogs— 508 lines + 26 positional parameterspkg/cli/logs_orchestrator.go:38–546body_location: {start_line: 38, end_line: 546}NewLogsCommandatlogs_command.go:245) + 7 testcontext_cancellation_test.go:73:LogsDownloadOptionsstructLow Priority — Tracked
3. Survey of remaining 12 functions over 400 lines
extractRepoMemoryConfig(400, same shape as rejig docs #1),extractAllImportFields(490),GetExecutionStepstriplet (478/373/287, sister functions with shared shape)buildMaintenanceWorkflowYAML822,buildConclusionJob607,buildPreActivationJob480,generateSideRepoMaintenanceWorkflow428)Full top-50 function-length output
Side findings ruled out (saved as cache stats)
fmt.Errorfcalls inpkg/, only 1 documented exception uses%vwitherr(compiler_orchestrator_frontmatter.go:41with//nolint:errorlintand an explanatory comment).%wwrapping is consistent. NOT issue-worthy.panic()calls inpkg/non-test. All examined are legitimate (init-time embed-load,BUG:programmer-error guards, crypto/rand failure). NOT issue-worthy.os.Exitscan: 2 calls inpkg/, both inpkg/cli/upgrade_command.go— appropriate for CLI commands. NOT issue-worthy.These rule-outs are intentionally documented in
sergo-stats.jsonso future runs don't re-investigate.✅ Improvement Tasks Generated
Task 1: Refactor
extractSafeOutputsConfigto a table-driven handler registrySeverity: Medium · Effort: Medium · Issue: #aw_sg5fn1
Problem: 637-line function with 45 nearly-identical parse-and-assign blocks; new safe-output handlers must be added in this giant
ifblock, and a wrong-field assignment (e.g. assigning to.UploadAssetvs.UploadAssets) compiles silently.Validation:
go test ./pkg/workflow/...Task 2: Introduce
LogsDownloadOptionsstruct forDownloadWorkflowLogsSeverity: Medium · Effort: Small · Issue: #aw_sg5fn2
Problem: 26-parameter positional signature; 7 test callers each enumerate every argument including filler zeros; adding any flag requires editing every callsite.
Validation:
go test ./pkg/cli/...false/""/0defaults surviveTask 3: Track remaining 12 long functions and pick high-leverage extraction targets
Severity: Low · Effort: N/A (tracking) · Issue: #aw_sg5fn3
Recommendation: when convenient, knock off
extractRepoMemoryConfig(same fix as Task 1),extractAllImportFields(table-driven), and theGetExecutionStepstriplet (shared helper). Add a CI line-count gate to keep the list from growing.📈 Success Metrics
This Run
pkg/non-test sweep)Reasoning for Score
pkg/was measured; rule-outs (panics, error wrapping,os.Exit) were also documented to prevent re-investigation.extractRepoMemoryConfig) into a fourth concrete task; the 3-issue cap prevented that.Issue duplication check
Attempted
gh issue list --search ...forextractSafeOutputsConfig,DownloadWorkflowLogs, and thesergolabel — all calls returnedHTTP 403from the sandbox firewall ((localhost/redacted)). Duplication could not be programmatically verified. Past Sergo run topics (concurrency, constructors, type-safety, error handling) are clearly distinct from today's function-length theme, so a duplicate is unlikely. Issues do carry theexpires: 7dconfigured policy and are expected to auto-close if not actioned.📊 Historical Context
Strategy Performance
Scores are trending upward as the strategies move from "specific anti-pattern hunt" to "systematic enumeration with rule-outs" — both Run 4 and Run 5 took the form "inventory the entire population, then issue on the outliers" (goroutines for Run 4, function lengths for Run 5).
Cumulative Statistics
🎯 Recommendations
Immediate Actions
extractSafeOutputsConfig(highest leverage; same fix mechanically extends toextractRepoMemoryConfig)DownloadWorkflowLogs(smallest effort, biggest readability win)Long-term Improvements
main.DownloadWorkflowLogsat 26 is an outlier today; a soft cap would have caught it before it reached 26.🔄 Next Run Preview
Suggested Focus Areas
pkg/missing godoc commentsfor i := range ... { go func() { _ = i }() }patterns relying on old behaviour)interface{}vsanyconsistency sweepStrategy Evolution
The "enumerate the population, rule out the boring, issue on the outliers" pattern (Runs 4 + 5) is scoring well. Continue using it. Avoid the temptation to revisit panics/error-wrapping — those have been ruled out and the rule-outs are now cached. Prefer underexplored axes: API surface, loop-capture, type-erasure (
any).Generated by Sergo — The Serena Go Expert
Run ID: §25620196889
Strategy: function-complexity-and-long-function-hot-spots
Beta Was this translation helpful? Give feedback.
All reactions