Skip to main content

Runbook

Everything below comes from the Helm chart charts/workforce-management, the composition roots under cmd/ and the adapters they wire. For every environment variable see Configuration.

Deployables​

All four binaries ship in one image (image.repository, default workforce-management). Each Deployment selects its binary with command.

Deployment (template)BinaryEnabled byContainer portServiceProbes
<fullname> (deployment.yaml), component apidefault entrypoint, cmd/workforcealwayshttp = service.targetPort 8080service.yaml: ClusterIP 80 → 8080startup /healthz (2 s × 30), liveness /healthz, readiness /readyz
<fullname>-mcp (mcp-deployment.yaml)/app/mcpmcp.enabled (default false)8090 (MCP_ADDR)mcp-service.yaml: ClusterIP 8090 → 8090startup, liveness, readiness all on /healthz
projector (projector-deployment.yaml), component analytics-projector/app/workforce-projectoranalytics.enabled (default false)admin 8091 (ADMIN_ADDR)nonestartup, liveness, readiness all on /healthz on admin
reports (reports-deployment.yaml)/app/workforce-reportsanalytics.enabled8092 (HTTP_ADDR)ClusterIP 80 → 8092, in the same templatestartup, liveness, readiness all on /healthz
frontend (frontend-deployment.yaml)nginx-unprivileged serving web/frontend.enabled (default false)8080frontend-service.yaml: ClusterIP 80 → 8080liveness, readiness /healthz

Edge routing is owned by warehouse-infra. APIs are reached through Kong at :8000 under /api/workforce-management. The chart's own ingress and gatewayApi HTTPRoute blocks are both disabled by default. The console remote is served by the Nginx web gateway at /mfes/workforce-management/, never through Kong (see the frontend: comment in values.yaml). REST and MCP are unauthenticated.

The chart refuses to render without database.url or database.existingSecret (workforce-management.requireDatabase) and without kafka.brokers (workforce-management.requireKafka), because cmd/workforce and cmd/mcp exit at once without DATABASE_URL and KAFKA_BROKERS (ADR 0038). The same requireRealRuntime gate also refuses config.eventPublisher other than kafka, kafka.enabled=false, pathCatalogue.enabled=true, a terminationGracePeriodSeconds under 25, retired-mode extraEnv entries, and analytics.enabled without a DSN source or analytics.projector.consumerGroup.

What the chart templates, and what needs extraEnv​

