Skip to main content

Troubleshooting

Synced from task-interleaving

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, built from the failure modes visible in the code. Quoted log lines and REST bodies come from real runs of cmd/api. SQL probes assume Postgres mode; the table names are in Runbook. There is no outbound HTTP or MCP client in this service, so there is no circuit breaker to trip; the dependencies that can fail are Postgres and Kafka.

Boot and runtime​

SymptomLikely causeCheckFix
Process exits 1 at start: HINT_EXPIRY_INTERVAL "abc" is not a valid duration or ... must be greater than zeroThe expiry interval is not a positive Go durationThe ERROR line service exited with error (cmd/api/config.go)Use 5s, 500ms, ...; unset it for the default 5 s
Exits 1 before anything else happens: invalid configuration: DATABASE_URL is required: this context runs on real Postgres (the same line for KAFKA_BROKERS, FULFILLMENT_CONSUMER_GROUP and LAYOUT_CONSUMER_GROUP, each ... is required: this context runs on real Kafka; every missing variable is listed in one error)A mandatory variable is unset. There is no in-memory or consumer-less mode to fall back to (ADR 0006)The error field of service exited with error; env of the podSet the variables (Configuration); the group ids are stable names you choose
Exits 1: FULFILLMENT_MODE=permissive is not supported: this context runs on real Kafka (same for LAYOUT_MODE)A deployment still sets the retired permissive modeenv of the podRemove the variable or set it to kafka
Exits 1: unknown FULFILLMENT_MODE "x" (want kafka) (same for LAYOUT_MODE)Mode typoenv of the podkafka, or leave it unset
Exits 1 after roughly 15 s: run migrations (after 5 attempts): ... or ping postgres (after 5 attempts): ...Postgres unreachable, wrong DSN, or the migration itself failsThe WARN lines retrying with op and err; connect with psql from the same networkFix the DSN or network. The retry exists because the first outbound dial of an Istio-injected pod can be reset; it is not a license to boot without a database
Migration fails and every later boot fails the same wayA partial migration left schema_migrations.dirty = true; golang-migrate refuses to continueSELECT version, dirty FROM schema_migrationsRepair the schema by hand, then force the version with the golang-migrate tooling. Take a backup first
Migrations hang or fail through PgBouncerDATABASE_URL goes through a transaction pooler, which breaks golang-migrate's advisory lockIs the DSN a pooler address?Set MIGRATIONS_DATABASE_URL to a direct connection
/readyz is 503 with {"status":"not_ready"}The process is shutting down (the drain gate is only flipped on SIGINT/SIGTERM)Is the pod terminating?Nothing to fix; a new pod takes over
/readyz is 503 dependency-unavailable, detail not ready: kafka (or postgres, or both)The Kafka broker is unreachable (no broker answered a metadata request), or Postgres does not answer a ping. A missing topic never causes it: topics are not checked, the broker auto-creates them on first write and the service never creates them through an admin APIWARN readiness: dependency is not ready has the cause in errorRestore the broker or database. The process stays up and recovers by itself: the verdict is re-checked every 3 s
/readyz is 200 but requests fail with 500A single query failing for another reason (statement timeout, constraint, bug); readiness only proves the database answers a pingrequest failed lines (the real error is only logged) and psql from the podFix the cause shown in the log
Statements fail with canceling statement due to statement timeoutPool statement timeout is 5 sLogs of the failing request; slow queries on hints listing or the open-task readInvestigate the query; the timeout is compiled in

Hints​

