[sergo] Sergo Report: Context-Propagation Revisit + Dead-Code Audit - 2026-03-13 #20870
Closed
Replies: 1 comment
-
|
This discussion was automatically closed because it expired on 2026-03-14T22:29:25.657Z.
|
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-03-13
Strategy: context-propagation-revisit-plus-dead-code-audit
Success Score: 7/10
Run ID: §23072627078
Executive Summary
Today's run (run 20) combined a revisit of the long-standing context-propagation/sleep audit (50% cached) with a novel dead-code sweep of date-time parsing utilities (50% new). The context-propagation component confirmed two previously reported unfixed issues:
getLatestWorkflowRunWithRetrystill uses baretime.Sleepwithout context cancellation, anddispatch.go'sgetRepoDefaultBranchstill lacks acontext.Contextparameter. The dead-code audit uncovered a new issue intime_delta.go'snormalizeDateTimeString: asmartFormatsslice of 12 format strings containing ordinal suffixes that can never match their input, because ordinals were stripped two lines earlier.Two previously reported issues were confirmed fixed since the last run:
gateway_logs.goscanner buffer calls (runs 13–19) andmcp_inspect_mcp.gocontext propagation (run 8) are now correctly handled. The codebase continues to show improvement, though several long-standing issues remain open.🛠️ Serena Tools Update
Tools Snapshot
Tool Capabilities Used Today
activate_project— activated gh-aw Go workspacelist_dir— exploredpkg/package structureget_symbols_overview— overview oftool_graph.go,compile_stats.go,audit_report_analysis.go,log_aggregation.gofind_referencing_symbols— traced call graph forgenerateExampleFromSchema,generateExampleJSONForPathsearch_for_pattern— pattern-matching for type assertions and scanner usage📊 Strategy Selection
Cached Reuse Component (50%)
Previous Strategy Adapted:
context-sleep-audit-plus-polling-infra(run 9, 2026-02-28, score 8)getLatestWorkflowRunWithRetry's uncancellabletime.Sleep, and run 19 (yesterday) identifieddispatch.go'sgetRepoDefaultBranch. Confirming these are still unfixed tracks technical debt accumulation.dispatch.gofollow-up from run 19, and verified whether any newly modified files introduced new context-free HTTP/subprocess calls.New Exploration Component (50%)
Novel Approach: Dead-code audit of string/time utility functions using mismatched ordinal format strings.
pkg/workflow/time_delta.go,pkg/parser/schema_suggestions.goCombined Strategy Rationale
Context-propagation audits have consistently delivered HIGH-severity findings, making them reliable for the cached component. Pairing this with dead-code audits of string-manipulation utilities provides breadth coverage of a different class of bug (logical errors vs. resource management), while also scanning recently introduced utility code that hasn't been analyzed in previous runs.
🔍 Analysis Execution
Codebase Context
pkg/cli,pkg/workflow,pkg/parserrun_workflow_tracking.go,dispatch.go,time_delta.go,expression_validation.go,secret_extraction.go,gateway_logs.go,mcp_inspect_mcp.go,tool_graph.go,compile_stats.goConfirmed Fixed Issues
gateway_logs.golines 336 and 777: both missingscanner.Buffer(buf, maxScannerBufferSize)calls — now FIXED (all 4 scanner instances confirmed with Buffer call)mcp_inspect_mcp.go:context.Background()replaced withcontext.WithTimeout(context.Background(), 30*time.Second)— now FIXEDFindings Summary
📋 Detailed Findings
High Priority Issues
[H1]
getLatestWorkflowRunWithRetry: Uncancellable retry sleep —run_workflow_tracking.go:73The function retries up to 6 times with exponential backoff (2s–10s intervals), but
time.Sleep(delay)at line 73 cannot be interrupted. The caller has no way to propagate acontext.Contextdown, so pressing Ctrl+C during the wait phase leaves the user blocked until the current sleep interval expires. The codebase already hasPollWithSignalHandlinginsignal_aware_poll.godesigned for exactly this use case.This has been reported and unfixed since run 9 (2026-02-28).
Medium Priority Issues
[M1]
normalizeDateTimeString:smartFormatsare dead code —time_delta.go:271-283(New finding)normalizeDateTimeStringstrips ordinal suffixes from its input at line 244:Then at lines 271–283, a
smartFormatsslice is constructed and tried against the already de-ordinalizeddateTimeStr:In Go's
time.Parse,"January 2nd 2006"requires the literal text"nd"after the day digit. SincedateTimeStrwas de-ordinalized two lines earlier, these formats will never match. The 12-formatsmartFormatsslice is entirely dead code.Additionally, the standard
formatslist (lines 192–238) already covers these patterns after ordinal removal (e.g.,"2 January 2006"at line 222 matches "1 June 2025" after stripping "1st June 2025"). ThesmartFormatsblock is therefore both dead and redundant.The error message at line 292 claims support for "1st June 2025" — this claim is true but succeeds via the standard formats, not
smartFormats. A maintainer reading this code would incorrectly assumesmartFormatsprovides ordinal parsing coverage.[M2]
regexp.MustCompilein function bodies and loops —expression_validation.go:288,400+secret_extraction.go:50,56(Unfixed since run 14)Three functions compile fixed regular expressions on every invocation:
expression_validation.go:288—orPattern := regexp.MustCompile(...)insidevalidateSingleExpression, which is called recursively (line 295 calls itself). Each recursive call recompiles.expression_validation.go:400—regexp.MustCompile(^\d+-\d+$)inside a for loop, recompiled on every iteration.secret_extraction.go:50,56— Two regexps compiled insideExtractSecretsFromValue, called for every secret-containing expression.All three should be package-level
vardeclarations compiled once at startup.Low Priority / Notes
time_delta.gosmartFormats secondary inconsistency: Line 260–266 triesnormalizedStr(double-space collapsed), but line 286 triesdateTimeStr(pre-normalization). Should usenormalizedStrfor consistency with the preceding block.tool_graph.go:124ambiguous separator: Transition keys use"->"as separator (fmt.Sprintf("%s->%s", from, to)), butstrings.Split(key, "->")would producelen > 2if tool names ever contain"->". In practice, tool names use underscores, so no current impact. LOW.schema_suggestions.go:377generateExampleFromSchemarecursion depth: No depth limit unlike the siblingcollectSchemaPropertyPaths(which hasschemaTraversalMaxDepth = 15). In practice bounded by the internal schema depth. LOW.Stable Unfixed Issues (tracked, not repeated):
dispatch.go:93—getRepoDefaultBranchno context (run 19)GetSupportedEngines/GetAllEngines/GetEngineByPrefixnon-deterministic map iteration (run 2+)DependencyGraphno mutex onnodes/reverseImports(run 11)pr_command.gotransferPR os.Chdir without CWD restore (run 16)deps_outdated.go:161new http.Client per call in sequential loop (run 18)mcp_registry.go:95,112io.ReadAllwithout size limit (run 17)deps_security.gopagination missing +io.ReadAllwithout limit (run 8)stringutil.Truncatebyte-level slicing (run 18)git_helpers.gorunGitWithSpinnerno context (run 15)✅ Improvement Tasks Generated
Task 1: Add context cancellation to
getLatestWorkflowRunWithRetryIssue Type: Context Propagation / Polling
Problem:
getLatestWorkflowRunWithRetryinrun_workflow_tracking.go:73usestime.Sleep(delay)for retry backoff. This call cannot be interrupted by context cancellation, meaning Ctrl+C during the wait phase leaves the user blocked for up to 10 seconds. The codebase hasPollWithSignalHandlinginsignal_aware_poll.godesigned for cancellable polling.Location(s):
pkg/cli/run_workflow_tracking.go:29— function signature (noctx context.Contextparameter)pkg/cli/run_workflow_tracking.go:73—time.Sleep(delay)callpkg/cli/run_workflow_execution.go— caller(s) ofgetLatestWorkflowRunWithRetryImpact:
PollWithSignalHandlingpattern not being used where it should beRecommendation:
Add
ctx context.Contextas the first parameter togetLatestWorkflowRunWithRetry. Replacetime.Sleep(delay)with a context-aware sleep usingselect:Or refactor to use
PollWithSignalHandlingif the retry logic aligns with its interface.Validation:
Estimated Effort: Small
Task 2: Fix dead
smartFormatsinnormalizeDateTimeStringIssue Type: Dead Code / Logic Bug
Problem:
normalizeDateTimeStringintime_delta.gostrips ordinal suffixes from its input at line 244, then at lines 271–284 constructs asmartFormatsslice of 12 format strings that all contain ordinal suffixes ("2nd","nd", etc.). Since the input no longer contains ordinals at that point, these format strings can never produce a successful parse. The block is dead code.Location(s):
pkg/workflow/time_delta.go:244— ordinal strippingpkg/workflow/time_delta.go:271-290—smartFormatsblock (dead code)Impact:
Recommendation:
Remove the
smartFormatsblock entirely (lines 271–290). The standardformatsslice already handles these patterns after ordinal removal (e.g.,"2 January 2006"matches "1 June 2025" after stripping "1st June 2025"). Update the comment at line 269 to clarify that ordinal dates are handled by stripping (line 244) followed by standard formats.Validation:
Estimated Effort: Small
Task 3: Move function-body
regexp.MustCompileto package-level variablesIssue Type: Performance / Code Quality
Problem:
Three functions compile fixed regular expressions on every invocation instead of declaring them as package-level variables:
validateSingleExpression(expression_validation.go:288): compilesorPatternon each call, AND the function is recursive — O(n) compilations per expression treeextractRuntimeImportPathsloop (expression_validation.go:400):regexp.MustCompileinside a for loop — one compilation per loop iterationExtractSecretsFromValue(secret_extraction.go:50,56): two regexps compiled on each call to this per-expression utilityLocation(s):
pkg/workflow/expression_validation.go:288—orPattern := regexp.MustCompile(...)pkg/workflow/expression_validation.go:400—regexp.MustCompile(...)inside for looppkg/workflow/secret_extraction.go:50—exprPattern := regexp.MustCompile(...)pkg/workflow/secret_extraction.go:56—secretPattern := regexp.MustCompile(...)Impact:
validateSingleExpressionwhich is called recursivelyRecommendation:
Move all four regexps to the package-level
varblock (which already exists inexpression_validation.goat lines 64–80):Validation:
Estimated Effort: Small
📈 Success Metrics
This Run
Reasoning for Score
📊 Historical Context
Confirmed Fixed Issues (Updated)
gateway_logs.goscanner.Buffer lines 336+777mcp_inspect_mcp.gocontext.Background()copilot_agent*.goregexp moved to package-levelCumulative Statistics
🎯 Recommendations
Immediate Actions
getLatestWorkflowRunWithRetry— add context parameter and replacetime.Sleepwith context-aware select. Small effort, big UX improvement (run 9, still open).smartFormatsdead code block fromtime_delta.go— add clarifying comment. 5-minute fix.regexp.MustCompilecalls inexpression_validation.goandsecret_extraction.goto package-level vars. Small effort, measurable performance benefit.Long-term Improvements
The
DependencyGraphrace condition (nodes/reverseImportsmaps accessed from multiple goroutines without mutex, reported run 11) andGetSupportedEngines/GetAllEnginesnon-deterministic map iteration (reported run 2, still unfixed after 11 reports) are the two longest-running issues in the backlog. Both have clear, simple fixes and high impact on reliability.🔄 Next Run Preview
Suggested Focus Areas
pkg/cli/deps_outdated.go: Thehttp.Clientper-call-in-loop pattern (run 18) creates N TCP connections for N Go module dependencies — investigate whethersync.WaitGroup-based parallel fetching with a shared client would be appropriate.import_field_extractor.go: Six silent JSON parse failures (run 16) — check if these have been addressed.pr_command.go:634:os.Chdirwithout restoration (run 16) — still unfixed for 4 runs.Strategy Evolution
The dead-code audit proved useful for finding logic bugs in utility functions. Next run could extend this to other time-related or string-parsing utilities in
pkg/workflow/to look for similar ordering/sequencing issues (processing applied in wrong order, conditions that prevent fallback logic from ever firing, etc.).Generated by Sergo - The Serena Go Expert
Run ID: §23072627078
Strategy: context-propagation-revisit-plus-dead-code-audit
Beta Was this translation helpful? Give feedback.
All reactions