Skip to content

[lint-monster] Lint Group 2: Type assertion safety & deferred mutex locks (40 violations) #34852

@github-actions

Description

@github-actions

Lint Issue Group 2: Type Assertion Safety & Deferred Lock Fixes

Summary

40 lint violations spanning type assertion safety (29 issues) and deferred mutex unlock errors (11 issues). These are low-level safety issues affecting core packages.

Issue Details

Category: Safety (panics, deadlocks)
Affected Packages: pkg/parser/, pkg/linters/, pkg/workflow/, pkg/cli/, pkg/agentdrain/, pkg/console/
Root Causes:

  1. Unchecked type assertions that can panic if type is wrong
  2. Non-deferred mutex unlocks that don't protect against deadlocks on early return or panic

Type Assertion Violations (29 issues)

Examples:

  • pkg/parser/virtual_fs.go:76,90 - Unchecked *FrontmatterResult assertions
  • pkg/workflow/dispatch_repository.go:164 - Unchecked map[string]any assertion
  • pkg/workflow/repository_features_validation.go:185,212 - Unchecked *RepositoryFeatures assertions
  • pkg/linters/excessivefuncparams/excessivefuncparams.go:41 - Unchecked *ast.FuncDecl assertion
  • pkg/cli/jsonworkflow_to_markdown.go:448,455 - Unchecked string assertions

Fix Pattern:

// WRONG
value := x.(Type)  // Panics if x is not Type

// CORRECT
value, ok := x.(Type)
if !ok {
  return fmt.Errorf("expected Type, got %T", x)
}

Deferred Mutex Unlock Violations (11 issues)

Examples:

  • pkg/agentdrain/coordinator.go:115 - Mutex Lock without defer
  • pkg/agentdrain/miner.go:118,137,148 - Multiple mutex issues
  • pkg/console/spinner.go:130,159,175,195 - Spinner mutex locks
  • pkg/cli/compile_watch.go:189 - Watch mode mutex issue
  • pkg/cli/docker_images.go:104 - Docker mutex issue

Fix Pattern:

// WRONG
mu.Lock()
// ... code that might return or panic ...
mu.Unlock()

// CORRECT
mu.Lock()
defer mu.Unlock()
// ... code ...

Expected Outcome

All 40 violations resolved by:

  1. Adding two-value form checks for all type assertions
  2. Adding defer statements immediately after all mutex locks
  3. No behavioral changes; only safety improvements
  4. All fixes verified with make golint-custom

Remediation Checklist

  • Find all 29 type assertion violations: grep -r "x\.( " pkg/ | grep -v test
  • For each unchecked assertion:
    • Change to two-value form with ok check
    • Add error return or sensible fallback
  • Find all 11 deferred mutex violations: grep -n "\.Lock()" pkg/agentdrain/*.go pkg/console/*.go pkg/cli/compile_watch.go pkg/cli/docker_images.go
  • For each Lock() call:
    • Add defer mu.Unlock() immediately after the Lock() line
    • Remove any existing manual Unlock() calls that follow
  • Run make golint-custom and verify all 40 violations are gone
  • Run make test-unit to ensure no regressions
  • Commit with message: "fix: add safety checks for type assertions and deferred mutex unlocks"

Skill Guidance

Use error-pattern-safety SKILL for:

  • Safe error pattern matching guidelines
  • Type assertion safety considerations
  • Mutex locking safety patterns

Notes

  • Type assertion safety: Panics can crash workflows silently
  • Deferred unlock safety: Prevents deadlocks when functions return early or panic
  • These changes are pure safety improvements with no behavior change

Generated by 🧌 LintMonster · haiku45 162.7K ·

  • expires on Jun 2, 2026, 3:52 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions