Skip to content

ctxbackground: zero-violation analyzer ready for CI enforcement, missing from LINTER_FLAGS #51929

Description

@github-actions

Summary

ctxbackground (flags context.Background() calls inside functions that already receive a context.Context parameter) is clean, type-resolved, and has zero production violations, but is absent from the CI-enforced linter set in .github/workflows/cgo.yml.

Verification performed

  1. Both previously-filed precision bugs for this linter are already fixed in the current code (pkg/linters/ctxbackground/ctxbackground.go):
    • The FuncDecl-only enclosing-scope walk (prior false negative for closures) is fixed: the analyzer now walks cur.Enclosing((*ast.FuncDecl)(nil), (*ast.FuncLit)(nil)) and stops at the nearest enclosing function (breaking after the first match), so it no longer crosses FuncLit boundaries.
    • The syntactic-name-match bug (matching the identifier "context" textually) is fixed: isContextBackgroundCall (ctxbackground.go:83-101) resolves the selector via pass.TypesInfo.ObjectOf and checks *types.PkgName.Imported().Path() == "context" — a type-resolved check, immune to aliasing/shadowing.
  2. nolint + generated/test-file skip parity: the analyzer calls nolint.HasDirectiveForLinter and filecheck.ShouldSkipFilename (which covers both generated files and _test.go files) — consistent with its enforced siblings.
  3. Zero production violations: searched all non-test, non-linter-testdata occurrences of context.Background() under pkg/ for cases where the enclosing function also declares a context.Context parameter (the analyzer's trigger condition). Every hit inspected (pkg/parser/remote_workflow_spec.go, pkg/workflow/repository_features_validation.go, pkg/actionpins/resolve.go, etc.) is a function that does not take a context.Context parameter (several have an explicit comment noting context-threading is a tracked follow-up), or passes a non-context.Context-typed value (e.g. *PinContext) — correctly outside the analyzer's scope. No true-positive sites exist today.

Recommendation

Add -ctxbackground to the LINTER_FLAGS list in both the default-build and wasm-build make golint-custom invocations in .github/workflows/cgo.yml (~lines 1370 and 1373), matching the pattern used for its already-enforced ctx-family siblings (execcommandwithoutcontext, timesleepnocontext, httpnoctx, contextcancelnotdeferred).

Validation checklist

  • -ctxbackground added to both LINTER_FLAGS strings in cgo.yml
  • CI run confirms zero violations under the default build and the GOOS=js GOARCH=wasm build
  • pkg/linters/doc.go / README.md already list it as active (registry doc-sync is currently correct at 64 analyzers — no drift found)

Effort: trivial — CI config change only, no source changes.

Generated by 🤖 Sergo - Serena Go Expert · agent · 326.7 AIC · ⌖ 30.4 AIC · ⊞ 5.9K ·

  • expires on Aug 17, 2026, 8:29 PM UTC-08:00

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions