Task 15 Execution Packet: Messaging Federation + Clustering (Aligned to 2026-01-25 Plan)

This packet replaces the old Task 15 notes. It is aligned to Phase 14 / Task 15 in docs/plans/2026-01-25-end-state.md and to the current repo layout (infra/nats/*, infra/docker/*, apps/sea-mq-worker/*).

Use this as the exact execution guide for an agent implementing Task 15.


Objective

Deliver messaging that scales single instance → cluster → mesh, with deterministic topology, JetStream durability, and federation across clusters.

Minimum outcomes (per plan):


Non-negotiables


Step 0 — Ground current code reality (must confirm before editing)

Verify these in-repo surfaces:

If any of these differ, adjust this packet before coding.


Step 1 — Federation mechanism (resolved)

Use NATS supercluster gateways (resolved default).


Step 2 — NATS config: cluster + federation + JetStream domain

Required file edits

Required env vars

Cluster:

Federation (supercluster gateways):

JetStream:

Required config blocks (mesh file)

Success signal: nats --domain <domain> stream ls works on each cluster domain.


Step 3 — Compose wiring for mesh profile

Add a mesh profile with two 3-node clusters (sea-a, sea-b).

Files

Requirements

Success signal: Gateway connections appear in NATS monitoring endpoints, and cross-cluster pub/sub works.


Step 4 — Stream provisioning (deterministic + env-only)

Modify infra/nats/setup-streams.sh:

Add env controls

Requirements


Step 5 — Worker env support (only if missing)

apps/sea-mq-worker/src/main.rs must support env-only configuration for:

Add only what is missing; preserve defaults and backwards compatibility.


Step 6 — E2E test: federation actually works

Create/replace:

Test contract (minimum)

Required env vars (skip-safe)

Minimum additional tests (per plan)

These can be separate tests or a combined suite, but must be deterministic and skip-safe if the mesh isn’t running.


Step 7 — Verification

Bring up mesh (example):

1
docker compose -f infra/docker/docker-compose.mesh.yml --profile nats-mesh up -d

Run E2E test:

1
2
3
export E2E_NATS_A_URL="nats://localhost:4422"
export E2E_NATS_B_URL="nats://localhost:5422"
cargo test -p sea-mq-worker e2e_federation_pubsub_across_clusters -- --nocapture

Only mark Task 15 complete after tests pass.


Acceptance criteria (from plan)