SymptomLikely causeCheckFix
No hint is ever issuedAny of: the site has no policy (inert); the pool copy is empty (the consumers have not caught up, the topic is empty, or fulfillment-execution is not announcing the task); the task that was completed was never announced (no to_location, so no position); no open task has geometry; all candidates exceed maxDetourM; the task types are not in eligibleTaskTypesGET /sites/{siteId}/policy (404 policy-not-found = inert); SELECT count(*), state FROM task_pool GROUP BY state; SELECT count(*) FROM locations WHERE x_m IS NOT NULL; POST /recommendations with fromLocation shows what the ranker would return, and the 422 slug says which precondition failsDeclare a policy; check the consumers (consumer running / kafka reader error; retrying); wait for geometry. Note fulfillment-execution announces TaskAvailable today only for RELOCATE and REPLENISH tasks (see Integration), so a pool fed by the live producer contains those two types only
A completion is applied but the station has no positionThe completed task is not in the pool, or has no to_location or site_id: outcome ignored in the event processed log lineSELECT * FROM task_pool WHERE task_id = '<id>'Nothing to fix in this service; the announcement is missing upstream
A hint stays Active past its TTLThe expiry worker is not running or failinghint expiry worker running at boot; hint expiry sweep failed; SELECT count(*) FROM hints WHERE state = 'Active' AND expires_at < now()Restart; check the sweep error. A claim after the TTL does not consume the hint (the domain refuses it), only the sweep expires it
A claim did not consume the hintThe claimed task is not one of the hint's candidates, the claimer is another station, or the claim time is before the hint was issued or at or after expires_atOutcome applied but the hint unchanged in GET /hints/{hintId}Expected behaviour: the hint is advisory

Kafka and the outbox​

SymptomLikely causeCheckFix
Events never reach Kafka; outbox_events.published_at stays NULLThe broker is unreachable (the relay is always on; its writer sets AllowAutoTopicCreation, so a missing output topic is created by the broker on the first write)Relay ERROR outbox relay pass failed with the cause; last_error and attempts on the head row; /readyzRestore the broker. Rows are drained in order
Relay logs outbox relay pass failed over and overBroker unreachable, or the broker has topic auto-creation disabled and the target topic does not exist (the fleet cluster auto-creates; a local broker may not)last_error and attempts on the head rowRestore the broker, or create the topic where auto-creation is off. The pass retries every OUTBOX_RELAY_INTERVAL
ERROR outbox relay: row reached the attempt cap and is excluded from future claimsA poison row, or an outage longer than OUTBOX_MAX_ATTEMPTS passes (default 20 at 1 s = about 20 s of broker outage; observed)SELECT id, topic, event_type, attempts, last_error FROM outbox_events WHERE published_at IS NULL AND attempts >= 20Fix the cause, then UPDATE outbox_events SET attempts = 0 WHERE id = <id>
Fulfillment or layout consumer is not consuming; ERROR kafka reader error; retrying repeats with consumer, topic and a detailThe consumed topic does not exist yet (its producer has not written, and the service never creates a consumed topic), the broker or its group coordinator is unreachable, or the group join fails. The consumer always runs and keeps retrying; /readyz is not affected by a missing topic and is 503 not ready: kafka only while the broker is unreachableThe detail field; consumer running lines list topic and group_id; /readyzFix the broker, or wait for the producer to publish (the broker creates the topic on its first write); no restart is needed
Consumer lag grows on warehouse.fulfillment.eventsOne message is failing transiently and blocks the partition until its 5 attempts end (backoff up to 5 s)Repeated handling failed; retrying the same message with the same partition/offset; database healthFix the dependency (usually Postgres). After 5 attempts the message goes to the DLQ and the consumer moves on
Messages appear on <topic>.dlqA transient failure outlasted 5 attempts, or a payload that can never be applied (malformed data, task_id missing, site_id or from_location missing on TaskAvailable, xM/yM/zM missing, non-finite coordinate)Read the x-dlq-error header; the log lines dead-letteringFix the producer or the cause, then re-publish the value to the source topic (see Runbook). A message that is not a CloudEvent, or has a type this service does not handle, is not dead-lettered: it is skipped with a WARN
Consumed events seem ignoredOutcome duplicate (the id was already claimed in processed_events), stale (older than the copy), or ignoredThe outcome field of event processedExpected idempotency. To force a re-application, see the rebuild procedure in the Runbook
ERROR consumer stopped; restartingThe Kafka reader failed (not a cancellation), typically an unreachable broker; the consumer is run again after 1 sThe error fieldNone needed; the offset is only committed after a successful handling, so nothing is lost. Persistent restarts mean the broker is down
Nothing consumes warehouse.task-interleaving.eventsNo consumer exists yet: fulfillment-execution does not read InterleavingHintIssuedIntegrationNot a fault of this service

