# Troubleshoot vehicle state

Use this flow when a vehicle is duplicated, missing, stored incorrectly, or has mismatched key or
ownership state. Avoid direct production SQL edits before tracing the responsible transition.

## Evidence to collect

- Commits for garage, vehicle keys, core, dealership, and persistence resources
- Plate, citizen identifier, garage, state before/after, and relevant logs from a test vehicle
- Local schema/config diffs and resource restart timing
- Whether the error follows purchase, store, retrieve, impound, reconnect, or restart

## Safe diagnostic

1. Reproduce one transition on staging and query the record before and after it.
2. Trace every writer for the vehicle state/garage fields at the pinned commits.
3. Normalize plate handling at system boundaries and verify entity existence/ownership server-side.
4. Test without local patches to separate upstream behavior from integration conflicts.

## Fix

Make one server-authoritative resource own each transition and align its schema/config with the
deployed commit. Add logging around failed transitions and test the complete vehicle lifecycle.

## Rollback

Restore the previous compatible resource set and database snapshot. For a single test record, use a
reviewed, targeted correction only after capturing its prior values.

## Sources

- [qb-garages upstream](https://github.com/qbcore-fivem/qb-garages)
- [qb-garages issue tracker](https://github.com/qbcore-fivem/qb-garages/issues)
