[sergo] Sergo Report: switch-statement-complexity-plus-exported-api-usage-audit — 2026-05-12 #31634
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #31867. |
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 7 ranked all 195 non-test
.gofiles inpkg/bycasecount and drilled into the top-5 hotspots. The headline finding: eight parallel dispatch tables keyed by the sameSafeOutputshandler-type axis — a maintenance hazard explicitly documented in code (safe_outputs_state.go:16-21) but where the source comment undercounts the actual sprawl by half (says 4, actual is 8). Two adjacent permission-scope switches inpermissions.goandfrontmatter_parsing.goexhibit the same shotgun-surgery anti-pattern on a smaller scale, including a 49-case identity switch where each branch literally returnsPermissionScope(key).Three issues were filed (#aw_sg7a1, #aw_sg7a2, #aw_sg7a3). All findings are independent of Run 5/6 trackers and have not been raised before. Self-assessed success score: 9/10.
Strategy Selection
Cached Reuse Component (50%)
Adapted from: Run 5
function-complexity-and-long-function-hot-spots(9/10).switch/casestatement complexity — a complementary measure (a 200-line function can be trivial; a 60-case switch is always dispatch).^\s*case .*:lines per file inpkg/, drill into top-5.New Exploration Component (50%)
Approach: Exported-symbol usage audit via Serena
find_referencing_symbols(and Grep cross-check). Scanned exportedpkg/workflow/*functions to find dead-or-near-dead API surface.find_symbol --name_path_pattern=hasSafeOutputTyperan for 71 seconds without--include_kinds— fell back to Grep for plain-name lookups. New cache entry recorded.hasSafeOutputType, which led to the dispatch-table cluster.Why this combination worked
The complexity scan supplies where (frontmatter_parsing.go 58 cases, permissions.go 49, imports.go 45). The exported-API scan supplied what for — discovering that
hasSafeOutputTypeis one of multiple sibling functions all carrying the same dispatch logic. Cross-product revealed the 8-table cluster.Serena Tools Update
activate_project,find_symbol, plus Grep / Read as cross-check.Performance note logged to cache
find_symbolwith--name_path_patternand no--include_kindsfilter took 71 seconds for a simple symbol lookup. For plain-name queries, Grep returned the same answer in under 1s. Cache updated to recommend Grep first and reservefind_symbolfor cases needing kind filtering or precise body locations.Analysis Execution
Codebase context
pkg/: 772casestatements: 195caselines inpkg/: 1,390Top-5 case-count hotspots
casecountpkg/workflow/frontmatter_parsing.goparsePermissionsConfig(40-case) +parseRuntimesConfigpkg/workflow/permissions.goconvertStringToPermissionScope(49-case identity switch)pkg/workflow/imports.gohasSafeOutputType(45-case)pkg/workflow/safe_outputs_permissions.goSafeOutputsConfigFromKeys(45-case)pkg/workflow/mcp_config_custom.goFindings Summary
Detailed Findings
Critical / High (filed as issues)
#aw_sg7a1 — 8 parallel dispatch tables keyed by safe-output type
The inventory:
safeOutputFieldMapping(map literal)safe_outputs_state.go:27-71hasAnySafeOutputEnabledsafe_outputs_state.go:79+hasNonBuiltinSafeOutputsEnabledsafe_outputs_state.gohasSafeOutputTypeimports.go:321-419SafeOutputsConfigFromKeyssafe_outputs_permissions.go:313+ComputePermissionsForSafeOutputssafe_outputs_permissions.go:79-307mergeSafeOutputConfigimports.go:423-670if result.X == nil && imported.X != nilextractSafeOutputsConfigcompiler.goExisting safeguard:
safe_outputs_state.go:16-21lists 4 locations — half the actual count. Recommended fix: one descriptor table consumed by all eight sites via reflection. See full issue text on #aw_sg7a1.#aw_sg7a2 —
convertStringToPermissionScope49-case identity switchEvery case returns
PermissionScope(key)because constants are defined asPermissionActions = "actions", etc. Collapsible to a 5-line validated cast against the already-existingGetAllPermissionScopes()/GetAllGitHubAppOnlyScopes()inventory. ~110 lines → ~12.#aw_sg7a3 —
parsePermissionsConfig40-case scope→struct-field switchDuplicates the permission inventory for the fourth time (const block, 2× Get* slices,
convertStringToPermissionScope, and now this). Recommend driving from amap[PermissionScope]func(*PermissionsConfig, string)setter table, or convertingPermissionsConfigitself tomap[PermissionScope]string.Medium-priority companion observations (not filed)
pkg/workflow/mcp_config_custom.go(34 cases) — large but not surveyed this run; carry to Run 8.pkg/cli/audit_agentic_analysis.go(32 cases) — same — carry forward.pkg/workflow/imports.go:184MergeSafeOutputsmediates betweenmergeSafeOutputConfig(Weekly Research Report: AI Workflow Automation Landscape and Market Opportunities - August 2025 #7) andextractSafeOutputsConfig(Add workflow: githubnext/agentics/weekly-research #8). After #aw_sg7a1 it should collapse to a small wrapper.pkg/workflow/safe_outputs_state.go:16-21comment must be updated whichever way #aw_sg7a1 lands (or be deleted if the descriptor-table fix removes the need entirely).Improvement Tasks Generated
Task 1 — Descriptor-table refactor of SafeOutputs dispatch (
#aw_sg7a1)safe_outputs_*_test.gosuite;TestHasSafeOutputTypeNewKeysbecomes a descriptor-table parity checkTask 2 — Collapse
convertStringToPermissionScopeidentity switch (#aw_sg7a2)GetAllPermissionScopes() ∪ GetAllGitHubAppOnlyScopes()Task 3 — Table-drive
parsePermissionsConfig(#aw_sg7a3)Success Metrics (this run)
Reasoning for score
Historical Context
Strategy performance trend
Cumulative
Recommendations
Immediate
validPermissionScopesmap that #aw_sg7a3 can reuse.Long-term
A
go:generatestep that emits all eight dispatch sites (or analogous ones for permissions) from one source-of-truth table would prevent recurrence. Consider gating CI on a parity check that fails if the table and any individual function drift.Next Run Preview
Suggested focus areas
mcp_config_custom.go(34 cases),audit_agentic_analysis.go(32),tool_description_enhancer.go(30),stop_after.go(23)pkg/parserandpkg/stringutil(small leaf packages, manageable scope)Strategy evolution
Complexity-axis scans (line count → param count → nesting depth → switch cases) have anchored Runs 5–7 with consistent 9/10 scores. Suggest one more complexity sweep (method density) before pivoting to a new theme like inter-package coupling.
References
extractSafeOutputsConfighas 45 near-identical parse-and-assign blocks (table-driven candidate) #31298 (extractSafeOutputsConfig refactor — site Add workflow: githubnext/agentics/weekly-research #8 in the dispatch cluster), Tracking: 14 production functions inpkg/are >400 lines (function-length hot-spots) #31300 (long-function tracker)gh issue listreturns HTTP 403 on/meta— duplicate detection via gh search was unavailable this run; relied on Sergo cache (no prior issue covers these findings) and safe-outputs creation.Beta Was this translation helpful? Give feedback.
All reactions