## final-review-fix (2026-07-08 15:41 CST)

### Changes

- Made realtime duplicate suppression source-aware in `go/vehicle-gateway/internal/stats/daily_metric.go` by keying the in-memory mileage cache with `vin + protocol + source_key + stat_date`, so identical mileage from different sources is retained while same-source repeats are still skipped.
- Added optional previous-baseline querying and per-source/day caching in `Writer`; realtime candidates now:
  - become `NO_PREVIOUS_BASELINE` with reason `missing_previous_source` when the same-source previous-day candidate is absent,
  - use previous-day `latest_total_mileage_km` as `first_total_mileage_km`,
  - compute `daily_mileage_km` from previous-day baseline when present,
  - become `INVALID_DELTA` with reason `outside_daily_range` when the delta is negative or above `maxSelectedDailyMileageKM`.
- Added generic stale-final cleanup to `ProjectDailyMileage` in `go/vehicle-gateway/internal/stats/source_mileage.go` so `vehicle_daily_mileage` is deleted when no candidate remains selected for the exact `(vin, stat_date, protocol)` target.
- Changed `BACKFILL_METHOD` default from `scan` to `last_diff` in `go/vehicle-gateway/cmd/stats-backfill/main.go`.
- Expanded regression coverage for source-aware realtime dedupe, realtime baseline/no-baseline behavior, projector cleanup SQL, stale-final cleanup through backfill, and the backfill method default.

### Test Results

- `cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway && go test ./internal/stats -run 'TestWriter|TestProjectDailyMileage|TestSource' -count=1`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats	0.435s`
- `cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway && go test ./cmd/stats-backfill ./internal/stats -count=1`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/stats-backfill	0.643s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats	0.279s`
- `cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway && go test ./... -count=1`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/capacity-check	0.419s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/gateway	0.397s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/history-writer	0.728s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/load-sim	0.698s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/nats-fast-writer	0.688s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/nats-kafka-bridge	0.683s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/realtime-api	0.574s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/stat-writer	0.534s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/cmd/stats-backfill	0.634s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/capacity	0.834s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope	0.738s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/eventbus	0.758s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/gateway	0.483s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/health	0.384s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/history	0.502s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/identity	0.631s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/loadsim	0.640s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/metrics	0.626s`
  - `?   	lingniu-vehicle-ingest/go/vehicle-gateway/internal/observability	[no test files]`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/gb32960	0.622s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/jt808	0.371s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/yutongmqtt	0.384s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/realtime	0.496s`
  - `ok  	lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats	0.443s`
  - `?   	lingniu-vehicle-ingest/go/vehicle-gateway/internal/topics	[no test files]`
