[sergo] Sergo Report: HTTP Context Chain + Vestigial init() - 2026-04-06 #24947
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #25151. |
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
Today's Sergo run combined an extension of the HTTP context propagation analysis (cached from the 2026-04-05 sentinel-extension run) with a new exploration of vestigial
init()functions inpkg/workflow. The HTTP analysis grew from 2 known locations to 4 confirmed locations where HTTP requests are issued without a parentcontext.Context, preventing cancellation by the CLI's command lifecycle. The new exploration found 3 no-opinit()functions that do nothing but log a message — dead code left from a prior refactor that removed embedded scripts.The codebase continues to show consistent patterns: HTTP utility functions (deps check, registry search, download helpers) were all authored without context parameters, making them resistant to cooperative cancellation. Similarly, the
pkg/workflowpackage has an inconsistency between files that load embedded JSON eagerly ininit()(domains, permissions, toolsets) and files that load lazily viasync.Once(action_pins, schema_validation, docker_validation). Three tasks are proposed to address these findings.🛠️ Serena Tools Update
Tools Snapshot
Tool Capabilities Used Today
activate_project— project initializationlist_dir— codebase structure explorationsearch_for_pattern(via bash grep) — HTTP call site detection, init() scanningfind_symbol/get_symbols_overview— function signature and context verification📊 Strategy Selection
Cached Reuse Component (50%)
Previous Strategy Adapted:
sentinel-extension-and-context-http(2026-04-05, score 8/10)mcp_registry.goanddeps_security.goas usinghttp.NewRequestwithout context. The run scored 8/10 and the notes flagged that the analysis was incomplete — "sentinel-extension" was the primary finding and HTTP context was a secondary note. Worth extending.client.Get()calls (not justhttp.NewRequest), and traced the full call chain from CLI command entry points down to the HTTP calls to confirm no context is available anywhere in the chain.New Exploration Component (50%)
Novel Approach: Vestigial
init()function auditjs.go), someinit()functions may have been left in place with only a log call as their body.grepfor^func init()acrosspkg/, then reading each bodypkg/workflow/*.go— 7init()functions found and auditedCombined Strategy Rationale
The HTTP-context and init()-audit themes are orthogonal but both focused on startup efficiency and operational correctness: one prevents silent HTTP request leaks on command cancellation, the other removes startup log noise and reveals an inconsistent initialization pattern. Together they give good breadth across the CLI and workflow packages.
🔍 Analysis Execution
Codebase Context
pkg/cli(HTTP pattern scan),pkg/workflow(init() audit)init()functions,sync.OnceusageFindings Summary
📋 Detailed Findings
High Priority: HTTP Requests Without Context Propagation
Four functions in
pkg/cliissue HTTP requests usinghttp.NewRequestorclient.Getwithout acontext.Contextparameter. None of their callers pass a context either — the missing context propagates all the way from the CLI command handler.pkg/cli/mcp_registry.gocreateRegistryRequesthttp.NewRequest(method, url, nil)pkg/cli/deps_security.goquerySecurityAdvisorieshttp.NewRequest(http.MethodGet, url, nil)pkg/cli/deps_outdated.gogetLatestVersionclient.Get(url)pkg/cli/agent_download.godownloadAgentFileFromGitHubclient.Get(rawURL)The callers —
SearchServers,CheckSecurityAdvisories,CheckOutdatedDependencies, anddownloadAgentFileFromGitHub— also have noctx context.Contextparameter. If the user presses Ctrl-C during adepscheck ormcp add, the HTTP request will continue until the server responds or the client-levelTimeoutfires (typically 5–30 seconds). The request cannot be cancelled cooperatively.Note:
mcp_inspect_mcp_scripts_server.go:52usesclient.Getinside a polling health-check loop with its own deadline mechanism — this is acceptable and excluded from the task.Medium Priority: Vestigial No-Op
init()FunctionsThree
init()functions inpkg/workflowcontain only a singlelog.Printcall and perform no initialization work:The
js.goandscripts.goinits are clear remnants of a refactor that removed embedded scripts — the log message itself says "embedded scripts removed". The actualregexp.MustCompilecalls inexpression_patterns.gohappen in package-levelvardeclarations; theinit()only logs that the compilation is "initializing."These three
init()functions add entries to the startup log without doing meaningful work, which makes debugging startup behaviour harder (logs appear to show initialization happening, but nothing is actually being initialized).Medium Priority: Inconsistent Embedded Data Loading Strategy
Within
pkg/workflow, two conflicting patterns exist for loading embedded data:Eager (
init()at program start):domains.go:121— parsesecosystemDomainsJSONpermissions_toolset_data.go:39— parsesgithubToolsetsPermissionsJSONgithub_tool_to_toolset.go:20— parsesgithubToolToToolsetJSONruntime_definitions.go:164— buildscommandToRuntime/actionRepoToRuntimemapsLazy (
sync.Onceon first use):action_pins.go:54— lazy-loads and cachesactionPinsJSONschema_validation.go:56— lazy-compiles JSON schemadocker_validation.go:58— lazy-checks Docker daemon availabilityagentic_engine.go:391— lazy-initializes engine registryCommands like
gh-aw version,gh-aw help, orgh-aw compile(without domain-restricted features) still pay the startup cost of parsing domains/permissions/toolsets JSON, even when those packages are never used. The inconsistency also makes it harder for new contributors to know which pattern to follow when adding new embedded data.✅ Improvement Tasks Generated
Task 1: Propagate
context.ContextThrough HTTP Utility FunctionsIssue Type: Code Navigation / API Correctness
Problem:
Four functions in
pkg/cliissue HTTP requests without a context, preventing cooperative cancellation when the user interrupts a command (Ctrl-C) or when a parent deadline fires.Locations:
pkg/cli/mcp_registry.go:55-56—createRegistryRequest(method, url string)and its callerSearchServerspkg/cli/deps_security.go:133-138—querySecurityAdvisories(depVersions, verbose)and its callerCheckSecurityAdvisoriespkg/cli/deps_outdated.go:155-162—getLatestVersion(modulePath, currentVersion, verbose)and its callerCheckOutdatedDependenciespkg/cli/agent_download.go:21-49—downloadAgentFileFromGitHub(verbose)Impact:
deps_report.go,mcp_add.go,mcp_registry_list.go)Recommendation: Add
ctx context.Contextas the first parameter to each function and usehttp.NewRequestWithContext/http.MethodGetwith context:Thread context from the cobra command's
RunEfunction (which receivescmd.Context()) through the call chain to each HTTP site.Validation:
cmd.Context()is available at each command entry pointCtrl-Cduringgh-aw depscancels the HTTP requestEstimated Effort: Medium
Task 2: Remove Vestigial No-Op
init()FunctionsIssue Type: Dead Code Removal
Problem:
Three
init()functions inpkg/workflowdo nothing except emit a log message. Two are explicit remnants of a refactor that removed embedded scripts; one logs that regex compilation is "initializing" when the actual compilation occurs invardeclarations (not insideinit()).Locations:
pkg/workflow/js.go:14-16pkg/workflow/scripts.go:20-22pkg/workflow/expression_patterns.go:67-69Impact:
Recommendation: Delete all three
init()functions. No callers depend on their side effects (confirmed by search — no test or production code references the log messages). If the log-level information is valuable, it belongs in a comment, not a runtime log statement.Validation:
go build ./...succeedsEstimated Effort: Small
Task 3: Standardize Embedded Data Loading to Lazy
sync.OncePatternIssue Type: Inconsistent Pattern / Startup Performance
Problem:
pkg/workflowmixes two incompatible initialization strategies for embedded data. Three files use eagerinit()(blocking at process start for every CLI invocation), while four others use lazysync.Once(loaded only when first needed). Commands that never use domains, permissions, or toolsets still parse all their JSON on startup.Locations (eager, to be converted):
pkg/workflow/domains.go:121—ecosystemDomainsfrom embedded JSONpkg/workflow/permissions_toolset_data.go:39—toolsetPermissionsMapfrom embedded JSONpkg/workflow/github_tool_to_toolset.go:20—GitHubToolToToolsetMapfrom embedded JSONLocations (lazy, existing model to follow):
pkg/workflow/action_pins.go:54—actionPinsOnce sync.Once+getActionPins()accessorImpact:
gh-awinvocation; inconsistency confuses contributors about the correct patternRecommendation: Convert the three eager loaders to follow the
action_pins.gomodel:Update all call sites that currently reference
ecosystemDomainsdirectly to callgetEcosystemDomains(). Apply the same pattern totoolsetPermissionsMapandGitHubToolToToolsetMap.Validation:
gh-aw versionstartup log no longer shows domain/permissions/toolset loading messagesEstimated Effort: Medium
📈 Success Metrics
This Run
Reasoning for Score
pkg/cliand allinit()functions inpkg/workflow. Did not scanpkg/parserorpkg/agentdraindeeply today.📊 Historical Context
Strategy Performance (last 10 runs)
Cumulative Statistics
🎯 Recommendations
Immediate Actions
ctx context.ContexttocreateRegistryRequest,querySecurityAdvisories,getLatestVersion,downloadAgentFileFromGitHuband usehttp.NewRequestWithContextLong-term Improvements
The codebase has now had 10 consecutive days of static analysis. Observed patterns suggest a linter rule for
http.NewRequest(flagging calls without context) and a custom vet check forinit()functions with no side effects would catch these automatically. Consider addingstaticcheckorreviveto the CI pipeline with rules covering these patterns.🔄 Next Run Preview
Suggested Focus Areas
pkg/parser: Not deeply analyzed yet — likely has HTTP calls, error patterns, or context issuespkg/agentdrain: Small package (coordinator, miner) — worth a full symbol auditmcp_inspect_inspector.gogoroutines (process monitoring) have no recovery — check if panics inserverCmd.Wait()paths could crash the inspectorStrategy Evolution
Consider a "caller chain tracing" strategy next: pick 3-5 exported functions, trace every caller up to the CLI entry point, and verify that context, cancellation, and error propagation are complete end-to-end. This would catch more systemic issues than per-file pattern matching.
References:
Beta Was this translation helpful? Give feedback.
All reactions