P6 C Carrier Rule Cutover
Source: docs/runbooks/p6-c-carrier-rule-cutover.md
# P6-C Carrier Rule Cutover Runbook
Use this runbook to safely switch SHIP carrier-rule loading from hardcoded defaults to `ref.carrier_rules`.
## Scope
Datasets covered by this cutover:
- `CLAIM_WINDOW` (dispute deadlines)
- `DIM_FACTOR` (`STANDARD` divisor defaults)
- `SEVERITY_THRESHOLD` (`AMOUNT_VARIANCE` threshold baseline)
## Preconditions
- P6-C seed lane merged (`ref.carrier_rules` baseline rows present)
- Runtime lane merged (`SHIP_CARRIER_CONFIG_SOURCE` support in loader + ingest + detector)
- Staging environment has `DATABASE_URL` and worker/API deployment access
## Step 1: Pre-cutover parity check (staging)
Run the parity gate script against staging DB:
```bash
DATABASE_URL="<staging-db-url>" \
npx tsx scripts/check-ship-carrier-config-parity.ts
```
Expected result:
- Exit code `0`
- `status=OK`
- All datasets show `MATCH`
If exit code is `1`, stop and resolve mismatches in `ref.carrier_rules` first.
## Step 2: Dual mode soak
Set:
```bash
SHIP_CARRIER_CONFIG_SOURCE=dual
```
Deploy API + worker, then soak for at least one business cycle.
Monitor logs for:
- `[CarrierConfigLoader] Parity mismatch between hardcoded and ref DB configs`
- `[CarrierConfigLoader] DIM factor parity mismatch between hardcoded and ref DB`
- `[CarrierConfigLoader] Severity threshold parity mismatch between hardcoded and ref DB`
No mismatch logs should appear during soak.
## Step 3: Cut over to DB mode
Set:
```bash
SHIP_CARRIER_CONFIG_SOURCE=db
```
Deploy API + worker, then validate:
- SHIP upload + finding generation completes
- dispute deadlines remain expected for FEDEX/UPS
- DIM billable weight behavior matches known samples
## Step 4: Rollback plan
If issues appear:
```bash
SHIP_CARRIER_CONFIG_SOURCE=hardcoded
```
Redeploy and open a follow-up for parity/data correction before reattempting DB mode.
## Optional ongoing guard
Schedule the parity script daily/weekly in staging:
```bash
DATABASE_URL="<staging-db-url>" \
npx tsx scripts/check-ship-carrier-config-parity.ts --json
```
Alert on non-zero exit.