entwine: thin first slice — Connect, Drain, ShutdownGroup (COR-925)
Commit
New shared module entire.io/entire/entwine, the one home for the org's NATS connection-lifecycle plumbing that had been copy-pasted across entire-core, entire-api, and mirror-pipeline (the natsdial copies even carried a "keep in sync until extracted into a shared library" TODO).
This first slice ships the connection-lifecycle core only:
- Connect: rotation-aware mTLS dial (ENTIRE_INTERNAL_TLS_* env, cert re-read on every handshake) with the org-standard resiliency posture — reconnect-forever, bounded DrainTimeout, and lifecycle log handlers that route the nil-error disconnect on an explicit Close to INFO so a clean shutdown isn't logged as a fault.
- Drain / IsShutdownFetchErr: graceful shutdown — async-aware drain-and-wait, and a classifier so pull-consumer fetch loops treat a drain/close during shutdown as a clean exit rather than an ERROR (COR-923).
- ShutdownGroup: cancels background loops, joins them, and only then drains the connections — the ordering that keeps a Drain from racing an in-flight Fetch.
Lifted from the proven implementations (entiredb internal/natsx, entire-api natsdial/jsconsumer); adapted to depend only on log/slog and nats.go — no slogutil/otel — so it stays a lean foundational dep. nats.go is pinned to v1.50.0 to match mirror-pipeline (the first consumer) and force no upgrade via MVS. jsconsumer/natsmsg/backoff land later as entiredb/entire-api converge.
- go build / vet / mod tidy clean, gofmt clean
- go test -race: 12/12 pass (IsShutdownFetchErr truth table, ShutdownGroup join/timeout/cancel/idempotency, mTLS cert rotation)
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01PrEiH1Yg7qi1jJ3SRQPP3x