Skip to content

Use errors.Is for context.Canceled / context.DeadlineExceeded comparisons in actionlint.go and mcp_validation.go #33696

Closed

Description

@github-actions

Summary

Three production sites compare a Context.Err() return value to context.Canceled / context.DeadlineExceeded with ==, while the rest of the codebase (including production code in the same package family) consistently uses errors.Is. This is a low-severity but real idiom inconsistency: == only happens to work because Context.Err() is documented by the standard library to return exactly one of those sentinels — any future wrapper (e.g., context.Cause, a custom context wrapper) would silently break these checks. Filed by Sergo Run 15.

Affected sites

File Line Current Recommended
pkg/cli/actionlint.go 310 if runCtx.Err() == context.DeadlineExceeded { if errors.Is(runCtx.Err(), context.DeadlineExceeded) {
pkg/cli/actionlint.go 320 if runCtx.Err() == context.Canceled { if errors.Is(runCtx.Err(), context.Canceled) {
pkg/cli/mcp_validation.go 205 if ctx.Err() == context.DeadlineExceeded { if errors.Is(ctx.Err(), context.DeadlineExceeded) {

Evidence of existing convention

The codebase already uses errors.Is for this exact comparison in multiple files — production and test — proving this is the established idiom:

  • pkg/cli/trial_helpers.go:93 — errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) (production)
  • pkg/cli/pr_automerge_test.go:46, pkg/cli/logs_orchestrator_test.go:141, pkg/cli/logs_parallel_test.go:299, pkg/cli/mcp_server_stdio_integration_test.go:78, pkg/cli/run_workflow_execution_test.go:110,185 (tests)

For reference, io.EOF comparisons in the codebase are 100% on the errors.Is side already (2/2 sites): pkg/fileutil/tar.go:34, pkg/cli/experiments_command.go:775.

Severity

Low — current code is functionally correct because Context.Err() is contractually guaranteed by stdlib to return an unwrapped sentinel. The fix is idiom consistency and futureproofing, not a bug fix.

Recommended fix

Replace the three == checks with errors.Is. The errors package is already imported in both files (used by errors.New(...) calls nearby).

// pkg/cli/actionlint.go
if errors.Is(runCtx.Err(), context.DeadlineExceeded) { ... }
if errors.Is(runCtx.Err(), context.Canceled) { ... }

// pkg/cli/mcp_validation.go
if errors.Is(ctx.Err(), context.DeadlineExceeded) { ... }

Validation

  • go vet ./... clean
  • go test ./pkg/cli/... passes (existing timeout tests must still pass)
  • Grep confirms zero remaining \.Err\(\) == context\. matches in pkg/

Estimated effort

Small — 3 line-level edits in 2 files, no behaviour change.

Why now

Sergo Run 13 introduced the errstringmatch linter and Run 14 cleaned up the seven prod violations, establishing a clear project value for migrating away from brittle error-shape matching. The == against context sentinels is the same family of anti-pattern at a smaller scale — easy to clean up in the same theme.


Generated by Sergo Run 15 — strategy: open-issue-reverify + error-comparison-idiom-audit. Auto-closes after 7 days per create-issue.expires: 7d.

Generated by 🤖 Sergo - Serena Go Expert · ● 15.3M · ◷

  • expires on May 28, 2026, 5:14 AM UTC

Activity

  1. github-actions commented on May 21, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · ● 23.8K · ◷

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions