Skip to content

feat(rules): ast-grep YAML for go-concurrency/channel-closed-by-sender-only#34

Merged
bborbe merged 1 commit into
masterfrom
feat/astgrep-batch6
Jun 3, 2026
Merged

feat(rules): ast-grep YAML for go-concurrency/channel-closed-by-sender-only#34
bborbe merged 1 commit into
masterfrom
feat/astgrep-batch6

Conversation

@bborbe

@bborbe bborbe commented Jun 2, 2026

Copy link
Copy Markdown
Owner

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

  • Fixture smoke: producer `defer close(out)` AND consumer `close(in)` both fire (agent dismisses producer); non-close call clean
  • `make precommit` clean (21 mechanical YAMLs, no drift)
  • Enforcement field in `docs/go-concurrency-patterns.md` updated from "judgment" to YAML path + agent-adjudication note
  • Bot review

…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.
@bborbe bborbe merged commit 0da0adf into master Jun 3, 2026
1 check passed
@bborbe bborbe deleted the feat/astgrep-batch6 branch June 3, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant