Troubleshooting
Synced from network-inventory-planning
This page is a copy of docs/docs/operations/troubleshooting.md on develop, derived from that repository's code. Edit it there, then re-sync.
Symptom → cause → check → fix
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| API pod never becomes ready; startup probe fails after 60s | A migration failed or Postgres is unreachable: the server only listens after RunMigrations and the ping succeed. | Pod logs: run migrations: ..., open postgres pool: ... or ping postgres: ...; the process exits. | Fix the DSN or the migration. Behind PgBouncer set MIGRATIONS_DATABASE_URL to a direct DSN (ADR 0006). |
API exits at boot with PLANNING_MAX_STALENESS must be a positive duration | Unparsable or non-positive value. | kubectl get deploy -o yaml env. | Use a Go duration such as 10m. |
nip-projector CrashLoopBackOff with ANALYTICS_DATABASE_URL is required / KAFKA_BROKERS is required | Required variable missing. | Pod env / the analytics Secret. | Set analytics.database.* and kafka.enabled. |
nip-projector or nip-reports exits about 15s after its first dial at boot | The database is genuinely unreachable (boot retry exhausted: 5 attempts, 1+2+4+8 = 15s of backoff, plus the time each failed dial takes). | Log ... (after 5 attempts): .... | Fix the DSN or network; a single early reset is retried automatically. |
GET /v1/transfer-simulations → 503 read-models-unavailable | The API runs without DATABASE_URL. | Startup log DATABASE_URL unset. | Configure the database. |
GET /v1/transfer-simulations → 503 read-models-incomplete | BuildSnapshot refused: an empty table, a fact older than PLANNING_MAX_STALENESS, no site with all three facts, or a participating site disabled for a direction. | The problem detail names the reason (for example stale site capability for WH1). SELECT site_id, as_of FROM site_capability; and the same for site_sku_demand / published_capacity_plan. | Check the three consumers run (their group ids are set) and the upstream contexts publish; a disabled site must be re-enabled upstream (any disabled participating site refuses the whole snapshot). |
| Read models never change | The consumer's group variable is empty, KAFKA_BROKERS is unset, or the consumer is blocked on one message. | Boot log consumer disabled name=...; ERROR lines ... handling failed; retrying the same message with partition/offset; consumer lag. | Set the group id; fix the transient cause (usually the database). Deterministic problems are skipped at WARN, so a blocked partition always has an ERROR line. |
POST /v1/transfer-approvals → 503 saga-unavailable | No DATABASE_URL, or no KAFKA_BROKERS (no outbox writer). | Boot WARN KAFKA_BROKERS not configured. | Configure both. |
Approval → 503 config-incomplete | TRANSFER_PICK_PATH_ID unset or the pick CPT offset not positive (ADR 0005). | Boot WARN work release not configured. | Set config.transferPickPathId. |
Approval → 422 facts-incomplete | The current snapshot refuses (stale or missing facts), a site is missing or not enabled for its direction, the destination shows no in-window demand for the SKU, or the origin capacity cannot cover its own demand plus the quantity. | detail names the rule. | Refresh the facts or pick another pair; the approval re-validates against current facts by design. |
Approval → 422 invalid-approval | A missing field, non-positive quantity, origin = destination, missing proposalAsOf or empty policy version. | detail. | Fix the request. |
Approval → 422 proposal-expired | The 24h expiry computed at approval is not after "now" (clock problem). | Server clock. | — |
Approval → 409 idempotency-key-reused | The Idempotency-Key was used before with a different origin, destination, SKU, quantity, policy version, proposalAsOf or operator reason (the fingerprint is method + path + SHA-256 of the whole body). | SELECT transfer_id, idempotency_key FROM inter_warehouse_transfer WHERE idempotency_key = '<key>'; | Send a fresh key per logical approval. A replay with the byte-identical body answers the stored 200 with the header Idempotency-Replayed: true. |
Approval → 400 idempotency-key-required | Header missing. | — | Send Idempotency-Key. |
Approval → 503 approval-unavailable | Any other failure: reading the read models or writing the transaction. | API logs, Postgres health. | Retry with the same key once the database is healthy. |
Transfer stays ALLOCATING | inventory-storage never replied, the relay is off, or TRANSFER_REPLY_CONSUMER_GROUP is empty. | outbox_events row for TransferAllocationRequested has published_at? Reply consumer running? find_stuck_transfers with state=ALLOCATING. | Enable the relay / consumer; check inventory-storage's allocation consumer. The health check flags it after 1h. |
Transfer UNFULFILLABLE | inventory-storage rejected: ORIGIN_SITE_UNKNOWN, INSUFFICIENT_USABLE or IDEMPOTENCY_CONFLICT. | rejectionReason on GET /v1/transfers/{id}. | Terminal; approve a new transfer if appropriate. |
Transfer stays ALLOCATED | No TransferPicked from fulfillment-execution: the pick WorkDemandReleased was not consumed by wes-work-planning, or TRANSFER_FACT_CONSUMER_GROUP is empty. | outbox_events for WorkDemandReleased (key <transferId>:pick); fact consumer boot log. | Check WES knows TRANSFER_PICK_PATH_ID; enable the fact consumer. |
Transfer stays PICKED, no dispatch work | TRANSFER_DISPATCH_PATH_ID (or its offset) is not configured: the PICKED transition commits, the dispatch demand is withheld and the fact is skipped. | WARN on the fact consumer; no <transferId>:dispatch row in outbox_events. | Configure the dispatch path. There is no automatic re-release; the missing demand has to be re-issued by hand (re-publishing is not possible because the row was never written). |
Transfer stays IN_TRANSIT | Neither TransferArrived nor inventory-storage's TransferReceiptStaged arrived. | Reply and fact consumers' WARN/ERROR lines. | Check the destination receiving flow. |
| A fact is ignored | It was a replay, out of order, or for an unknown transfer_ref. A fact that failed the aggregate's checks (wrong line, site, SKU, quantity) is dead-lettered instead (row below). | WARN skipping deterministic ... with transfer_id. | Expected for replays; otherwise check the producer. |
A transfer reply or fact lands on warehouse.inventory.events.dlq / warehouse.fulfillment.events.dlq | The message could never apply: a malformed payload, or one the aggregate refuses (ErrReplyRefused: other line id, origin, SKU, allocation total, no reservation id or expiry, unknown rejection reason; ErrFactRefused: impossible quantity, foreign line, wrong site/SKU). It was dead-lettered and committed past (ADR 0013); the partition keeps flowing and the transfer keeps its state. | ERROR transfer-reply-consumer: dead-lettering a message that can never be applied (or transfer-fact-consumer: ...) with error, dlq_topic, partition, offset; DLQ headers x-dlq-consumer, x-dlq-error. | Fix the producer's payload. See "Drain a transfer DLQ" in the Runbook. |
outbox_events backlog grows | Relay disabled (OUTBOX_RELAY_ENABLED empty), broker unreachable, or one row failing (head-of-line). | SELECT id, attempts, last_error FROM outbox_events WHERE published_at IS NULL ORDER BY id LIMIT 5; | Fix the cause of last_error; the next 1s tick retries. |
ERROR outbox relay: row reached the attempt cap and is excluded from future claims; one event never reaches Kafka while later ones do | That row failed OUTBOX_MAX_ATTEMPTS sends (default 20): a poison message or a long broker outage (ADR 0016). | SELECT id, topic, event_type, key, attempts, last_error FROM outbox_events WHERE published_at IS NULL AND attempts >= 20; | Fix the cause, then UPDATE outbox_events SET attempts = 0 WHERE id = <id>; (Runbook). |
| Analytics DLQ grows | A saga-health event with an unusable payload, or one the projection rejects. | Message headers x-dlq-error, x-dlq-source-topic. | Fix the producer or projection, then re-produce the message. |
| Reports are stale | Projector down, lagging or blocked on a transient database error. | GET /reports/freshness lag_seconds; projector /readyz; consumer lag of network-inventory-planning-analytics. | Restore the analytical database; the projector resumes from its committed offset. |
| Funnel report misses a state | The relay is off, or the analytics projector lags. Every transition (approval trail, ALLOCATED, PICKED, IN_TRANSIT, ARRIVED, RECEIVED, UNFULFILLABLE) writes one TransferStateAdvanced outbox row in the transition's transaction. | SELECT event_type, count(*) FROM outbox_events WHERE event_type LIKE '%TransferStateAdvanced' AND published_at IS NULL GROUP BY 1; then SELECT to_state, count(*) FROM transfer_state_advances GROUP BY 1; | Enable the relay; check projector lag. |
GET /v1/rebalance-runs is empty | NIP_REBALANCE_SCHEDULE is unset (the default) or there is no outbox. | Boot log scheduled rebalance disabled. | Set the schedule. |
Scheduled runs are COMPLETED but proposalCount is always 0 | The catalogues are empty, no lane is Enabled, an origin has no policy for the SKU, the destination's in-window demand is 0, or the origin's headroom minus its safety stock is ≤ 0 (ADR 0015). | GET /v1/rebalance-policies, GET /v1/transfer-lanes, GET /v1/transfer-simulations (capacityHeadroom, totalDemand). A positive rejectedCount means candidates cost more than their priority benefit. | Add the policies at BOTH ends of a lane and enable the lane; raise the destination's UnitPriority or lower the lane's UnitHandlingCost. |
A catalogue PUT answers 412 version-mismatch | The If-Match revision is not the entry's current one (someone else changed it), or the entry does not exist yet. | GET the catalogue and read the entry's revision. | Re-apply the change with the current revision, or omit If-Match for a last-writer-wins PUT. |
TransferStuckDetected repeats for the same transfer | Expected: every tick re-reports every transfer still over its threshold, and every API replica runs its own ticker. | — | Deduplicate downstream by transfer_id. |
| Health check never fires | NIP_HEALTH_CHECK_INTERVAL=0, an invalid NIP_STUCK_THRESHOLDS, or no outbox. | Boot log saga health check disabled / invalid stuck thresholds. | Fix the value; an unknown state name disables the whole check. |
MCP tool returns read-side-unavailable | cmd/mcp runs without DATABASE_URL. | MCP boot log. | Configure the database. |
There is no circuit breaker and no 412 anywhere in this service: NIP makes no
outbound HTTP calls and uses no ETags.
Problem types
Every REST error is application/problem+json with
type = https://warehouse.example/problems/<slug>
(internal/adapters/inbound/http/handler.go, transfers_read.go,
reports_handler.go).
| Slug | Status | Route(s) |
|---|---|---|
invalid-request | 400 | POST /v1/transfer-proposal-runs, POST /v1/transfer-approvals, catalogue PUTs (malformed JSON or unknown field) |
invalid-planning-snapshot | 422 | generate (missing asOf, mixed position snapshot) |
read-models-unavailable | 503 | GET /v1/transfer-simulations |
read-models-incomplete | 503 | GET /v1/transfer-simulations |
saga-unavailable | 503 | approve |
idempotency-key-required | 400 | approve |
idempotency-key-reused | 409 | approve |
config-incomplete | 503 | approve |
invalid-approval | 422 | approve |
facts-incomplete | 422 | approve |
proposal-expired | 422 | approve |
approval-unavailable | 503 | approve |
rebalance-runs-unavailable | 503 | GET /v1/rebalance-runs |
invalid-limit | 400 | every paged GET (limit outside 1–500) |
invalid-cursor | 400 | every paged GET (cursor does not decode) |
unknown-query-parameter | 400 | every paged GET (a parameter it does not declare, e.g. the retired offset, after, nextToken) |
idempotency-key-required / idempotency-key-invalid | 400 | every POST (missing key; not 1-128 printable ASCII) |
idempotency-key-reused | 409 | every POST (same key, different method/path/body) |
idempotency-unavailable | 503 | every POST on an instance without its idempotency store (no database) |
catalogue-unavailable | 503 | GET/PUT /v1/rebalance-policies, GET/PUT /v1/transfer-lanes (no database, or the store failed) |
invalid-if-match | 400 | catalogue PUT (If-Match is not a revision) |
invalid-catalogue-entry | 422 | catalogue PUT (missing key, negative value, TargetStock below SafetyStock, lane to itself) |
version-mismatch | 412 | catalogue PUT (If-Match is not the current revision) |
concurrent-modification | 409 | catalogue PUT (lost a write race on the same revision) |
read-side-unavailable | 503 | GET /v1/transfers, GET /v1/transfers/{id} |
invalid-query | 400 | GET /v1/transfers (unknown state) |
transfer-not-found | 404 | GET /v1/transfers/{id} |
invalid-report-range | 400 | nip-reports /reports/* |
invalid-report-limit | 400 | /reports/stuck-transfers |
report-store-error | 500 | nip-reports /reports/* |
MCP tools report the same slugs as the prefix of an isError result
(invalid-query: ..., transfer-not-found: ..., read-side-unavailable: ...,
read-models-unavailable: ..., read-models-incomplete: ...), and
internal-error for anything untyped.