[sergo] Sergo Report: constants-adoption-audit-plus-context-propagation-scan — 2026-05-15 #32291
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #32547. |
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-05-15
Run: 10
Strategy:
constants-adoption-audit-plus-context-propagation-scanSuccess Score: 9/10
Executive Summary
Run 10 paired two analyses: a continuation of the
helper_underadoption_failure_modepattern (now the dominant theme across Runs 5/7/8/9/10) and a freshcontext.Background()propagation scan. The combination produced two clean, distinct, actionable findings filed as issues; a verified status update on two prior issues; and the discovery that the codebase has zerocontext.TODO()calls in production — an unusually disciplined signal for a 792-file Go codebase.Key takeaway: the team's prior Run 8 fix (
FilePerm*/DirPerm*constants) shipped successfully, Run 9'sGetWorkflowDir()env-var override was implemented, but Run 8'sDefaultHTTPClientTimeoutconstant and Run 9's.github/workflowsliteral adoption remain open work. The two new issues filed today are scoped specifically to avoid overlap with that backlog.Serena Tools Update
Tool capabilities used today
activate_projectfind_referencing_symbols(*ActionResolver).ResolveSHA— 4.9s, returned 11 references identifying all 5 productioncontext.Background()callsitesfind_symbol(skipped)ResolveSHAerrored as expected; reconfirmed Run 5 finding that receiver methods need(*Type).methodqualified formStrategy Selection
Cached Reuse Component (50%) — helper-adoption audit
Previous Strategy Adapted:
exported-symbol-dead-code-plus-magic-literal-duplication(Run 8, 8/10) andstring-literal-centralization-plus-interface-pollution-audit(Run 9, 9/10)helper_underadoption_failure_mode— constants/helpers exist inpkg/constantsbut call sites bypass them via literal duplication. Run 9's.github/workflowscase (27 prod sites bypassingGetWorkflowDir()) is the canonical exemplar.Default*andGet*exported symbols inpkg/constants/constants.gofor adoption percentage — focusing on runtime constants (paths, timeouts, ports) rather than format-policy constants (perms, dirs) already covered.Default*Timeout,Default*MCP*Port,Default*GatewayPayloadDir,AWF*Dir,AWFConfigFilePath,AWFReflectFilePath,GhAwRootDir,GetWorkflowDir).New Exploration Component (50%) — context.Background/TODO scan
Novel Approach: Audit every
context.Background()andcontext.TODO()callsite inpkg/non-test to identify cases where a function should accept or forward an existingctx context.Contextinstead of materializing a fresh one. Cross-reference via Serenafind_referencing_symbolsto map the full callgraph ofResolveSHA.find_referencing_symbols, Grep with multi-patternpkg/workflow/,pkg/cli/,pkg/actionpins/— all packages that make network calls during workflow compilationCombined Strategy Rationale
The two components complement each other along orthogonal axes: the cached side audits what exists but isn't used (constants), the new side audits what's used but shouldn't be the way it is (
context.Background()at non-boundary sites). Together they triangulate on a single underlying engineering smell — bypass patterns that look harmless in isolation but accumulate maintenance debt.Analysis Execution
Codebase Context
pkg/non-test: 792context.Background(): 23 (in pkg/ non-test)context.Background()callsites: 28context.TODO()callsites: 0Default*constants in pkg/constants/constants.go: ~25 (sampled 11)Findings Summary
Detailed Findings
Medium #1 —
context.Background()cluster in ResolveSHA call sites (#aw_sgar1, filed as issue)5 production call sites pass
context.Background()directly to(*ActionResolver).ResolveSHA(ctx, repo, version), a network operation:pkg/workflow/maintenance_workflow.goresolveActionRefpkg/workflow/action_sha_checker.goCheckActionSHAUpdates(exported)pkg/workflow/action_reference.goresolveSetupActionRef(action mode)pkg/workflow/action_reference.goresolveSetupActionRef(release mode)pkg/cli/copilot_setup.gogetActionRefThe correct pattern already exists at
pkg/actionpins/actionpins.go:317:The
PinContextstruct carriesCtx context.Contextand the resolver call falls back toBackground()only when no parent ctx is provided. The 5 unfixed sites should adopt this pattern (withctx context.Contextthreaded through their signatures).Medium #2 — AWFProxyLogsDir same-file inconsistency (#aw_sgar2, filed as issue)
pkg/workflow/engine_firewall_support.go:Same file, same logical concept (firewall logs directory for YAML emission), but only one site uses the constant. Future migrations of the sandbox path will silently miss line 104.
Low #1 — Run 8
DefaultHTTPClientTimeoutNOT YET implemented (status update)Run 8 filed
#aw_sg8a2for centralizing the30 * time.Secondliteral at 4 prod sites. Run 10 confirms: noDefaultHTTPClientTimeoutconstant exists yet inpkg/constants/, and all 4 literal sites are unchanged:pkg/parser/remote_fetch.go:522pkg/cli/mcp_registry.go:50pkg/cli/deps_security.go:139pkg/cli/agent_download.go:45Not re-filed (existing tracking issue covers it).
Low #2 — Run 9
GetWorkflowDir()env-var override IMPLEMENTED (status update)Run 9's
#aw_sg9a1flagged thatconstants.GetWorkflowDir()ignored the documentedGH_AW_WORKFLOWS_DIRenv-var override. Run 10 verifies the helper now reads the env var:The broader call-site adoption (Run 9 reported 27 literal sites vs 13 helper sites) was not re-audited this run.
Low #3–#4 — Minor observations not warranting separate issues
AWFAuditDirminor bypass atpkg/cli/firewall_policy.go:459: usesfilepath.Join(agentDir, "tmp", "gh-aw", "sandbox", "firewall", "audit")plusagentBase+"/tmp/gh-aw/sandbox/firewall/audit". Defensible — the join form is needed for OS-portable path construction inside an artifact directory.mcpScriptsStartPort = 3000atpkg/cli/mcp_inspect_mcp_scripts_server.go:21: literal duplicate ofconstants.DefaultMCPServerPort = 3000. Not filed (the local constant has different semantics — it's the starting port for a port-scan loop, not the default port).context.Background()defensible sites (23 of 28): nil-check fallbacks (action_resolver.go:33,actionpins.go:85,318,signal_aware_poll.go:68,retry.go:69), top-level CLI entry points (add_command.go:367,outcomes_command.go:138,mcp_server_command.go:171, etc.), andRunGH/RunGHCombinednon-Context convenience wrappers (analog of stdlibhttp.Getvshttp.NewRequestWithContext).context.TODO()calls in prod: notable signal of context discipline.Improvement Tasks Generated
Task 1 — Thread
context.Contextthrough ResolveSHA wrapper functionspkg/workflow/maintenance_workflow.go,pkg/workflow/action_sha_checker.go,pkg/workflow/action_reference.go,pkg/cli/copilot_setup.gopkg/actionpins/actionpins.go:317Task 2 — Replace
AWFProxyLogsDirliteral atengine_firewall_support.go:104pkg/workflow/engine_firewall_support.goSuccess Metrics
This Run
Reasoning: Two distinct, scoped, actionable findings filed with clear before/after code; one prior issue verified as implemented; one prior issue verified as still open (no re-file); zero false positives; Serena
find_referencing_symbolsvalidated the context-propagation finding with precision. Did not hit 10/10 because the issues are medium-severity preventive rather than fixing a live bug.Historical Context
Cumulative Statistics
Strategy Performance Trend
Recommendations
Immediate Actions
ctx context.Contextthrough ResolveSHA wrappers (Issue filed) — unblocks caller cancellation of compile-path network callsAWFProxyLogsDirliteral atengine_firewall_support.go:104(Issue filed) — prevents future sandbox-path migration bugLong-term Improvements
helper_underadoption_failure_modehas now appeared in 5 of 10 runs. Consider adding a CI check that grep-detects known sentinel literals (e.g.,/tmp/gh-aw/sandbox/firewall/,".github/workflows",30 * time.Secondonhttp.Client) and fails when they appear outsidepkg/constants/.#aw_sg8a2(DefaultHTTPClientTimeout) has been open since 2026-05-13. Add to the next-run watchlist for adoption verification.Next Run Preview
Suggested Focus Areas
fmt.Errorfvserrors.Newconsistency — Run 5 noted 1704fmt.Errorfcalls but didn't audit%wplacement at the boundary between Errorf and New_test.gofiles for repeated 5+-line setup blocksinit()function audit — Run 5 logged panic in init was clean; never audited init bodies for side-effect orderingtime.Now()call distribution — clock injection / testability axis#aw_sg8a2adoption as Phase-3 health checkStrategy Evolution
The 50/50 cached/new split has now stabilized as the dominant pattern. Consider introducing a third "verification" component (~10%): each run, re-audit one previously-filed issue to confirm/deny adoption. Run 10 did this informally for
GetWorkflowDir()andFilePerm*; formalizing it would make adoption gaps explicit.References:
Beta Was this translation helpful? Give feedback.
All reactions