Skip to content

Negotiate wire-format version at connection start - #44

Merged
Mearman merged 5 commits into
mainfrom
feat/wire-mesh-core-migration
Sep 10, 2026
Merged

Negotiate wire-format version at connection start#44
Mearman merged 5 commits into
mainfrom
feat/wire-mesh-core-migration

Conversation

@Mearman

@Mearman Mearman commented Sep 10, 2026

Copy link
Copy Markdown
Member

Fixes #31

A mixed fleet of old and new peers now negotiates down to what both actually support, or refuses loudly, instead of one side silently misinterpreting the other's state sync during a rolling upgrade.

A client sends a small CBOR handshake frame as the very first bytes on a connection and does not wait; a server replies only in response to a received frame, so a legacy client never sees binary bytes at all. Version and shared-domain negotiation is @exadev/wire-mesh-core's negotiate(), the same mechanism every wire-mesh consumer speaks. A peer that sends no frame is classified legacy and the connection proceeds exactly as before.

normaliseWireState covers the other direction: a legacy peer's state_sync payload can genuinely be missing deliveryQueues (#30) or an entity's version field (#29), so it fills in the defaults before the payload reaches applyStateSync.

Depends on @exadev/wire-mesh-core (ts/packages/core in ExaDev/wire-mesh) as a git-dependency-with-subdirectory workspace dependency.

Test plan

  • Unit tests: gate state machine (pending/legacy/negotiated/refused), split-frame reassembly, normaliseWireState
  • Live-socket integration tests: negotiated, legacy fallback, and refusal over a real TCP pair
  • Full existing integration suite (TCP, TLS, WebSocket mesh e2e, broadcast window, downtime replay, identity restart) — 44/44 passing
  • typecheck, lint, build all green

Resolved via pnpm's git-dependency-with-subdirectory syntax against the
ts/packages/core workspace member, mirroring the committed-dist/no-prepare-script
pattern already proven for cddl.js, so the unpublished package installs cleanly
without running any lifecycle script.
Fixes #31: a mixed fleet of old and new peers now negotiates down to what
both actually support, or refuses loudly, instead of one side silently
misinterpreting the other's state sync during a rolling upgrade.

A client sends a small CBOR handshake frame as the very first bytes on a
connection and does not wait; a server replies only in response to a
received frame, so a legacy client never sees binary bytes at all. Version
and shared-domain negotiation is wire-mesh-core's negotiate(), the same
mechanism every wire-mesh consumer speaks. A peer that sends no frame is
classified legacy and the connection proceeds exactly as before.
Wires attachSocketHandshake/attachWsHandshake into every client and server
connection site across TCP, TLS, and WebSocket, each transport's write of its
own first application message (introduce, connect_request, or pong) reordered
to land after the handshake frame it was previously racing ahead of.

Also updated package.json's test file list to include the new handshake
suite (it lists tests explicitly rather than globbing).
A legacy peer's state_sync payload can genuinely be missing deliveryQueues
(#30) or an entity's version field (#29), since nothing validates a
state_sync message's shape beyond isMeshMessage's bare method check.
normaliseWireState fills in the defaults (empty collections, version 1)
before the payload reaches applyStateSync, so an old-build snapshot parses
to a complete state instead of throwing.

WireStateInput models exactly that tolerance as its own type rather than
widening SerialisedState itself, so domain code elsewhere keeps working with
the fully-populated type.
handshake.ts imports cbor2 directly for CDE frame encoding; it was only
resolvable locally because @exadev/wire-mesh-core happens to pull it in
transitively, which pnpm's strict install does not expose as an importable
module for a package that never declared it. CI's fresh install surfaced
this immediately.
@Mearman
Mearman marked this pull request as ready for review September 10, 2026 17:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-10T18:04:00.618098Z 4b149f1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Mearman
Mearman merged commit f112c77 into main Sep 10, 2026
5 checks passed
@Mearman
Mearman deleted the feat/wire-mesh-core-migration branch September 10, 2026 18:04
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.28.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wire protocol has no version negotiation; mixed fleets break state sync during rolling upgrades

1 participant