跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
开发与测试

go-concurrency-review

Review Go code for concurrency safety and goroutine lifecycle issues including race conditions, deadlocks, goroutine leaks, mutex misuse, and context propagation. Trigger when code contains go func, channels, sync primitives, WaitGroup, errgroup, or goroutine lifecycle management. Use for concurrency-focused review of Go projects.

johnqtcg · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add johnqtcg/awesome-skills --skill go-concurrency-review

技能说明


name: go-concurrency-review description: Review Go code for concurrency safety and goroutine lifecycle issues including race conditions, deadlocks, goroutine leaks, mutex misuse, and context propagation. Trigger when code contains go func, channels, sync primitives, WaitGroup, errgroup, or goroutine lifecycle management. Use for concurrency-focused review of Go projects. allowed-tools: Read, Grep, Glob, Bash(go build*), Bash(go vet*), Bash(go test -race*)

Go Concurrency Review

Purpose

Identify concurrency defects and goroutine lifecycle issues in Go code. Scope: race conditions, deadlocks, goroutine leaks, mutex misuse, context propagation, and lifecycle management.

This skill does NOT cover: security vulnerabilities, performance optimization, code style, test quality, error handling patterns, or business logic — those belong to sibling vertical skills.

When To Use

  • Code contains go func, goroutine creation
  • Code uses channels, sync primitives (Mutex, RWMutex, WaitGroup)
  • Code uses errgroup, singleflight
  • Code involves context propagation and cancellation
  • Code contains graceful shutdown logic

When NOT To Use

  • Security vulnerabilities → go-security-review
  • Performance optimization (lock contention as perf issue) → go-performance-review
  • Code style/lint → go-quality-review
  • Error handling correctness → go-error-review
  • Business logic → go-logic-review

Mandatory Gates

1) Execution Integrity Gate

Never claim go test -race ran unless it actually produced output. If not run: state reason + exact command.

2) Go Version Gate

Read go.mod for go directive. Key version gates:

  • errgroup.SetLimit (Go 1.20+)
  • sync.OnceValue / sync.OnceFunc (Go 1.21+)
  • Loop variable fix (Go 1.22+) — do NOT flag loop variable capture in Go ≥ 1.22

3) Anti-Example Suppression Gate

MUST quote specific code evidence satisfying precondition. Category match alone insufficient.

Embedded anti-examples:

  • "Race condition on this map" — when map is created and consumed within single function scope or single goroutine. Cite the creation site and all access sites to confirm single-goroutine usage.
  • "Should use errgroup instead of WaitGroup" — when no error propagation is needed and goroutine count is small and fixed (e.g., 2-3 known goroutines).
  • "Missing context propagation" — when function is synchronous, short-lived, performs no I/O, and has no cancellable work.
  • "Loop variable capture bug" — when project uses Go ≥ 1.22 (check go.mod). The loop variable fix makes v := v unnecessary.
  • "Should add mutex" — when data structure is only written during initialization (before any goroutine launch) and only read afterward.

4) Generated Code Exclusion Gate

Exclude: *.pb.go, *_gen.go, mock_*.go. Note excluded files in Execution Status.

Workflow

  1. Define scope — files/diff under review. Apply Generated Code Exclusion Gate.
  2. Gather evidence — read changed files, identify concurrency patterns: go func, chan, sync.*, errgroup, context.WithCancel, select, time.After.
  3. Load references — always load go-concurrency-patterns.md.
  4. Run go test -race if feasible — report output. If not feasible, state reason + exact command.
  5. Evaluate ALL 14 checklist items → apply suppression gate → format output.

Grep-Gated Execution Protocol

This skill uses mechanical grep pre-scanning to guarantee zero missed checklist items. 13 of 14 items are grep-gated; 1 is semantic-only.

Execution Order

  1. Identify target files (from dispatch prompt, or write raw snippet to $TMPDIR/review_snippet.go)
  2. Run grep for all grep-gated checklist items against target files
  3. HIT → run semantic analysis to confirm or reject
  4. MISS → auto-mark NOT FOUND, skip semantic analysis
  5. For compound patterns: run all grep patterns, apply AND/AND NOT logic
  6. For semantic-only items (item 13): full model reasoning
  7. Report only FOUND items

Grep Audit Line

Include in Execution Status: Grep pre-scan: X/13 items hit, Z confirmed as findings (1 semantic-only)

Compound Pattern Protocol

Several items share the trigger go\s+func but have different secondary conditions:

  • Item 8 (Unrecovered panic): go\s+func HIT AND recover() NOT found in goroutine body
  • Item 12 (Loop variable capture): go\s+func HIT AND inside for loop AND Go version < 1.22
  • Item 14 (Unbounded goroutines): go\s+func HIT AND NONE of SetLimit|semaphore|maxConcurrency|worker.*pool|make(chan struct found in same scope

Run go\s+func grep ONCE, then apply all compound conditions to the results.

Concurrency Checklist (14 Items)

All High severity unless marked (Medium).

#ItemCode Pattern TriggersGrep Pattern
1Goroutine leakgo func without context cancel or channel close on return pathgo\s+func|go\s+\w+\(
2Data raceShared map/slice/var written from multiple goroutines without syncgo\s+func (compound: ALSO check shared variable write in closure — semantic confirmation required)
3Mutex misuseMissing defer mu.Unlock(), lock copying (value receiver on mutex-holding struct), inconsistent RWMutexsync\.Mutex|sync\.RWMutex
4Channel deadlockUnbuffered send without receiver, missing close(), select without default on full channelmake\(chan|<-chan|chan<-|<-\s*\w+
5Missing errgroupMultiple goroutines coordinated without error propagation — should use errgroup.Groupsync\.WaitGroup|wg\.
6Missing context propagationcontext.Background() where parent ctx available; context.Value for request-scoped datacontext\.Background\(\)|context\.TODO\(\)|context\.Value
7sync.Pool / sync.Once misusePool without Reset before Put; Once panic caching (Go < 1.21, use OnceValue after)sync\.Pool|sync\.Once
8**Unrecov
阅读完整来源 ↗