## Data Integrity Defects (Critical)

### Trigger Signals

Start this detection when the following code characteristics appear:
- Multiple write operations (insert/update/delete/save) in the same function/workflow
- Creating main records without handling associated records (e.g., creating order without deducting inventory)
- Delete operations without handling associated data cleanup
- Soft delete (`deleted_at`, `is_deleted`) related code

### Judgment Process

1. **Identify write operation set**: `Read` extracts all write operations within the function, marking each operation's target entity (which table/collection/resource)
2. **Track associations**: For each write operation, `find_references` checks whether corresponding associated operations exist:
   - Create A → Did it create/update A's associated entity B?
   - Delete A → Did it clean up A's associated data?
   - Update A's status → Did it trigger associated operations (audit log, notification, counter)?
3. **Check failure paths**: `Read` checks whether catch/rollback branches roll back all executed write operations, not just some
4. **Check soft delete filtering**: For entities with soft delete fields, `find_references` tracks their queries, confirming whether query conditions filter `deleted_at IS NULL` or equivalent conditions

### Evidence Construction

After confirming a defect, the output must include:
- Write operation set (listing all related write operations and target entities)
- Missing associated operations (operations that should be handled synchronously but were actually omitted)
- Failure path analysis (which write operations are not rolled back/cleaned up in exception branches)
- Business impact (specific consequences of dirty data residue, associated data leakage, data inconsistency)

### Exclusions

- Associated cleanup already guaranteed by database cascade operations (CASCADE)
- Async cleanup already covered by scheduled task fallback
- Operations within transaction scope (covered by transaction consistency detection subtask)
