[sergo] Sergo Report: Error Handling & Context Propagation - 2026-05-04 #30068
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #30276. |
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.
-
🔬 Sergo Report: Error Handling & Context Propagation
Date: 2026-05-04
Strategy:
error-handling-and-context-propagationSuccess Score: 7/10
Run ID: §25301644786
Executive Summary
This is the inaugural Sergo run on the gh-aw Go codebase (766 non-test Go files, ~180K LOC). With no prior strategy cache to draw from, the analysis focused on two foundational code quality dimensions: error handling patterns and code structure.
The codebase is overall well-structured with clear interface segregation (
pkg/workflow/agentic_engine.go), good error wrapping hygiene in most code paths, and intentional crash-fast strategies for embedded data initialization. The three most actionable findings are: (1) missingcontext.Contextpropagation through GitHub API call chains, (2) an explicitly developer-flagged architectural TODO for safe outputs decoupling, and (3) growing per-engine domain function sprawl.🛠️ Serena Tools Update
Tools Snapshot
Tool Capabilities Used Today
activate_projectget_symbols_overviewsearch_for_patternfind_symbol📊 Strategy Selection
Cached Reuse Component (50%)
No prior cache — this is the first run. For the "cached" slot, the most universally high-value Go analysis pattern was selected: error handling and context propagation. This is the #1 category of code quality issues in mature Go codebases.
pkg/production Go files (excluding_test.go)New Exploration Component (50%)
Novel Approach: Large-file structural complexity analysis using
get_symbols_overviewget_symbols_overviewon the 5 largest filespkg/workflow/— the core compilation packageCombined Strategy Rationale
The error-handling scan (breadth-first, all files) + large-file structural analysis (depth-first, top 5 files) provides complementary coverage: systematic pattern detection paired with deep architectural understanding of the most complex code.
🔍 Analysis Execution
Codebase Context
pkg/workflow/(compiler),pkg/cli/(CLI),pkg/parser/(YAML parsing),pkg/actionpins/rhysd/actionlint,securego/gosec/v2,modelcontextprotocol/go-sdk,anthropics/anthropic-sdk-goFindings Summary
📋 Detailed Findings
Medium Priority
Finding M1:
context.Background()used directly in GitHub API call chainsProduction code in
pkg/workflow/andpkg/cli/passescontext.Background()directly to functions that make GitHub API network calls, bypassing any parent context timeout or cancellation:pkg/workflow/action_reference.go:78,116—resolver.ResolveSHA(context.Background(), ...)pkg/workflow/action_sha_checker.go:122— same patternpkg/workflow/maintenance_workflow.go:68— same patternpkg/workflow/github_cli.go:131,153—RunGHContext(context.Background(), ...)pkg/cli/add_command.go:366—fetchAllRemoteDependencies(context.Background(), ...)Total production instances: 24 across
pkg/. These network calls can hang indefinitely if GitHub's API is unresponsive, and cannot be cancelled by parent CLI signal handlers.Finding M2: Safe outputs event trigger coupling — developer-flagged TODO
At
pkg/workflow/compiler_safe_outputs_steps.go:67-73, a developer explicitly marked an architectural concern:The safe outputs application step reconstructs target branch information from GitHub Actions event expressions (
github.base_ref || github.event.pull_request.base.ref || ...). This causes a known bug:issue_commentevents on PRs targeting non-default branches checkout the wrong base branch.Low Priority
View Low Priority Findings
Finding L1: Per-engine domain function sprawl in
domains.gopkg/workflow/domains.go(1113 lines) exports 16+ per-engine domain functions, many of which are one-line wrappers aroundGetAllowedDomainsForEngineWithModel. Adding a new AI engine requires adding 2+ mechanical boilerplate functions. The generic API already exists; the wrappers add surface area without value.Finding L2: Silent error discards in
compile_pipeline.gopkg/cli/compile_pipeline.go:402-403discardsfilepath.Glob()errors. Since the patterns are compile-time constants (*.lock.yml,*.invalid.yml), these errors are practically impossible but worth a brief comment.Finding L3: Error chain breaking is a design choice (documented)
The codebase uses
errors.New()(370+ instances) rather thanfmt.Errorf("%w")in many places. Based on comments inpkg/workflow/error_wrapping_test.go, this appears intentional — preventing internal error types from leaking to users. No action required.Finding L4: Panic usage is intentional
All
panic()calls in production code are ininit()functions loading embedded JSON or binary data. This is a correct crash-fast strategy for detecting compile/packaging errors. No action required.✅ Improvement Tasks Generated
Task 1: Propagate
context.Contextin action SHA resolution (Medium, Priority: 1)Issue Type: Context Propagation Anti-Pattern
Problem:
resolver.ResolveSHA()and related network operations are called withcontext.Background()throughout the action resolution code paths. These GitHub API calls have no timeout or cancellation support.Locations:
pkg/workflow/action_reference.go:78,116pkg/workflow/action_sha_checker.go:122pkg/workflow/maintenance_workflow.go:68pkg/workflow/github_cli.go:131,153pkg/cli/add_command.go:366Recommendation: Thread
ctx context.Contextthrough the call chains leading to these network operations. Verify existingcontext.WithTimeout(context.Background(), ...)patterns are also updated to use the parent context instead.Estimated Effort: Medium
Task 2: Decouple safe outputs from event trigger context (Medium, Priority: 2)
Issue Type: Architectural Debt (Developer-Flagged TODO)
Problem:
pkg/workflow/compiler_safe_outputs_steps.go:67-73reconstructs target branch from event context rather than having it encoded in the safe output payload, causing a known bug forissue_commentevents on non-default-branch PRs.Recommendation: Enrich the safe output metadata at generation time with
target_branchandtarget_repo, eliminating the event-context fallback expression chain at application time.Estimated Effort: Large
Task 3: Reduce per-engine boilerplate in
domains.go(Low, Priority: 3)Issue Type: Code Duplication / API Sprawl
Problem:
pkg/workflow/domains.gohas 16+ thin per-engine wrapper functions. Each new engine addition requires mechanical boilerplate; the underlying generic API already handles all cases.Recommendation: Remove per-engine
GetXxxAllowedDomainsWithToolsAndRuntimeswrappers and have callers useGetAllowedDomainsForEngineWithModeldirectly. ConsolidateGetXxxDefaultDomainsinto a singleGetDefaultDomainsForEngine(engine, model)function.Estimated Effort: Small
📈 Success Metrics
This Run
Score Reasoning
Cumulative Statistics (First Run)
error-handling-and-context-propagation🎯 Recommendations
Immediate Actions
context.Contextthrough action SHA resolution call chains. Improves production reliability for GitHub API calls with no functional behavior change.@dsyme's TODO. Fixes a known edge-case bug and improves testability of safe output application.Long-term Improvements
context.Contextparameter audit to CI to prevent newcontext.Background()from being introduced in production network call paths.agentic_engine.gointerface segregation pattern is excellent and should be used as a model for other packages needing capability detection.🔄 Next Run Preview
Suggested Focus Areas
x.(Type)(without the comma-ok pattern) that could panic at runtimeBaseEngineproperly implements all methods required byCodingAgentEngineand check for any engines that override methods incorrectlysourcegraph/conc— analyze goroutine patterns for potential data racesStrategy Evolution
References:
Beta Was this translation helpful? Give feedback.
All reactions