fix(core): address concurrent relay pairings by device, not by recency - #174
Merged
Merged
Conversation
Adds a deviceC fixture and RED tests proving mesh-session's relay handling must read to-device/from-device per frame rather than track a single most-recently-established pairing: concurrent relay pairings must each attribute an inbound request to its real sender, a response must address back to that sender even after a different pairing was established in between, and a previously-paired target must not trigger a redundant relay-connect after pairing with someone else. Also updates the existing fromDevice/relay-connect assertions to match the wire-mesh#30 hub, which always stamps from-device on every forwarded relay-data frame.
mesh-session tracked at most one active relay pairing in a single relayPeerDevice field, shared across every device this connection was ever paired with. Establishing a new pairing silently overwrote it, so an inbound request was always attributed to whichever peer paired most recently rather than whoever actually sent it, and a response was addressed back the same wrong way -- relay-hub.ts has forwarded real per-frame to-device/from-device addressing since wire-mesh#30, but mesh-session never read or wrote either field. Replaces the single field with a relayPairings map of every pairing this connection currently holds, used only to avoid a redundant relay-connect for an already-paired target. Outbound relay-data is now always explicitly addressed: sendManageRequest stamps to-device with its own targetDevice, and respond() echoes back whatever from-device the original request actually carried. Inbound attribution (fromDevice and the new toDevice, for a caller fronting more than one local device behind one hub connection) is read solely from each relay-data frame's own fields, never guessed from pairing state.
mesh-session.ts's relay-connect/relay-data handling had grown past the project's own 800-line file budget once addressing was fixed to read to-device/from-device per frame instead of a single tracked pairing. Pulls two genuinely reusable pieces out into their own small modules rather than trimming comments to fit: relay-pairing.ts owns the "which devices is this connection already paired with" set (used only to avoid a redundant relay-connect), and frame-codec.ts's new wrapRelayData mirrors its own tryDecodeFrame for the outbound side of the same relay-data envelope. applyManageRequest now takes the relay-data-frame itself rather than two separately-threaded fields, since it already carries both to-device and from-device. No behaviour change.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #170
mesh-session.tstracked at most one active relay pairing per connection in a singlerelayPeerDevicefield, shared across every device that connection was ever paired with. Establishing a new pairing silently overwrote it, so an inbound relay-data request was always attributed to whichever peer paired most recently rather than whoever actually sent it, and a reply was addressed back the same wrong way.relay-hub.tshas forwarded real per-frameto-device/from-deviceaddressing since #30 (a multiplexed adjacency map, not a single slot), butmesh-session.tsnever read or wrote either field on its own side of the wire.This replaces the single field with a
relayPairingsmap of every pairing the connection currently holds (used only to avoid a redundantrelay-connectfor an already-paired target). Outboundrelay-datais now always explicitly addressed:sendManageRequeststampsto-devicewith its owntargetDevice, andrespond()echoes back whateverfrom-devicethe original request actually carried. Inbound attribution (fromDevice, and a newtoDevicefor a caller fronting more than one local device behind one hub connection, e.g. a gateway) is read solely from eachrelay-dataframe's own fields, never guessed from pairing state.Root cause and fix are entirely within
wire-mesh-core; agent-comms is not touched, per the issue.