Skip to main content

Troubleshooting

Synced from outbound-shipping

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.

Each entry is a symptom, the cause in the code, how to check it and the fix. Source: cmd/api/config.go, internal/application/usecases/*.go, internal/adapters/inbound/kafka/*.go, internal/adapters/inbound/http/errors.go, internal/adapters/outbound/outbox/relay.go, migrations/.

Most consumer problems are visible in one log line per message: event processed with outcome applied, duplicate or ignored. ignored is not an error; it means the use case found nothing to do, and the causes are listed below.

Boot​

SymptomCauseCheckFix
api exited with error naming DATABASE_URL is required, KAFKA_BROKERS is required or <X>_CONSUMER_GROUP is requiredloadConfig collects every missing variable and fails oncethe joined error lists each missing nameSet them all; see Configuration. There is no default and no in-memory fallback.
run migrations: ... at bootthe DSN cannot run DDL (a pooler in transaction mode, a read-only role) or an earlier run left the schema dirtythe error text; SELECT * FROM schema_migrationsProvide MIGRATIONS_DATABASE_URL with a direct connection and a role that owns the schema. If dirty = true, repair the schema by hand and reset the version; there is no automatic down-migration.
cmd/mcp exits DATABASE_URL is required: this context runs on real Postgresno DATABASE_URLthe exit logSet it; cmd/mcp reads no other mandatory variable.
Process up, /readyz returns 503 dependency-unavailablePostgres ping failed or the first broker in KAFKA_BROKERS does not accept TCPthe problem detail names postgres and/or kafka; the log line readiness: dependency is not readyFix the network or credentials. List a reachable broker first in KAFKA_BROKERS: only the first one is dialled.
/readyz is 200 but nothing is consumedreadiness dials TCP only, and consumers connect lazilykafka reader error; retrying lines with consumer, topic, detailFix the group join or ACL; a topic that does not exist yet is retried silently by kafka-go but logged by the error logger.

A load is not planned, or does not progress​

SymptomCauseCheckFix
PackageManifested logged outcome=ignored, no package and no loadthe manifest lacks site_id or cpt (producer fields are additive and omitted when unknown, ADR 0003), or the site has no schedule copy, or the manifest's cutoff matches no entry of the scheduleSELECT * FROM cpt_schedules WHERE site_id = ...; compare the manifest's cpt instant, converted to the schedule's timezone, with each entry's local_time and days_of_week (the match is on the local HH:MM and, when listed, the weekday)Make the producer send site_id and cpt; make sure CPTScheduleChanged for the site was consumed (CPT_CONSUMER_GROUP). The package is not stored when ignored, but the event's CloudEvents id is claimed in processed_events (an ignored outcome commits), so replaying the same message is a duplicate. Recover by having the producer re-emit the manifest with a new id, or by deleting that row: DELETE FROM processed_events WHERE consumer = 'outbound-shipping-fulfillment' AND event_id = '<id>' and then replaying it.
LoadDoorAssigned never raisedthe appointment is not OUTBOUND, names no cpt_id, or arrived before any open load of that cpt existed (the reverse order, appointment first, is planned, not implemented: see Appointment before the load)SELECT * FROM dock_appointments WHERE appointment_id = ...; outcome=ignored on the DockAppointmentBooked lineThe appointment copy is saved either way, but the door is assigned only when an appointment event arrives while an open load of that cpt exists. Workaround: have dock-scheduling book (publish) the appointment again after the load exists; a redelivery with the same CloudEvents id is deduplicated and does nothing.
Loading never starts after the trailer dockedTrailerDocked was ignored: no open load has that (site, door), because no door was assigned yet; or the load is not PLANNEDSELECT load_id, state, door_code, trailer_id FROM outbound_loads WHERE site_id = ... AND door_code = ...Fix the door assignment first, then a new TrailerDocked (new CloudEvents id) at that door starts loading. Loading starts only from a docking; there is no REST route for it.
Two loads for one cutoffcannot happen: the partial unique index uq_open_load_per_cutoff allows one PLANNED/LOADING load per (site, cpt, operating_date, ship_method); a raced insert is retried once and joins the winner\d outbound_loadsnone

REST refusals​

Every error is application/problem+json with type https://errors.outbound-shipping.warehouse-systems.dev/<slug>. The catalogue is in the API overview.

Status and slugCauseFix
400 idempotency-key-requireda POST without Idempotency-Key, or with one longer than 128 charactersSend the header: 1 to 128 characters, the fleet bound (ADR 0010).
409 idempotency-key-reusedthe key was used with another method, path or bodyUse a new key for a new request. A replay of the same request returns the stored answer with Idempotency-Replayed: true — when the stored answer is final (ADR 0012); a RETRYABLE refusal was never stored, so the same key runs again. A stored answer stops answering 24 hours after it was stored (ADR 0012 addendum): after that the key is free and the request executes again — not a reuse conflict.
a replay answers as a fresh execution after 24hthe stored answer is older than ports.IdempotencyTTLExpected (ADR 0012 addendum): expiry is enforced at read and the idempotency-purge worker deletes the dead rows hourly. Nothing to fix; mint a fresh key per logical request as the fleet rule says.
400 unknown-query-parametera query parameter the route does not declareRemove it. GET /loads takes site_id, state, operating_date, limit, cursor.
422 not-staging-locationthe location is not a Staging location of the package's own site, or the layout copy has no such location yet (zones and locations come from warehouse.facility.events)SELECT l.location_code, l.role, z.site_code FROM locations l LEFT JOIN zones z USING (zone_id) WHERE l.location_code = .... An empty role means Storage and never stages.
409 wrong-loadthe package is on another load, has no load, or the door scanned is not the load's door (a load with no door assigned refuses every loading)GET /loads/{id} for door_code; check the package's load_id
409 package-state / 409 already-shippedthe scan is not allowed from the package's state; a shipped package cannot be unloadedGET /loads/{id}/packages?state=...
409 packages-outstandinga package of the load is neither loaded nor short-shippedlist the load's packages in EXPECTED or STAGED
409 load-state, load-not-closed, load-confirmedthe command does not fit the load's state (a cancel of a LOADING or CLOSED load is load-state); a SHIP_CONFIRMED load never changes, whatever the command, a cancel included (load-confirmed)GET /loads/{id}
409 load-has-packagescancelling a PLANNED load that already has packages (a LOADING load answers load-state)
400 bad-request on a closea short_ships entry without a package_id or a reason
409 concurrent-modificationoptimistic-lock failure (WHERE version = ... matched no row)re-read and retry
404 load-not-found, package-not-found, bol-not-foundunknown id

Ship-confirm does not happen​

SymptomCauseCheckFix
Trailer departed, load still CLOSED, log outcome=ignoredthe departure carried no seal_number: a departure without a seal confirms nothing, because the bill of lading must certify the yard's sealthe TrailerDeparted payloadyard-management must record the seal; a later TrailerDeparted with a seal (new CloudEvents id) confirms.
Departure message in warehouse.yard-management.events.dlq, load CLOSEDthe confirm failed inside the transaction and rolled back, most often because the appointment copy has no carrier: the bill of lading refuses an empty carrier (billoflading.ErrRequiredField), which is treated as transient, retried 5 times, then dead-letteredx-dlq-error header on the DLQ record; SELECT carrier FROM dock_appointments WHERE appointment_id = (SELECT appointment_id FROM outbound_loads WHERE load_id = ...)Make sure the dock appointment event carries the carrier, then republish the departure to the yard topic.
Departure while the load is LOADING: no ShipmentConfirmed, PackageMissedLoad eventsby design (ADR 0002): the truck left before the close, nothing is confirmed, and every package not loaded raises PackageMissedLoad oncemissed_loads MCP tool, outbox_events for PackageMissedLoadShort-ship what missed and close; see the runbook.
Departure for a trailer this service never sawoutcome=ignored: no load has that (site, trailer) attachednone; not ours to confirm.

Kafka and the outbox​

SymptomCauseCheckFix
Events missing downstream, outbox_events backlog growingthe relay cannot reach the broker, or the database is slowoutbox relay pass failed logs; SELECT count(*), min(created_at) FROM outbox_events WHERE published_at IS NULLRestore the broker; the relay resumes by itself.
One event never arrives, others dothe row reached OUTBOX_MAX_ATTEMPTS and is parkedthe ERROR outbox relay: row reached the attempt cap...; attempts >= 20 rows (your OUTBOX_MAX_ATTEMPTS; with 0 = unlimited a failing row is retried forever and is never parked)Fix the cause in last_error, then UPDATE outbox_events SET attempts = 0 WHERE id = ....
A message in <topic>.dlqpoison payload (missing id, site or door, undecodable data) or five failed attemptsthe x-dlq-error, x-dlq-source-* headers; the dead-lettering log linesFix the producer or the cause, republish the value to the original topic. Messages that are not CloudEvents are skipped, not dead-lettered.
A topic stopped being consumed, process healthythe consumer loop exited (kafka consumer stopped in the log) while probes stay greenconsumer-group lag; the log lineRestart the pod; alert on that line.
Everything replays after a deploya consumer group id changed (or was derived from the pod name)the group ids in the environmentKeep group ids stable. A replay is safe (the inbox dedupes) but re-reads the whole topic.
Duplicate downstream messagesthe relay is at-least-once: a crash between send and UPDATE published_at re-sends with the same CloudEvents idConsumers dedupe on id.

Read models and MCP​

SymptomCauseFix
GET /reports/load-adherence or loads_at_risk empty or stalethe board (load_board) is fed by this service's own analytics consumer; it lags or its group is stuckCheck ANALYTICS_CONSUMER_GROUP lag and SELECT max(updated_at) FROM load_board. The OLTP endpoints (/loads, /packages) are always current.
MCP tool result invalid-limit / invalid-site-idlimit above 200, or a blank site_id for missed_loadsFix the input.
MCP client sees no write toolsby design: cmd/mcp is read-only (L1)Use REST for every write.

Appointment before the load (planned)​

Status: known gap, behaviour planned and deliberately not implemented yet. BookAppointment (internal/application/usecases/book_appointment.go) assigns a door only when DockAppointmentBooked arrives while an open load of the same (site, cpt) exists. If the appointment arrives first, the copy is saved and nothing else happens; the planning path (ExpectPackage, on the first PackageManifested of a cutoff) never looks at the appointment copy, so the load stays without a door until another appointment event for that cpt arrives. No ADR (0001 to 0007) states the rule for the reverse order: ADR 0005 only says LoadDoorAssigned is raised when "an outbound dock appointment names the load's cpt", and the AsyncAPI says the door is assigned "if one exists when the event arrives". Implementing it needs decisions the records do not make:

  • Which appointment when several copies name the same cpt: the load is keyed by (site, cpt, operating date, ship method) but ListOpenByCpt and the appointment copy ignore the date, and the copy can only be read by appointment id today (a new lookup by (site, cpt) plus a rule such as "window starts on the operating date, highest version, latest booking" would be needed).
  • Cancel and reschedule: this service consumes only DockAppointmentBooked; dock-scheduling's cancel/reschedule events are not consumed, so a copy can be stale and a door assigned from it would stay assigned.
  • Where to trigger it: on load planning (ExpectPackage), when it expects a package, or on a sweep; each differs in which LoadDoorAssigned events are raised and when.

Until an ADR picks the rule the operator workaround above stays (ADR 0011 proposes one and is not yet accepted). This page and use cases are the places to update when it lands.