feat(rules): ast-grep YAML for go-concurrency/channel-closed-by-sender-only#34
Merged
Conversation
…r-only Mechanical YAML count: 27 -> 28. Hybrid pattern: flag every close($X) call. Agent decides per-finding whether enclosing function is producer (sends into channel — close correct, typically 'defer close(ch)') or consumer (only receives — close is the bug). Multi-producer routed through dedicated closer goroutine + WaitGroup is also producer-side once the agent reads the surrounding context. Pattern uses bare 'close($X)' — same simple-pattern approach as PR #33's no-custom-ptr-helpers. The producer-vs-consumer judgment needs reading function body's send/receive direction, exactly the cross-context reasoning ast-grep can't reliably do. Verified via fixture: producer's 'defer close(out)' (correct) AND consumer's 'close(in)' (wrong) both fire; non-close call clean. Agent dismisses the producer side and surfaces the consumer side as the real violation. Enforcement field in go-concurrency-patterns.md updated from 'judgment (ast-grep follow-up: ...)' to YAML path + agent note.
This was referenced Jun 3, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mechanical YAML count: 20 → 21 (this PR; #33 also has 7 queued — 20→27 if both land).
Hybrid pattern: ast-grep flags every
close(\$X)call; agent decides per-finding whether the enclosing function is the producer (sends into the channel — close correct) or a consumer (only receives — close is the bug).Pattern
```yaml
rule:
pattern: 'close($X)'
```
Bare pattern — producer-vs-consumer judgment needs reading the function body's send/receive direction (cross-context reasoning ast-grep can't reliably do). The agent dismisses producer-side closes (often `defer close(ch)`) and surfaces consumer-side closes as the real bug.
Test plan