Repository navigation
[repository-quality] Repository Quality: Package-Level Mutable State & init() Side Effects #73195
Replies: 0 comments
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.
🎯 Repository Quality Improvement Report - Package-Level Mutable State & init() Side Effects
Analysis Date: 2026-10-30
Focus Area: Package-Level Mutable State & init() Side Effects
Strategy Type: Custom
Custom Area: Yes — prior runs covered panics, errors, tests, nolint, HTTP; none examined hidden global state and init-order coupling, which affects test isolation and WASM builds.
Executive Summary
Non-linter production code has only 5
init()functions, which is a healthy baseline. The riskiest ispkg/workflow/cooldown.go:14, which mutatesghAwOnSectionKeys(declared inevent_validation.go:83) from another file. Correctness depends on Go file init order, and the map is read during validation elsewhere (event_validation.go:146,github_app_requirements.go:217).Several exported package-level slices and maps can be mutated by any importer:
DefaultGitHubToolsets,ActionFriendlyGitHubToolsets,DefaultEndorsementReactions,DefaultMarshalOptions,BuiltinGraderRegistry,ValidationConfigand others. There are also about 243 package-level map/slice vars, plus test-seam function vars inengine_definition.go:399-413guarded by a mutex that production code does not hold when reading them.Full Analysis Report
Focus Area: Package-Level Mutable State & init()
Metrics Collected:
init()funcsinit()mutating another file's globalcooldown.go)init()building derived mapsruntime_definitions.go:185)knownEngineImports*(9 refs)os.Getenvin non-test pkg codeFindings
Strengths
init()functions; linters (packagelevelmutableslicemap) already exist.Areas for Improvement
cooldown.go:14mutatesghAwOnSectionKeysat init; the key belongs in the literal.const.runtime_definitions.go:185buildscommandToRuntimeandactionRepoToRuntimeininit(); these can usesync.OnceValueor an initializer function.os.Getenvis scattered (engine_secrets.go7,shell_completion.go6);envutilexists but is not used consistently.🤖 Tasks for Copilot Agent
NOTE TO PLANNER AGENT: Split the following tasks into individual work items.
Improvement Tasks
Task 1: Remove cross-file init() mutation of ghAwOnSectionKeys
Priority: High
Estimated Effort: Small
Focus Area: Package-Level Mutable State
Description: Move the
cooldownkey into theghAwOnSectionKeysliteral and deleteinit()incooldown.go.Acceptance Criteria:
init()inpkg/workflow/cooldown.gogo test ./pkg/workflow/...passesCode Region:
pkg/workflow/cooldown.go,pkg/workflow/event_validation.goTask 2: Replace init()-built runtime lookup maps with lazy builders
Priority: Medium
Estimated Effort: Small
Focus Area: Package-Level Mutable State
Description: Replace
init()inruntime_definitions.gowithsync.OnceValue-based accessors, or a var initializer function.Acceptance Criteria:
commandToRuntimeandactionRepoToRuntimeare not assigned ininit()Code Region:
pkg/workflow/runtime_definitions.goTask 3: Harden exported mutable defaults
Priority: Medium
Estimated Effort: Medium
Focus Area: Package-Level Mutable State
Description: Convert exported slice/map defaults into accessor functions returning copies (
slices.Clone/maps.Clone), or unexport them, forDefaultGitHubToolsets,ActionFriendlyGitHubToolsets,GitHubToolsetsExcludedFromAll,DefaultEndorsementReactions,DefaultDisapprovalReactions,DefaultGraderIDs,DefaultMarshalOptions.Acceptance Criteria:
Code Region:
pkg/workflow/github_toolsets.go,mcp_github_config.go,graders_config.go,yaml_options.goTask 4: Encapsulate knownEngineImports test seams
Priority: Low
Estimated Effort: Medium
Focus Area: Package-Level Mutable State
Description: Group URL/client/download seams in
engine_definition.go:399-413into a struct with a constructor, so tests inject it instead of overwriting globals while production reads occur without the mutex.Acceptance Criteria:
Code Region:
pkg/workflow/engine_definition.go📊 Historical Context
14 runs recorded; all were custom areas (most recent: Runtime Panic Surface, Lint Suppression Debt, HTTP Server Hardening).
🎯 Recommendations
Immediate Actions (This Week)
Short-term Actions (This Month)
Long-term Actions (This Quarter)
📈 Success Metrics
Next Steps
Generated by Repository Quality Improvement Agent
Next analysis: 2026-10-31 — Focus area selected by diversity algorithm
All reactions