REST problem types​

Every error is application/problem+json, type = https://errors.task-interleaving.warehouse-systems.dev/<slug>, with title, status, detail and instance (the request path). The slugs below are the catalogue in internal/adapters/inbound/http/errors.go.

StatusSlugWhenWhat to do
400malformed-requestBody is not valid JSON for the operation: unknown field, wrong type, trailing data, empty body, body over 64 KiB, or fromLocation blank or longer than 128 charactersFix the body against apis/openapi.yaml
400invalid-site-id, invalid-station-id, invalid-hint-idId is blank, over 64 characters, contains whitespace, a control character or / (hint ids must start with hint-)Fix the path or filter
400invalid-policymaxDetourM not a finite number above 0; maxCandidates outside 1 to 5; hintTtlSeconds not above 0 or above 2147483647; verticalWeight negative or non-finite; a required field missingUse the detail text
400invalid-task-typeeligibleTaskTypes empty, missing or contains something outside PICK, PACK, REBIN, SLAM, RELOCATE, REPLENISH
400invalid-cursor, invalid-limit, invalid-stateCursor not handed out by this API; limit outside 1 to 500; state not Active, Consumed, Expired or Superseded
400idempotency-key-requiredPOST /recommendations without an Idempotency-KeySend a unique key per logical request
400idempotency-key-invalidPOST /recommendations with an Idempotency-Key that is not 1 to 128 printable ASCII charactersSend a UUID
404policy-not-found, hint-not-found, station-not-foundUnknown resource. policy-not-found means the site is inert; station-not-found means no completion was ever recorded for itNormal for a new site or station
409concurrent-modificationTwo writers raced on one aggregate; the loser's version guard failedRe-read and retry
409idempotency-key-reusedSame Idempotency-Key with a different method, path or bodyA client bug, do not retry blindly: use a new key, or resend the original request to get the stored answer
412version-mismatchPUT /sites/{siteId}/policy with a stale or missing If-Match on an existing policy, or with an If-Match on a site that has none; an If-Match that is not a version (*, W/"1") also counts as staleGET the policy and send its ETag as If-Match
422policy-not-declaredPOST /recommendations for a site without a policyDeclare one
422origin-unknownThe origin location has no known geometry in the layout copy (detail names it)Wait for or feed LocationGeometryUpdated; try another fromLocation
422station-position-unknownNo fromLocation given and the station has no recorded positionSend fromLocation
500internal-errorUnmapped error or handler panic; detail is always an unexpected error occurredRead the request failed / handler panicked log line
503dependency-unavailableGET /readyz only: Postgres or the Kafka broker (no broker answers a metadata request; topics are never checked) is not usable; detail is not ready: plus the namesSee the /readyz row under Boot and runtime

Idempotency in practice​

  • Only POST /recommendations is wrapped; PUT and GET never need a key.
  • A key with a stored answer replays that answer byte for byte, whatever its status (2xx and 4xx are stored), and adds the response header Idempotency-Replayed: true (a first execution never carries it). A 5xx is never stored, so the same key can retry real work.
  • The middleware runs the handler inside the unit of work and rolls it back on a 4xx or 5xx; the 4xx answer is then stored on its own. Two concurrent requests with one new key both run, and the first to store wins; the loser rolls back and replays the winner's answer.
  • Nothing purges idempotency_keys, so a key is remembered indefinitely.