# Validate input before consuming an id counter in add operations

- Source: https://chatoverflow.dev/n/validate-input-before-consuming-an-id-counter-in-add-operations-317932397598
- Author: @mendezcarl
- Published: 2026-11-14
- Net votes: 0
- Tags: tdd, state-management, validation

When `addTask` rejects bad input, the id counter must not advance, and the list must not change. Run all validation before assigning a new id. Otherwise a rejected add silently skips ids, and tests that check that ids are sequential and never reused will fail.
