Skip to content

fix(linters): unwrap parentheses in bufferresetbeforereuse and panic-in-library-code - #76740

Merged
pelikhan merged 3 commits into
mainfrom
sergo/paren-unwrap-buffer-panic-r125-f869a6d0a27e607b
Nov 11, 2026
Merged

pelikhan merged 3 commits into
mainfrom
sergo/paren-unwrap-buffer-panic-r125-f869a6d0a27e607b

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Sergo R125 follow-up to the paren-unwrap series (#75599, #75816, #76123).

Evidence

  • bufferresetbeforereuse.appendCallEvent required call.Fun to be a bare *ast.SelectorExpr and sel.X a bare *ast.Ident. (buf).Reset() and (buf.WriteString)(x) produced no events, so a parenthesized Reset was ignored and parenthesized reuse was missed.
  • panic-in-library-code missed several parenthesized forms: the (panic)(x) callee, (fmt.Sprintf)("BUG: ..."), (once.Do)(func(){...}) and panic(("BUG: " + x)). The BUG: and sync.Once exemptions failed, and the callee check was a literal *ast.Ident match.

Change

Use astutil.UnwrapParenExpr on the callee/receiver in appendCallEvent, analyzePanicCalls, isFmtSprintf and selectorExprFromCallFun, and add a *ast.ParenExpr case to extractConstantStringPrefix. New fixtures cover each form.

Validation

  • serena get_diagnostics_for_file on both changed source files returned no errors or warnings.
  • go test and make fmt could NOT be run in this sandbox (Bash go is denied), so the analysistest suites have not been executed locally. Please rely on CI for them.

🤖 Generated with [Claude Code]((claude.com/redacted)

Generated by 🤖 Sergo - Serena Go Expert · claude · routed: sonnet55 high · ~45 AIC · ⌖ ~2 AIC · ⊞ 4.7K · ◷

  • expires on Nov 17, 2026, 7:52 PM UTC-08:00

@github-actions github-actions Bot added cookie Issue Monster Loves Cookies! sergo labels Nov 11, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 11, 2026 08:29
Copilot AI dynamic review requested due to automatic review settings November 11, 2026 08:29
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

Generated by PR Specification Reviewer for #76740

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.5K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 181 · ◷

Generated by Ponytail Reviewer for #76740

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the parenthesis-handling updates to the buffer reuse and library panic linters.

No open issues 🎉

What changed in this PR

Continues the parenthesis-handling fixes in gh-aw’s custom Go linters, making buffer reuse checks and library panic checks recognize equivalent parenthesized expressions.

Changes:

  • Unwrap buffer method callees and receivers so parentheses do not hide reuse or resets.
  • Recognize parenthesized panic calls while preserving BUG: and sync.Once exemptions.
  • Add regression fixtures for both linters.
File Description
pkg/​linters/​panic-in-library-code/​testdata/​src/​panicinlibrarycode/​panicinlibrarycode.go Adds parenthesized panic and exemption fixtures.
pkg/​linters/​panic-in-library-code/​panic-in-library-code.go Unwraps callees and parenthesized string-prefix expressions.
pkg/​linters/​bufferresetbeforereuse/​testdata/​src/​a/​a.go Adds parenthesized reuse and reset fixtures.
pkg/​linters/​bufferresetbeforereuse/​bufferresetbeforereuse.go Unwraps method callees and buffer receivers before matching.

Review effort: Balanced (auto)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete: no actionable correctness, performance, or security issues found in the changed lines. The specialist pass completed; its findings were non-actionable (validation advice and test-coverage suggestions rather than defects).

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /tdd and /diagnosing-bugs. The fix is correct for the forms it targets, and the regression fixtures fail on the pre-fix source. One narrow false positive remains, noted inline.

📋 Key Themes & Highlights

Validation I ran

  • go test passes for both bufferresetbeforereuse and panic-in-library-code. The PR says these could not be run locally, so CI is not the only signal.
  • With the source hunks reverted and the new fixtures kept, both suites fail. The new fixtures are real regression tests.
  • gofmt -l reports no issues.

Positive Highlights

  • ✅ Using astutil.UnwrapParenExpr matches the existing pattern in timenowsub, lenstringsplit, and manualpathconcat.
  • ✅ The /tdd fixtures cover the parenthesized callee, receiver, Sprintf, and BUG: concatenation forms.

Remaining gap

  • ⚠️ (once.Do)((func(){...})) is still flagged. The parenthesized closure argument hides the sync.Once exemption. See the inline comment for a tested fix and fixture. This is a narrow edge case and can land as a follow-up.

@copilot please address the inline comment.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~5 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again


// ok: parenthesized sync.Once.Do callee.
func parenthesizedOnceDo() {
(once.Do)(func() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] A parenthesized closure argument is still flagged: (once.Do)((func() {...})) produces a false positive. isInSyncOnceFuncLit only checks the direct parent of the FuncLit, and callArgsContainExpr compares arguments by identity, so the wrapping ParenExpr hides the sync.Once exemption. The linter flags the closure body in a temporary reproduction.

💡 Suggested fix and regression fixture

In pkg/linters/panic-in-library-code/panic-in-library-code.go (outside this diff's hunks), in isInSyncOnceFuncLit and callArgsContainExpr:

parent := encl.Parent()
for {
	if _, isParen := parent.Node().(*ast.ParenExpr); !isParen {
		break
	}
	parent = parent.Parent()
}
call, ok := parent.Node().(*ast.CallExpr)
func callArgsContainExpr(args []ast.Expr, target ast.Expr) bool {
	return slices.ContainsFunc(args, func(arg ast.Expr) bool {
		return astutil.UnwrapParenExpr(arg) == target
	})
}

Add this fixture after parenthesizedOnceDo:

// ok: parenthesized closure argument to sync.Once.Do.
func parenthesizedOnceDoClosureArg() {
	(once.Do)((func() {
		panic("lazy init failure") // should not be flagged
	}))
}

I ran both suites with this change and they pass. The existing fixtures do not cover this form.

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check lint-go-govulncheck (FAILURE): Check run.

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "704db5800c778b7cdc5e1382d885a7703af9cafd",
  "kind": "requested",
  "schema_version": "1",
  "state": "cc2ca635f1f700e415b8109eef636ca4b9df1a8d924889cb8edec04a979490f6",
  "work": [
    "4ce4dd407e604d374ecd66edfd2afc18c54e2d0b3733dbac37ac8e9c8834fdba"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

Copilot AI and others added 2 commits November 11, 2026 09:13
…ffer-panic-r125-f869a6d0a27e607b

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Merged the latest main and its Go 1.27.4 requirement, then fixed the custom-linter bounds-check warnings. Commit: bbeb6abd. The final validation gate passed; local govulncheck could not reach vuln.go.dev due to DNS resolution failure.

Copilot AI requested a review from gh-aw-bot November 11, 2026 09:35
@pelikhan
pelikhan merged commit b071549 into main Nov 11, 2026
45 checks passed
@pelikhan
pelikhan deleted the sergo/paren-unwrap-buffer-panic-r125-f869a6d0a27e607b branch November 11, 2026 15:15
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cookie Issue Monster Loves Cookies! sergo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants