Enforce panicinlibrarycode in CI and tune it for accepted repo patterns#34374
Merged
Conversation
5 tasks
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix panicinlibrarycode analyzer enforcement in CI
Enforce May 24, 2026
panicinlibrarycode in CI and tune it for accepted repo patterns
pelikhan
approved these changes
May 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR wires the panicinlibrarycode analyzer into the blocking CI custom-linter gate and updates the analyzer so it can enforce “no new panic() in pkg/” without flagging a set of intentional, established patterns (lazy init via sync.Once, BUG: panics, init() panics, and explicitly documented panic contracts).
Changes:
- Enforce
panicinlibrarycodein thecgoCI workflow by running it alongsideerrstringmatchinmake golint-custom. - Refine
panicinlibrarycodeto skip specific accepted panic patterns (sync.Once closures,BUG:-prefixed messages,init()functions, and documented panic contracts). - Add/extend analyzer fixtures and add doc-comment panic contracts on intentional panic sites in
pkg/workflow.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/strings.go |
Adds a doc-comment panic contract for a crypto/rand failure panic path so the analyzer can allow it. |
pkg/workflow/model_aliases.go |
Documents an intentional panic when embedded JSON is invalid to satisfy the analyzer’s contract-based exemption. |
pkg/workflow/claude_tools.go |
Documents a precondition panic contract for the “neutral tools only” invariant. |
pkg/workflow/agentic_engine.go |
Documents an intentional panic for invalid built-in engine registration. |
pkg/linters/panic-in-library-code/testdata/src/panicinlibrarycode/panicinlibrarycode.go |
Extends fixtures to cover the newly allowed panic patterns. |
pkg/linters/panic-in-library-code/panic-in-library-code.go |
Implements the new skip logic using inspect.WithStack plus helpers for the allowed patterns. |
.github/workflows/cgo.yml |
Updates CI to include -panicinlibrarycode in the custom-linters gate. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 2
Comment on lines
+158
to
+162
| case *ast.CallExpr: | ||
| if len(e.Args) == 0 { | ||
| return "", false | ||
| } | ||
| return stringPrefix(pass, e.Args[0]) |
|
|
||
| func isInInitFunction(stack []ast.Node) bool { | ||
| decl := enclosingFuncDecl(stack) | ||
| return decl != nil && decl.Name != nil && decl.Name.Name == "init" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
panicinlibrarycodewas registered and tested, but thecgocustom-linter gate only selectederrstringmatch, so the rule never blocked new productionpanic()calls. This updates the analyzer and CI wiring so the rule is enforced without tripping on established, intentional panic patterns already used inpkg/.Enable the analyzer in the blocking CI gate
.github/workflows/cgo.ymlto runpanicinlibrarycodealongsideerrstringmatchinmake golint-custom.Refine
panicinlibrarycodeto match repo realitysync.Once.Do(func() { ... })lazy-init closures.BUG:.init()functions.Add focused analyzer coverage
panic()calls.Document intentional panic contracts where needed
sync.Once,BUG:, norinit()based, so they are explicit in code and recognized by the analyzer.Example of the newly allowed contract pattern: