app-state-fix
App State Fix
Target: $ARGUMENTS, or the current project root minus vendored and generated code when empty.
An implicit state machine is a lifecycle whose legal states and transitions live only in the programmer's head: spread across booleans (isLoading, isError, hasData), nullable fields that must agree, status strings compared ad hoc, or effects that set each other off. It works until two pieces drift and the app lands in an impossible state, one no transition was meant to produce.
1. Sweep for signals
Each hit is a lead, not a finding. Search every category:
- Flag clusters: two or more booleans on one owner (component state, store slice, class, DB row) describing one lifecycle:
isLoading/isError/isSuccess,isOpen/isClosing. - Paired nullables: fields that must be set or empty together:
data+error,startedAt+finishedAt,user+token. - Loose status fields:
status/phase/mode/steptyped as plain string or number and compared by literal in more than one place. - Compound guards: conditions over several flags,
if (a && !b || c), especially when repeated with variations. - Cascades: effects, watchers, listeners, or callbacks that set state which triggers another (
useEffectchains, signals, DB triggers, job status updates). - Persisted lifecycles: columns that jointly encode one (
status,deleted_at,approved_by,retry_count). - Explicit machines: enum + transition table, XState, exhaustive reducer. Record them as the baseline the codebase already has.
Done when every category has been searched in scope and every hit is a candidate or dismissed with a reason. Expect many: a non-trivial app with only a handful of candidates usually means a category was skimmed, so re-run that category before moving on.