|
| 1 | +--- |
| 2 | +date_created: 2026-07-01 |
| 3 | +date_modified: 2026-07-01 |
| 4 | +title: "The whole bus moves off deprecated nats@2 onto @nats-io/transport-node v3" |
| 5 | +lede: "All 10 services swapped the deprecated monolithic nats package for the scoped @nats-io/* v3 client — 27 files, one codec rewrite, zero wire-protocol changes — and every service round-tripped live on the rebuilt stack before the branch moved on." |
| 6 | +publish: true |
| 7 | +authors: |
| 8 | + - Michael Staton |
| 9 | +augmented_with: |
| 10 | + - Claude Code on Claude Fable 5 |
| 11 | +files_changed: |
| 12 | + - services/record-surrealdb-resolver/src/{server,handlers,domains}.ts |
| 13 | + - services/xlsx-ingest/src/server.ts |
| 14 | + - services/ingest/src/server.ts |
| 15 | + - services/prompt-store/src/{server,handlers}.ts |
| 16 | + - services/response-store/src/{server,handlers}.ts |
| 17 | + - services/row-store/src/{server,handlers}.ts |
| 18 | + - services/content-ingest/src/{server,handlers}.ts |
| 19 | + - services/social-search/src/{search,server,entity-pulse/dispatch}.ts |
| 20 | + - services/prompt-runner/src/{apply,chat-turn,drafter,preview,run,server}.ts |
| 21 | + - services/workspace/src/{nats,capabilities,chat,workspaces,ws}.ts |
| 22 | + - services/*/package.json |
| 23 | + - pnpm-lock.yaml |
| 24 | +tags: |
| 25 | + - Progress-Update |
| 26 | + - Dependency-Migration |
| 27 | + - NATS |
| 28 | + - Message-Bus |
| 29 | + - Services |
| 30 | + - Deprecation |
| 31 | +--- |
| 32 | + |
| 33 | +## Why Care? |
| 34 | + |
| 35 | +Every `pnpm install` printed `WARN deprecated nats@2.29.3` — the monolithic |
| 36 | +nats.js v2 package is end-of-life, split upstream into scoped `@nats-io/*` |
| 37 | +packages. This was the one dependency deliberately parked during the |
| 38 | +2026-07-01 upgrade campaign (Zod 4, Rsbuild 2 + MF 2.6, TypeScript 6, |
| 39 | +csv-parse 7) because it isn't a version bump: the codec utilities were |
| 40 | +**removed** in v3, so the swap rewrites how every inter-service message is |
| 41 | +encoded and decoded, across the message plumbing of all 10 backend services |
| 42 | +at once. A blind bump would have compiled fine in places and broken the bus |
| 43 | +at runtime. |
| 44 | + |
| 45 | +## What Shipped |
| 46 | + |
| 47 | +All 10 services (`record-surrealdb-resolver`, `xlsx-ingest`, `ingest`, |
| 48 | +`prompt-store`, `response-store`, `row-store`, `content-ingest`, |
| 49 | +`social-search`, `prompt-runner`, `workspace`) now declare |
| 50 | +`@nats-io/transport-node@^3.4.0` instead of `nats@^2.28.0`. The whole |
| 51 | +migration is five mechanical rewrites, per the plan's mapping table: |
| 52 | + |
| 53 | +- `from 'nats'` → `from '@nats-io/transport-node'` |
| 54 | +- `JSONCodec` import — dropped (removed in v3) |
| 55 | +- `const jc = JSONCodec();` — deleted (10 copies) |
| 56 | +- `jc.encode(obj)` → `JSON.stringify(obj)` (publish / request / respond all |
| 57 | + accept strings) |
| 58 | +- `jc.decode(X.data) as T` → `X.json() as T` — contextual on the `Msg` |
| 59 | + variable name (`msg`, `reply`, `saveReply`, `parentReply`, `ingestReply`) |
| 60 | + |
| 61 | +`connect()`, `subscribe()`, `publish()`, `request()`, `respond()`, and the |
| 62 | +`for await (const msg of sub)` iteration are unchanged. The NATS server, |
| 63 | +subjects, message shapes, and capability contracts are untouched — the wire |
| 64 | +protocol is identical. |
| 65 | + |
| 66 | +## How It Was Proven |
| 67 | + |
| 68 | +Per the plan's two load-bearing gates: |
| 69 | + |
| 70 | +1. **Pilot gate** — `record-surrealdb-resolver` migrated first and proven on |
| 71 | + the live broker before fan-out: a real `resolver.search.requested` |
| 72 | + request/reply round-tripped against SurrealDB (`ok:true`, 8 candidates) |
| 73 | + through the new encode/decode path. |
| 74 | +2. **Full-stack gate** — after the nine-service fan-out, the Docker images |
| 75 | + were rebuilt (`docker compose up --build`) and a scripted sweep fired one |
| 76 | + real round-trip through **every** service: workspace active-query, |
| 77 | + record-set list, prompt list, response list, connector inventory, |
| 78 | + resolver search, corpus list-for-record, prompt-run cancel, and full |
| 79 | + create-then-delete ingest cycles for both CSV and XLSX. 12/12 passed; |
| 80 | + service logs show zero JSON decode errors. |
| 81 | + |
| 82 | +`pnpm install` no longer prints a deprecation warning; the lockfile no |
| 83 | +longer resolves `nats@2.x`; tree-wide typecheck is clean. |
| 84 | + |
| 85 | +## Decisions On The Record |
| 86 | + |
| 87 | +- **No shared `@augment-it/nats` helper yet.** Ten near-identical `connect` |
| 88 | + call sites still beg for consolidation, but folding a refactor into a |
| 89 | + migration doubles the risk surface. It stays a follow-on, per the plan's |
| 90 | + Open Questions. |
| 91 | +- **`as T` casts kept over `msg.json<T>()`** — smaller, more literal diff |
| 92 | + matching the existing style. |
| 93 | +- One commit per service (pilot + nine), each atomic with its |
| 94 | + `package.json` and lockfile, so any service can be bisected or reverted |
| 95 | + independently. |
| 96 | + |
| 97 | +## See Also |
| 98 | + |
| 99 | +- `context-v/plans/Migrate-off-Deprecated-nats-Package-to-nats-io-Scoped-v3.md` |
| 100 | + — the plan this executed, mapping table and all |
| 101 | +- nats.js v2→v3 migration guide — |
| 102 | + `https://github.com/nats-io/nats.js/blob/main/migration.md` |
0 commit comments