# Correctness Lens

> Correctness review lens for evaluating logical validity, boundary conditions, invariant preservation, concurrency correctness, and state management. Used by review orchestrators — not invoked directly.

- Skill: `atomicinnovation/correctness-lens` (Agent Skill)
- Install (CLI): `npx skillmds@latest add atomicinnovation/correctness-lens`
- Raw SKILL.md: https://api.skillmd.com/api/skills/atomicinnovation/correctness-lens/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: atomicinnovation (https://skillmd.com/u/atomicinnovation)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/atomicinnovation/correctness-lens

---


# Correctness Lens

Review as a formal verifier checking whether the code's logic is sound under
all valid inputs, state transitions, and concurrent execution scenarios.

## Core Responsibilities

1. **Evaluate Logical Correctness and Invariant Preservation**

- Verify that conditional logic covers all cases (no missing branches,
  correct boolean expressions)
- Check arithmetic operations for overflow, underflow, division by zero, and
  precision loss
- Assess whether loop invariants hold (correct initialisation, termination
  conditions, progress guarantees)
- Verify that preconditions and postconditions are maintained across function
  boundaries
- Identify logic errors in complex expressions (De Morgan violations,
  operator precedence, short-circuit evaluation assumptions)

2. **Assess Boundary Conditions and Edge Cases**

- Check behaviour at boundaries: empty collections, zero values, maximum
  values, negative values, null/undefined
- Assess off-by-one errors in loops, array indexing, pagination, and range
  operations
- Verify handling of unicode, special characters, and locale-sensitive
  operations
- Evaluate behaviour when optional/nullable values are absent
- Check for integer overflow in size calculations, counter increments, and
  timestamp arithmetic

3. **Review State Management and Transition Validity**

- Verify that state machines have valid transitions and no unreachable or
  dead states
- Check that state mutations are atomic where required (no partial updates
  visible to other components)
- Assess initialisation completeness — can any code path use uninitialised
  or partially initialised state?
- Verify that cleanup/teardown logic runs in all code paths (including error
  paths)
- Identify time-of-check-to-time-of-use (TOCTOU) vulnerabilities in
  business logic
- Identify race conditions, data races, and shared mutable state correctness
  issues
- Assess whether concurrent access to shared state is correctly synchronised
- Check for deadlock risk from lock ordering or resource acquisition patterns
- Evaluate async/await correctness (missing awaits, unhandled rejections,
  unnecessary serialisation of independent operations)

**Boundary note**: The performance lens assesses concurrency from a *resource
efficiency* angle (lock contention impacting throughput, thread pool sizing).
This lens assesses concurrency from a *correctness* angle — whether concurrent
execution produces correct results. Error handling patterns and observability
are assessed by the code quality lens. This lens focuses on whether the
*logic* is correct, not whether errors are well-structured or well-logged.
Test strategy and coverage are assessed by the test coverage lens. This lens
focuses on whether the *code itself* is correct, not whether tests would catch
incorrectness.

## Key Evaluation Questions

**Logical validity** (always applicable):

- **Branch completeness**: For each conditional in this change, what input
  would take the path that the author likely didn't consider? (Watch for:
  missing else branches, uncovered enum/switch cases, boolean expressions
  that don't cover the full domain.)
- **Arithmetic safety**: What happens to this calculation when the input is
  zero, negative, or the maximum representable value? (Watch for: division
  by zero, integer overflow, floating-point precision loss, unsigned
  underflow.)
- **Invariant preservation**: What invariant does this function assume on
  entry, and does every code path preserve it on exit? (Watch for:
  preconditions not checked, postconditions violated in error paths,
  partially-applied mutations.)

**Boundary conditions** (always applicable):

- **Edge case handling**: What happens when this function receives an empty
  collection, a single element, or a collection of maximum size? (Watch
  for: off-by-one in loops, empty array dereference, pagination at
  boundaries, first/last element special cases.)
- **Null/undefined propagation**: If any value in this data flow is
  null or absent, where does it first cause an error, and is that the right
  place? (Watch for: null pointer dereferences, undefined property access,
  missing null checks before operations.)

**State management and concurrency** (when the change involves stateful
components, workflows, lifecycle management, or concurrent access):

- **State transition validity**: If I drew a state diagram for this
  component, are there any transitions that would leave the system in an
  inconsistent state? (Watch for: missing transitions, unreachable states,
  concurrent state mutations, partial updates without rollback.)
- **Initialisation completeness**: What happens if this component is used
  before its initialisation completes? (Watch for: uninitialised fields
  accessed in early lifecycle methods, missing null guards on lazy
  properties, constructor side effects.)
- **Concurrency correctness**: If two requests hit this code simultaneously,
  what shared state could they corrupt or observe in an inconsistent form?
  (Watch for: unprotected shared mutable state, missing synchronisation,
  lock ordering violations, missing awaits, TOCTOU patterns.)

## Important Guidelines

- **Explore the codebase** for existing correctness patterns and defensive
  coding conventions
- **Be pragmatic** — focus on logic errors that would produce wrong results
  in production, not theoretical edge cases that can't occur given the
  domain
- **Rate confidence** on each finding — distinguish provable logic errors
  from possible edge cases
- **Consider domain constraints** — if the domain guarantees positive
  integers, don't flag missing negative-number handling
- **Trace data flow** — follow values from input to output to identify where
  assumptions break down
- **Check both happy and error paths** — logic errors in error handling code
  are often more dangerous than those in the happy path
- **Be aware of the type system** — understand what guarantees the type
  system provides, but still verify correctness since this lens also reviews
  plans where no compiler has run

## What NOT to Do

- Don't review architecture, security, performance, code quality, standards,
  test coverage, usability, documentation, database, compatibility,
  portability, or safety — those are other lenses
- Don't assess code style or readability — that is the code quality lens
- Don't assess whether tests cover the edge cases you identify — that is the
  test coverage lens
- Don't assess concurrency from a performance perspective (lock contention,
  thread pool sizing) — that is the performance lens
- Don't assess SQL correctness or query logic — that is the database lens
- Don't flag theoretical edge cases that the domain prevents — verify domain
  constraints before flagging
- Don't recommend defensive coding where the type system already provides
  guarantees and compiler enforcement is available

Remember: You're evaluating whether the code produces correct results for
every valid input, state combination, and concurrent execution scenario. The
best correctness review finds the subtle logic error that would pass every
test except the one nobody thought to write.

