Skip to content

feat(realtime): wrap NATS wire protocol in nats, keep the seam - #79

Merged
sebyx07 merged 1 commit into
mainfrom
feat/nats-wrap-protocol
Aug 15, 2026
Merged

feat(realtime): wrap NATS wire protocol in nats, keep the seam#79
sebyx07 merged 1 commit into
mainfrom
feat/nats-wrap-protocol

Conversation

@sebyx07

@sebyx07 sebyx07 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Swaps the hand-rolled NATS wire client for the official nats (nats.js) library behind the existing Transport/NatsTransport/selectTransport seam — 1,019 LOC of hand-rolled protocol code deleted; zero caller-facing change. Documented in docs/idea/18-build-vs-wrap.md.
  • Gate task: proved nats-transport.live.test.ts and presence.live.test.ts (both describe.skipIf(TEST_NATS_URL === undefined)) actually run and pass, unmodified, against a real JetStream-enabled nats-server — not just the in-memory fake they were co-written with.

Test plan

  • TEST_NATS_URL=nats://localhost:14222 bun test packages/realtime/src/nats-transport.live.test.ts → 6 pass, 0 fail
  • TEST_NATS_URL=nats://localhost:14222 bun test packages/realtime/src/presence.live.test.ts → 3 pass, 0 fail
  • TEST_NATS_URL=nats://localhost:14222 bun test packages/realtime → 441 pass, 0 fail (9 more than without the env var — exactly the two live suites)
  • bun run scripts/verify.ts --json, with and without TEST_NATS_URL → 14/17 both times, live step ok:true, no regression
  • No Bun-compatibility failure surfaced — the fallback plan (record a reversal in docs/idea/18-build-vs-wrap.md) was not needed
  • git status clean — live suites required zero modification to pass

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

- delete 1,019 LOC of hand-rolled protocol (nats-protocol/commands/socket/
  connection) and the 431-line fake nats-server; nats@2.29.3 pinned exact,
  the first external runtime dep any @ultimat3/* package has taken
- add the port (nats-client.ts) and its one adapter (nats-lib-client.ts) —
  the only file in the repo that imports nats
- keep the seam: Transport, NatsTransport, NatsTransportOptions and
  selectTransport unchanged; presence.live.test.ts passes unmodified
- reconnect and re-subscription are the library's now, with our
  thundering-herd jitter handed down as its reconnectDelayHandler; the
  JetStream KV layer stays ours (per-message TTL, batch multi_last)
- test seam moves from an injected byte stream to an injected client;
  nats-fake.ts is now an in-memory bus implementing the port
- Bun compatibility gate passed: verified on Bun 1.3 against a real
  nats-server 2.11.17

Co-Authored-By: Claude <noreply@anthropic.com>
@sebyx07 sebyx07 added the claudetm Created by Claude Task Master label Aug 15, 2026
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 46 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 84123ea9-477f-40a2-8c79-d84a7ea5e521

📥 Commits

Reviewing files that changed from the base of the PR and between 50f640e and fc98ec0.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock, !**/bun.lock
📒 Files selected for processing (30)
  • CHANGELOG.md
  • docs/idea/17-scale-ladder.md
  • docs/idea/18-build-vs-wrap.md
  • docs/idea/README.md
  • packages/realtime/CLAUDE.md
  • packages/realtime/README.md
  • packages/realtime/package.json
  • packages/realtime/src/index.ts
  • packages/realtime/src/nats-client.test.ts
  • packages/realtime/src/nats-client.ts
  • packages/realtime/src/nats-commands.test.ts
  • packages/realtime/src/nats-commands.ts
  • packages/realtime/src/nats-connection-fixture.ts
  • packages/realtime/src/nats-connection.test.ts
  • packages/realtime/src/nats-connection.ts
  • packages/realtime/src/nats-fake.test.ts
  • packages/realtime/src/nats-fake.ts
  • packages/realtime/src/nats-jetstream.ts
  • packages/realtime/src/nats-kv.test.ts
  • packages/realtime/src/nats-kv.ts
  • packages/realtime/src/nats-lib-client.ts
  • packages/realtime/src/nats-protocol.test.ts
  • packages/realtime/src/nats-protocol.ts
  • packages/realtime/src/nats-socket.test.ts
  • packages/realtime/src/nats-socket.ts
  • packages/realtime/src/nats-transport.live.test.ts
  • packages/realtime/src/nats-transport.test.ts
  • packages/realtime/src/nats-transport.ts
  • packages/realtime/src/transport-env.test.ts
  • packages/realtime/src/transport-env.ts

Comment @coderabbitai help to get the list of available commands.

@developerz-ai

developerz-ai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

This PR looks ready — CI is green and there are no risk signals. The internal NATS protocol implementation swap to the official nats library preserves the transport seam, so no public API changes.

Feel free to apply a ready-to-merge label when you'd like to proceed.

🤖 Posted by developerz.ai — the maintainer agent, not a human.

@sebyx07
sebyx07 merged commit 12e837e into main Aug 15, 2026
5 checks passed
@sebyx07
sebyx07 deleted the feat/nats-wrap-protocol branch August 15, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claudetm Created by Claude Task Master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant