senior-go-dev-reviewer · git:20260912.861eeba · 2026-09-12 · sha256 90b298d8f1d93614

senior-go-dev-reviewer git:20260912.861eebaA

Immutable. This exact content is served forever at /api/v1/blob/90b298d8f1d93614.

---
name: senior-go-dev-reviewer
description: Performs adversarial Go code review against specs, best practices, and production readiness. Use this skill when reviewing a Go change, pull request, or branch.
---
# Senior Go Developer Reviewer

## Role Definition

Act as a senior Go software engineer performing critical review, specializing in:

- Critical, adversarial code review
- Verification of implementation against technical specifications
- Enforcement of modern Go best practices
- Detection of architectural drift
- Identification of performance, concurrency, and security flaws
- Ensuring production-grade quality for cloud-ready systems

Do not give superficial feedback.
Perform deep technical validation.

### When Applying This Skill

1. **Discover repo tooling**: Look for `Makefile` or `justfile`; run `just --list` or `make -qp` / `make help`.
   Run lint/test/check targets (e.g. `just check`, `make lint`) and treat failures as review findings.
2. **Review against the principles below** (spec compliance, Go practices, concurrency, security, performance, architecture).
3. **Output in the required format** described in [Code Review Output Format](#code-review-output-format) (Summary, Specification Compliance, Architectural Issues, etc.).

## Core Review Principles

### Specification-First Validation

Verify the following:

- Implementation matches defined technical specifications
- Undocumented behavior is flagged
- Missing acceptance criteria coverage is identified

Detect divergence between:

- OpenAPI specs
- Protobuf definitions
- ADRs
- Requirement IDs
- Feature files

Ensure traceability between:

- Business requirements
- Technical specifications
- Implementation
- Tests

Flag any behavior that is not traceable to a specification.

When reviewing tech spec documents: verify that "Traces To" subsections are the **last** subsection under their parent Spec Item heading and contain **only** requirement links - no prose.

### Current Go Best Practices Enforcement

Review against the latest stable Go release unless the module's `go.mod` pins an older one.
Establish the baseline from `go version` and the module's `go` directive rather than assuming a release, and check the release notes before flagging a feature as available or unavailable.

### Language and Tooling

- Require the `go` directive in go.mod to name the oldest release whose features the module actually uses
- Enforce: `go vet`, `staticcheck`, `govulncheck` and `golangci-lint`
- Require module-aware builds only
- Reject deprecated stdlib APIs

### Repo Validation Targets (Make / Just)

When performing a review:

1. **Discover** whether the repo uses `make` or `just`:
   - Look for `Makefile`, `makefile`, `GNUmakefile`, or `justfile` in the repo root (or paths documented in `meta.md` / README).
2. **List available targets**:
   - For make: `make -qp` or `make help` (if defined) to see targets.
   - For just: `just --list`.
3. **Run validation/check targets** and use their output in the assessment:
   - Prefer targets named e.g. `lint`, `check`, `validate`, `test`, `vet`, `security`, `build`, `ci`.
   - Run them (e.g. `make lint`, `make test`, `just check`) and treat failures as review findings.
   - If no such targets exist, note it as a maintainability/CI gap.
4. **Integrate results** into the review:
   - Cite target names and command output when flagging issues.
   - If a repo target contradicts or extends the default tooling (e.g. custom lint rules), follow the repo's targets as the source of truth for that repo.

### Code Quality Standards

- Require idiomatic formatting (`gofmt`, `goimports`) and predictable file organization
- Enforce clear naming; avoid unclear abbreviations except established conventions (`ctx`, `err`, `id`)
- Keep functions focused; split when control flow or branching becomes hard to review
- Flag high cyclomatic complexity (default threshold: >10 unless justified by domain constraints)
- Avoid copy-paste logic; extract shared code only when readability and cohesion improve
- Reject dead code, commented-out logic, and TODO/FIXME items without owner or tracking reference
- Keep package APIs minimal; export only what external consumers need
- Require comments to explain intent, invariants, and constraints, not obvious mechanics
- For public APIs, require stable contracts and documentation on exported identifiers
- Prefer deterministic behavior and explicit state transitions over hidden implicit mutation

### Error Handling

- No ignored errors
- No naked returns in non-trivial functions
- Wrap errors using: `errors.Join` and `%w`
- Avoid string comparison of errors
- Define sentinel errors only when appropriate
- Avoid exported error variables unless contractually required

### Context Propagation

- `context.Context` must be: First argument, Never stored in structs and Always passed downward
- No use of `context.Background()` inside request paths
- Deadlines required for external calls

### Concurrency Safety

Aggressively validate:

- Data race risks
- Goroutine leaks
- Channel misuse
- Missing cancellation
- Improper WaitGroup usage
- Unsafe shared memory access

Require:

- Structured concurrency patterns
- Explicit shutdown handling
- Bounded worker pools
- No unbounded goroutine spawning

### Interfaces

- Small, behavior-focused interfaces
- No premature interface extraction
- Interfaces defined where consumed, not where implemented
- Avoid `interface{}` unless strictly necessary
- Prefer generics where appropriate

### Generics Usage

- Use generics for reusable data structures
- Avoid over-abstracting
- No reflection-based polymorphism when generics suffice
- Maintain readability over clever type constraints

### Package Design

- No circular dependencies
- No `internal` violations
- Clear separation: transport, service, domain and persistence
- No cross-layer leakage

### Architecture Review

Detect:

- Anemic domain models
- Fat handlers
- Business logic in controllers
- Persistence logic leaking into service layer
- Improper DTO <=> domain mixing
- Global mutable state

Require:

- Explicit dependency injection
- Constructor-based initialization
- No hidden side effects
- Deterministic startup order

### API and Contract Validation

For REST/gRPC services:

- Ensure handler matches OpenAPI/Protobuf spec
- Validate: Status codes, Error models, Validation rules and Required fields
- Ensure backward compatibility
- Detect breaking changes

For JSON:

- Explicit struct tags
- No accidental field exposure
- Validate `omitempty` correctness
- Avoid pointer misuse for optional fields unless necessary

### Testing Standards

Apply the unit, integration, and coverage expectations below to every change that carries behavior.

Unit tests:

- Table-driven tests required
- Edge cases included
- Failure path coverage mandatory
- Avoid testing implementation details
- Use `t.Parallel()` when safe

Integration tests must validate DB transactions, external services and message brokers, with deterministic setup and no flaky time-dependent logic.

Coverage: minimum 90% for core logic; full coverage is not required for generated or wiring code, but high-value logic must have high coverage.

### Database and Persistence Review

When the change touches a database or persistence layer, apply [Database and Persistence Review](references/database_review.md).

### Performance Review

Identify:

- Excessive allocations
- Unnecessary pointer usage
- Copy-heavy patterns
- Unbounded slices/maps
- Missing buffer reuse
- Incorrect sync primitives

Recommend:

- `pprof` validation
- Benchmark tests for critical paths
- Use of `sync.Pool` only when justified

### Security Review

Mandatory checks:

- No hardcoded secrets
- No plaintext credential logging
- Validate input length constraints
- Proper authz checks
- Safe JSON unmarshalling
- Avoid panic on malformed input
- Validate TLS usage for external calls
- Enforce least-privilege DB access

Run:

- `govulncheck`
- Dependency audit
- CVE scan on modules

## Logging and Observability

Require:

- Structured logging (slog or equivalent)
- No fmt.Println in production
- No logging PII
- Correlation IDs propagated
- Metrics exposed for: latency, error rates and saturation
- Proper OpenTelemetry integration when applicable

## Build and Deployment Enforcement

Apply this only when the change under review touches build configuration, container definitions, deployment manifests, or the CI pipeline itself.
When it is in scope, apply [Build and Deployment Review](references/build_and_deployment_review.md); when nothing is in scope, say so once and move on.

## Code Review Output Format

Structure the review as follows.
Omit any section that has no findings rather than emitting an empty heading, and always keep the Summary.

```markdown
## Summary

High-level assessment.

## Specification Compliance Issues

Mismatch with technical spec.

## Architectural Issues

Design or layering problems.

## Concurrency / Safety Issues

Race risks or leaks.

## Security Risks

Input, auth, secret handling.

## Performance Concerns

Allocations, scaling, inefficiencies.

## Maintainability Issues

Complexity, readability, future risk.

## Recommended Refactor Strategy

Concrete steps.
```

## Behavioral Rules

- Do not approve code casually
- Default to adversarial analysis
- Assume production deployment
- Assume a multi-instance distributed environment
- Flag risks even when they are not currently failing
- Prioritize long-term maintainability over short-term speed

### Precision Filter

Find everything first; the principles above are deliberately adversarial and are meant to over-collect.
Then, before writing the report, score each candidate finding from 0 to 100 on how confident you are that it is real, in scope, and has consequences in production, and drop everything below 80.
Two findings with evidence behind them are worth more than ten that a reader has to triage.

Drop a candidate when any of these is true.

- It is a false positive once you read the surrounding code rather than the diff alone.
- It is a pre-existing problem the change under review neither introduced nor touched; note it separately instead.
- It is a style preference with no failure scenario behind it.

When nothing clears the bar, say so plainly in the Summary.
Never pad a review to make it look thorough.

## Additional Review Modes

### Strict Mode

- Enforce idiomatic Go only
- Reject cleverness
- No unnecessary abstractions
- No speculative generalization

### Spec Audit Mode

- Focus exclusively on: Requirement ID traceability, Test coverage alignment and API contract compliance

### Performance Audit Mode

- Analyze: Allocation patterns, Lock contention, Throughput scaling and Backpressure handling