templates/configmap.yaml renders HTTP_ADDR, EVENT_PUBLISHER, MIGRATIONS_PATH, MAX_HOURS_PER_SHIFT, OUTBOX_RELAY_INTERVAL, the housekeeping variables, SHUTDOWN_DRAIN_DELAY, INSTALLED_CAPACITY_MODE (default http), FULFILLMENT_EXECUTION_BASE_URL (default http://fulfillment-execution.<release namespace>.svc.cluster.local:80; both gap fix D24) and KAFKA_BROKERS from config.* / kafka.brokers, and the api Deployment mounts it with envFrom (gap fix D14, 2026-10-12; the full key table is in Configuration). Changing a config.* value takes effect on the next rollout: the checksum/config annotation rolls the pods. deployment.yaml also sets HTTP_ADDR, EVENT_PUBLISHER, MIGRATIONS_PATH, MAX_HOURS_PER_SHIFT, the housekeeping variables, SHUTDOWN_DRAIN_DELAY, DATABASE_URL, MIGRATIONS_DATABASE_URL (secret key, optional: true), LOG_LEVEL, KAFKA_BROKERS (always), and the OTel variables (when otel.enabled) as explicit env, which wins over the ConfigMap for the same key. The projector, reports and MCP Deployments do not mount the ConfigMap (the projector gets KAFKA_BROKERS and ANALYTICS_CONSUMER_GROUP, the MCP Deployment KAFKA_BROKERS and EVENT_PUBLISHER). charts/workforce-management/tests/render_test.sh (CI job chart-tests) fails if the mount disappears. These must come through extraEnv:

  • Nothing for the installed-capacity edge any more: the chart defaults it to http against fulfillment-execution's in-cluster Service. Override config.installedCapacityMode / config.fulfillmentExecutionBaseUrl (or an extraEnv entry, which wins) when fulfillment-execution lives elsewhere. With permissive, every CommitShiftPlan fails with 503 installed-capacity-unavailable.
  • Nothing for the catalogue or the measured-rate feed: PATH_CATALOGUE_SOURCE (kafka) and LABOR_PERFORMANCE_MODE (kafka-cache) are the binary's defaults. warehouse-infra still sets both explicitly, which the chart accepts; LABOR_PERFORMANCE_MODE=http plus LABOR_PERFORMANCE_BASE_URL is the REST rollback.
  • IDLE_SHARE_TRIM_THRESHOLD and CORS_ALLOWED_ORIGINS.

extraEnv is also rendered into the MCP Deployment.

Startup and readiness​

cmd/workforce boots in this order (cmd/workforce/main.go run):

  1. loadBootConfig: DATABASE_URL, KAFKA_BROKERS and the mode variables are validated; any problem is a boot error naming its variable, before telemetry, any connection and the listener (ADR 0038).
  2. Telemetry (non-blocking; a missing collector only drops data).
  3. The process-path catalogue: the compacted warehouse.process-path-management.events topic is replayed up to its current high-water mark, waiting at most 60 s. Failure stops the boot.
  4. Migrations on MIGRATIONS_DATABASE_URL, then the pgxpool on DATABASE_URL. Each step runs under bootretry: 5 attempts, 15 s of total backoff.
  5. With LABOR_PERFORMANCE_MODE=kafka-cache (the default): replay of warehouse.labor-performance.events, waiting at most 60 s. The boot then logs kafka topics with the topics it produces to and consumes from (it creates none).
  6. The housekeeping sweeper starts, then the HTTP listener and the outbox relay (always on).

/readyz waits for the dependencies. It returns 200 {"status":"ready"} only while the drain gate is open AND Postgres answers a ping AND a Kafka broker answers a metadata request (topics are never required). The verdict is cached 3 s and each check is bounded to 2 s. A failed dependency is a 503 dependency-unavailable problem naming postgres and/or kafka, and a WARN readiness: dependency is not ready in the log; during graceful shutdown it is 503 {"status":"not_ready"}. /healthz is pure liveness and is never flipped, so a dependency outage takes pods out of the Service without restarting them. The other three binaries have only /healthz.

The startup probe allows 30 × 2 s = 60 s before liveness takes over. A cold start that needs the full boot-retry budget twice (migrations, then the pool) plus a 60 s Kafka replay can exceed that. See Troubleshooting.

Graceful shutdown (cmd/workforce/serve.go)​

On SIGTERM: /readyz → 503, then a wait of SHUTDOWN_DRAIN_DELAY (10 s), then http.Server.Shutdown, then the Kafka consumers stop, then the sweeper, then the outbox relay finishes its in-flight pass. Everything after the drain wait shares one 10 s deadline. The Postgres pool closes last. The chart's terminationGracePeriodSeconds: 30 covers 10 s drain + 10 s shutdown + 5 s telemetry flush. cmd/mcp, the projector and reports shut down with a plain 10 s Shutdown.

The projector also stops on its own when its consumer loop exits without a signal (a commit or DLQ write failure): it shuts the admin server down and exits non-zero, so the pod restarts instead of serving a green /healthz over a dead consumer (gap fix D13, superviseConsumer in cmd/workforce-projector/main.go).

Migrations​

DatabaseFilesApplied byDSN
OLTPmigrations/000001_init … 000005_associate_shift_site_codecmd/workforce and cmd/mcp (when it has a DATABASE_URL), on every startMIGRATIONS_DATABASE_URL, falling back to DATABASE_URL
Analyticalmigrations/analytics/0001_reportcmd/workforce-projector, on every startANALYTICS_DATABASE_URL

The OLTP migrations create associate_shift, shift_plan, path_plan, labor_assignment, labor_assignment_history and domain_event (000001), outbox_events (000002), the version columns (000003), idempotency_keys (000004) and the associate shift's site code (000005). The analytical migration creates analytics_processed_events, analytics_consumed_events, analytics_pending_breaks and labor_rollup.

Migrations are golang-migrate. They take a session-scoped advisory lock, so in a PgBouncer environment MIGRATIONS_DATABASE_URL must be the direct, non-pooled DSN (ADR 0025). There is no separate migration Job. Concurrent replicas serialise on the lock, and cmd/workforce-reports never migrates. To roll a migration back, run the matching .down.sql by hand with the golang-migrate CLI against the direct DSN. The binaries only ever migrate up.

Kafka​

One broker cluster for the whole platform (in-cluster Bitnami; external access at localhost:9092 from the kind cluster). Every message is a CloudEvents 1.0 structured-mode event (internal/adapters/kafka/cloudevents). There is no binary-mode toggle.

TopicDirectionWhoConsumer groupNotes
warehouse.workforce.eventsproduceoutbox relay in cmd/workforce. cmd/mcp produces directly only when it runs without a database.n/aIntegration topic. Event types are in Events.
warehouse.workforce.analyticsproducesame as aboven/aAnalytics fan-out of every domain event (ADR 0010).
warehouse.workforce.analyticsconsumecmd/workforce-projectorworkforce-analytics (stable, shared)Idempotent on the CloudEvents id (analytics_consumed_events).
warehouse.workforce.analytics.dlqproducecmd/workforce-projectorn/aPoison messages, see below. Auto-created on first write.
warehouse.process-path-management.eventsconsumecmd/workforce, cmd/mcpworkforce-management-process-path-catalogue-<host>-<pid>-<ns> (unique per process)Full replay from the first offset on every start. No DLQ: an invalid CloudEvent is logged at WARN and skipped.
warehouse.labor-performance.eventsconsumecmd/workforce when LABOR_PERFORMANCE_MODE=kafka-cache (the default)workforce-management-labor-performance-cache-<host>-<pid>-<ns> (unique per process)Same replay and skip behaviour. Feeds the measured rate and the idle-share signal.

Outbox relay​

Every use case writes its events into outbox_events in the same transaction as its state change (two rows per event, one per topic) (ADR 0016). Only cmd/workforce runs the relay, and it is always on (internal/adapters/outbound/postgres/outbox_relay.go):

  • Each pass claims up to 100 unpublished rows (FOR UPDATE SKIP LOCKED, so overlapping pods during a rollout never double-send) and sends them one at a time in id order.
  • After a full batch the next pass starts at once. After a partial or empty one the relay sleeps OUTBOX_RELAY_INTERVAL (1 s).
  • On the first send failure the pass stops, the row gets attempts/last_error, rows already sent stay published, and the next pass retries the failed row. Ordering per key is preserved, so one stuck row holds back everything behind it, until the row has failed OUTBOX_MAX_ATTEMPTS times (default 20, about 20 s of continuous failure at the default interval; ADR 0036).
  • At the cap the relay stops claiming the row and logs it once at ERROR (outbox relay: row reached the attempt cap and is no longer claimed, with outbox_id, topic, event_type, key, attempts). The rows behind it publish, so later events with the same key overtake it. The row stays in outbox_events (published_at IS NULL) with its attempts and last_error; the sweeper never deletes it. After fixing the cause, re-arm it: UPDATE outbox_events SET attempts = 0 WHERE id = <outbox_id>; (after a broker outage, all parked rows: UPDATE outbox_events SET attempts = 0 WHERE published_at IS NULL AND attempts >= 20;). OUTBOX_MAX_ATTEMPTS=0 restores unlimited retries.
  • Lag is visible as workforce.outbox.lag_seconds (see Observability).

Analytics DLQ​

The projector retries each stage of a message (dedupe mark, projection apply) up to 3 attempts, with jittered backoff from 100 ms to 2 s. A message that does not decode as a CloudEvent goes straight to the DLQ. After the retries are exhausted, the raw payload is written to <topic>.dlq with x-dlq-source-topic and error-context headers, and the offset is committed anyway, so one poison message never blocks the partition. Only a DLQ write failure or a commit failure stops the consumer (internal/adapters/inbound/kafka/analytics_consumer.go).

Housekeeping​

cmd/workforce runs one sweeper goroutine (internal/adapters/outbound/postgres/sweeper.go, ADR 0028). It runs once at boot and then every HOUSEKEEPING_INTERVAL (1 h). It deletes in batches of 1000:

  • idempotency_keys rows older than IDEMPOTENCY_KEY_TTL (24 h). This is also the replay window of the Idempotency-Key contract: a retry after that is a new request. Stored answers are a 2xx and a FINAL refusal (ADR 0044: request-shape 400/422, planned-heads-exceed-installed, planned-hours-exceed-capacity); a RETRYABLE refusal, a 5xx (or a panic) rolls the key back, so a retry under the same key always runs again.
  • outbox_events rows that are published and older than OUTBOX_RETENTION (7 days). Unpublished rows are never swept.

A failed pass is logged as housekeeping sweep failed and retried on the next tick. Several replicas sweeping at once is safe: deletes are idempotent.

Scaling​

WorkloadHPA block (all default enabled: false)Notes
apiautoscaling.api: 1 to 4, 70 % CPUStateless. Its Kafka caches use per-process groups, so N replicas each replay their own copy.
projectorautoscaling.projector: 1 to 2Shared group workforce-analytics. Partitions rebalance across replicas.
reportsautoscaling.reports: 1 to 3Read-only and stateless.
frontendautoscaling.frontend: 1 to 3Static assets.
mcpnoneThe MCP server has been stateless since ADR 0041 (no Mcp-Session-Id state), so sessions no longer bar scaling out. The chart defaults to mcp.replicaCount: 1 and ships no HPA; changing that is a separate decision.

When an HPA is enabled, the Deployment's own replicas: is omitted. Connection budgets per process (ADR 0024): the OLTP pool has MaxConns 10 and a 5 s statement_timeout (internal/adapters/outbound/postgres/pool.go). The projector pool has 5 connections and 10 s; the reports pool has 5 connections, 15 s, and is read-only (internal/adapters/outbound/analyticsstore/pool.go). Multiply by the replica maximum when you size PgBouncer or max_connections.

Routine procedures​

TaskHow
Re-publish stuck outbox rowsFix the broker or topic. Inspect with SELECT id, topic, event_type, key, attempts, last_error FROM outbox_events WHERE published_at IS NULL ORDER BY id LIMIT 20;. A row below OUTBOX_MAX_ATTEMPTS is retried on every pass, so nothing else is needed. A row at the cap is parked: re-arm it with UPDATE outbox_events SET attempts = 0 WHERE id = <id>; (ADR 0036).
Re-send already-published eventsUPDATE outbox_events SET published_at = NULL WHERE id BETWEEN … ; while the rows are still inside OUTBOX_RETENTION. Consumers must dedupe on the CloudEvents id; the projector does.
Replay the analytics projectionStop the projector, reset group workforce-analytics on warehouse.workforce.analytics (kafka-consumer-groups.sh --reset-offsets --to-earliest --execute), restart. Already-applied ids are skipped through analytics_consumed_events. To rebuild from scratch, truncate the analytical tables first.
Reprocess the analytics DLQRead warehouse.workforce.analytics.dlq, fix the cause, and produce the original payload back onto warehouse.workforce.analytics. There is no tooling in this repo for it.
Refresh the process-path catalogueNothing to do: the catalogue consumer keeps consuming warehouse.process-path-management.events at runtime (the file source and its ConfigMap were removed, ADR 0038). A restart replays the topic from the first offset.
Rotate database credentialsUpdate the Secret (database.existingSecret, keys DATABASE_URL and MIGRATIONS_DATABASE_URL; the analytics Secret's ANALYTICS_DATABASE_URL / ANALYTICS_READER_DATABASE_URL), then kubectl rollout restart the Deployments. DSNs are read only at boot.
Disable housekeeping temporarilySet config.housekeepingInterval: "0" and roll.

Analytics reports API (cmd/workforce-reports)​

These routes are not in apis/openapi.yaml; they are served by the separate reader binary (internal/adapters/inbound/http/reports_handler.go). The request and response shapes are on Labor report.

RouteQuery parametersResponse
GET /healthznone200 {"status":"ok"}
GET /reports/laborfrom, to (RFC 3339, required), pathId (optional; empty means all paths), granularity (optional, only hour)200 {"rows":[{"pathId","hourBucket","shiftsStarted","shiftsEnded","breaks","avgBreakSeconds","certifications","laborAssigned","laborReassigned","understaffingEvents"}]} from labor_rollup. A missing or malformed parameter returns 400 with problem type invalid-report-query.
GET /reports/labor/freshnessnone200 {"lagSeconds": <float>}: seconds since the newest occurred_at in analytics_processed_events. It is 0 when the read model is empty, so "0" does not always mean "fresh".

A store failure on either report route returns 500 with problem type report-store-error. A row with an empty pathId is the building-wide, associate-scoped bucket (shifts, breaks, certifications).

cmd/mcp exposes the same report as the get_workforce_labor_report tool only when REPORTS_BASE_URL (chart mcp.reportsBaseUrl, or the in-cluster reports Service when analytics.enabled) is set.