Skip to content

Recognize parenthesized callees in timesleepnocontext, ctxbackground, execcommandwithoutcontext - #74737

Merged
pelikhan merged 1 commit into
mainfrom
sergo/paren-unwrap-ctx-family-r119-bb04c5acee319f1c
Nov 4, 2026
Merged

pelikhan merged 1 commit into
mainfrom
sergo/paren-unwrap-ctx-family-r119-bb04c5acee319f1c

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Three linters that CI runs on this repo (.github/workflows/cgo.yml:1674 and :1701) type-assert call.Fun directly. Because of that, they don't flag a call whose function is wrapped in parentheses:

Linter Missed form
timesleepnocontext (time.Sleep)(d) inside a function that takes ctx
ctxbackground (context.Background)() inside a function that takes ctx
execcommandwithoutcontext (exec.Command)(name) inside a function that takes ctx

This PR wraps call.Fun in astutil.UnwrapParenExpr, the same fix used in the earlier trimleftright/httpnoctx/stringreplaceminusone batch. It also replaces each linter's copy of the 12-line "is this selector on package X" check with astutil.IsPkgSelector, which more than 20 linters already use. Net change: −9 lines, and the go/types import is gone from all three files.

Evidence

  • A search for bare .Fun.(*ast. in pkg/ (non-test files) found timesleepnocontext.go:83, ctxbackground.go:84 and execcommandwithoutcontext.go:111.
  • Serena find_referencing_symbols on astutil.IsPkgSelector lists 20+ callers that use the same package-identity check these three copied by hand.
  • No non-testdata code in pkg/ currently uses a parenthesized time.Sleep, context.Background or exec.Command callee, so the stricter check adds no new CI findings.

Changes

  • pkg/linters/timesleepnocontext/timesleepnocontext.go: isTimeSleepCall now unwraps parentheses and uses IsPkgSelector.
  • pkg/linters/ctxbackground/ctxbackground.go: isContextBackgroundCall gets the same change, plus a doc comment.
  • pkg/linters/execcommandwithoutcontext/execcommandwithoutcontext.go: execCommandSelector gets the same change. The suggested fix still edits sel.Sel and inserts after call.Lparen, so (exec.Command)(name) becomes (exec.CommandContext)(ctx, name).
  • Test fixtures: added a parenthesized-callee case to each linter's testdata. Added the matching .golden fixes for the two linters that use RunWithSuggestedFixes (ctxbackground produces _ = ctx; execcommandwithoutcontext produces (exec.CommandContext)(ctx, name)).

Validation

  • Serena get_diagnostics_for_file (gopls) reports 0 diagnostics on all three changed source files and on the execcommandwithoutcontext fixture. That rules out an unused go/types import or type errors.
  • Not run in this sandbox: go test, gofmt and make fmt were denied by the agent's permission layer. CI should run go test ./pkg/linters/timesleepnocontext/ ./pkg/linters/ctxbackground/ ./pkg/linters/execcommandwithoutcontext/. The new fixtures add one want each, and the two new golden entries need to match.
Remaining bare call.Fun type assertions (follow-up candidates)

sprintfint.go:52 (has a golden file), timenowsub.go:42/99, errstringmatch.go:82/102, timeafterleak.go:70, closeerrorunchecked.go:116, httprespbodyclose.go:261, hardcodedfilepath.go:135, and about 30 more. These can go in small per-linter batches.

References:

Generated by 🤖 Sergo - Serena Go Expert · claude · routed: opus55 high · ~150 AIC · ⌖ ~2 AIC · ⊞ 3.8K · ◷

  • expires on Nov 10, 2026, 7:53 PM UTC-08:00

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

github-actions Bot commented Nov 4, 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 4, 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 · ⌖ ~1 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 4, 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 4, 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: gpt56 max · ~2 AIC · ⌖ ~1 AIC · ⊞ 118 · ◷

Generated by Ponytail Reviewer for #74737

@github-actions

github-actions Bot commented Nov 4, 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: opus55 medium · ~11 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

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 changes extending context-cancellation checks to parenthesized calls.

No open issues 🎉

What changed in this PR

This PR closes a detection gap in three gh-aw linters so parenthesized calls receive the same context-cancellation checks as ordinary calls.

Changes:

  • Unwrap parenthesized callees in timesleepnocontext, ctxbackground, and execcommandwithoutcontext.
  • Replace duplicated package-identity checks with astutil.IsPkgSelector.
  • Add regression fixtures and expected suggested-fix outputs.
File Description
pkg/​linters/​timesleepnocontext/​timesleepnocontext.go Recognizes parenthesized time.Sleep calls using shared helpers.
pkg/​linters/​timesleepnocontext/​testdata/​src/​timesleepnocontext/​timesleepnocontext.go Adds a parenthesized sleep regression case.
pkg/​linters/​execcommandwithoutcontext/​testdata/​src/​execcommandwithoutcontext/​execcommandwithoutcontext.go.golden Records the expected parenthesized CommandContext fix.
pkg/​linters/​execcommandwithoutcontext/​testdata/​src/​execcommandwithoutcontext/​execcommandwithoutcontext.go Adds a parenthesized command regression case.
pkg/​linters/​execcommandwithoutcontext/​execcommandwithoutcontext.go Recognizes parenthesized exec.Command calls using shared helpers.
pkg/​linters/​ctxbackground/​testdata/​src/​ctxbackground/​ctxbackground.go.golden Records replacement of the parenthesized call with ctx.
pkg/​linters/​ctxbackground/​testdata/​src/​ctxbackground/​ctxbackground.go Adds a parenthesized background-context regression case.
pkg/​linters/​ctxbackground/​ctxbackground.go Recognizes parenthesized context.Background calls and documents support.

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 summary

No actionable correctness, performance, or maintainability issues found in the changed lines. The specialist pass was unavailable/invalid, so this verdict is based on the independent source review.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 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 (regression-test check) and /codebase-design (shared helper reuse). No actionable issues found; approving.

📋 Key Themes & Highlights

Verification

  • ✅ go test passes for timesleepnocontext, ctxbackground, and execcommandwithoutcontext; gofmt and go vet are clean.
  • ✅ Regression check: with the three source hunks reverted, the new parenthesized-callee fixtures fail (want vs. fixed mismatch), so they guard the change.
  • ✅ IsPkgSelector and UnwrapParenExpr exist in pkg/linters/internal/astutil and match the removed inline logic. The package-identity check still goes through types.PkgName, and go/types is no longer needed in these files.
  • ✅ No parenthesized time.Sleep, context.Background, or exec.Command callees in non-testdata code, so the stricter matching adds no new CI findings (the PR body's claim holds).

Notes (non-blocking)

  • The pkg/linters/README.md descriptions for these three linters do not mention parenthesized callees. Consider a short note there so the behaviour is discoverable.

@pelikhan the three linters now recognise parenthesized callees and the shared helper is used consistently. Thanks for the clear PR description and evidence.

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

@pelikhan
pelikhan merged commit dac926c into main Nov 4, 2026
112 of 127 checks passed
@pelikhan
pelikhan deleted the sergo/paren-unwrap-ctx-family-r119-bb04c5acee319f1c branch November 4, 2026 04:26
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.0

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.

2 participants