You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new custom go/analysis linter, packagelevelmutableslicemap, under pkg/linters/packagelevelmutableslicemap/.
What it catches: package-level (file/package-scope) var declarations of slices or maps that are mutated from inside a function body via:
append() re-assignment (s = append(s, ...))
index assignment (m[k] = v)
delete(m, k)
Package-level mutable slices/maps are shared across every goroutine and every call into the package for the lifetime of the process. Mutating one from inside a function — rather than storing the state on a struct or returning fresh values — risks data races under concurrent access and can leak state between unrelated calls (e.g. across test runs or concurrent request handlers).
Why this is useful / evidence found:
Issue [concurrency] Concurrency Safety Issue in create_agent_session tool: module-level mutable state #52683 ("[concurrency] Concurrency Safety Issue in create_agent_session tool: module-level mutable state") flags exactly this class of bug: a module-level mutable array (_allResults) reset and mutated across main() invocations, currently latent but a real cross-run data-corruption risk if the calling architecture changes to parallel dispatch.
A codebase scan (Serena-assisted) found several package-level var slices/maps in pkg/ that would benefit from this check being available as an early warning for future code.
Supported directives:(nolint/redacted):packagelevelmutableslicemap on the mutating line suppresses the diagnostic, consistent with other linters in this package.
Testing
go test ./pkg/linters/packagelevelmutableslicemap/... — new analysistest fixture covering append-mutation, index-assignment, delete(), an immutable/read-only slice (no diagnostic), and a (nolint/redacted)-suppressed case.
go test ./pkg/linters/ — registry/doc/spec sync tests updated and passing (65 analyzers now).
go build ./cmd/linters/... and go run ./cmd/linters ./pkg/linters/packagelevelmutableslicemap/... — clean build, linter binary runs without flagging itself.
gofmt -l — no formatting issues.
Files changed
pkg/linters/packagelevelmutableslicemap/packagelevelmutableslicemap.go (new analyzer)
This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.
Protected files
README.md
The push was rejected because GitHub Actions does not have workflows permission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.
Create the pull request manually
# Download the patch from the workflow run
gh run download 31825008582 -n agent -D /tmp/agent-31825008582
# Create a new branch
git checkout -b linter-miner/packagelevelmutableslicemap-b267125f818cd2c5 main
# Apply the patch (--3way handles cross-repo patches)
git am --3way /tmp/agent-31825008582/aw-linter-miner-packagelevelmutableslicemap.patch
# Push the branch and create the pull request
git push origin linter-miner/packagelevelmutableslicemap-b267125f818cd2c5
gh pr create --title '[linter-miner] Add packagelevelmutableslicemap custom linter' --base main --head linter-miner/packagelevelmutableslicemap-b267125f818cd2c5 --repo github/gh-aw
Generated by Linter Miner · auto · 256.1 AIC · ⌖ 14.2 AIC · ⊞ 7.7K · ◷
Summary
Adds a new custom
go/analysislinter,packagelevelmutableslicemap, underpkg/linters/packagelevelmutableslicemap/.What it catches: package-level (file/package-scope)
vardeclarations of slices or maps that are mutated from inside a function body via:append()re-assignment (s = append(s, ...))m[k] = v)delete(m, k)Package-level mutable slices/maps are shared across every goroutine and every call into the package for the lifetime of the process. Mutating one from inside a function — rather than storing the state on a struct or returning fresh values — risks data races under concurrent access and can leak state between unrelated calls (e.g. across test runs or concurrent request handlers).
Why this is useful / evidence found:
_allResults) reset and mutated acrossmain()invocations, currently latent but a real cross-run data-corruption risk if the calling architecture changes to parallel dispatch.varslices/maps inpkg/that would benefit from this check being available as an early warning for future code.Supported directives:
(nolint/redacted):packagelevelmutableslicemapon the mutating line suppresses the diagnostic, consistent with other linters in this package.Testing
go test ./pkg/linters/packagelevelmutableslicemap/...— new analysistest fixture covering append-mutation, index-assignment, delete(), an immutable/read-only slice (no diagnostic), and a(nolint/redacted)-suppressed case.go test ./pkg/linters/— registry/doc/spec sync tests updated and passing (65 analyzers now).go build ./cmd/linters/...andgo run ./cmd/linters ./pkg/linters/packagelevelmutableslicemap/...— clean build, linter binary runs without flagging itself.gofmt -l— no formatting issues.Files changed
pkg/linters/packagelevelmutableslicemap/packagelevelmutableslicemap.go(new analyzer)pkg/linters/packagelevelmutableslicemap/packagelevelmutableslicemap_test.go(analysistest)pkg/linters/packagelevelmutableslicemap/testdata/src/packagelevelmutableslicemap/packagelevelmutableslicemap.go(fixture)pkg/linters/registry.go(registered analyzer)pkg/linters/doc.go,pkg/linters/README.md,pkg/linters/spec_test.go(documentation/spec sync)Warning
Protected Files — Push Permission Denied
This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.
Protected files
README.mdThe push was rejected because GitHub Actions does not have
workflowspermission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.Create the pull request manually