0.5.4: send handshake on replacement transports in _createPeer#23
Merged
0.5.4: send handshake on replacement transports in _createPeer#23
Conversation
Companion fix to v0.5.3. When the dual-dial dedup or stale-prior swap path in _createPeer replaced an existing transport, the new transport was registered in existingPeer.transports but no handshake was sent on it — _addPeer (which sends the handshake) is only called for brand-new peers, not transport replacements. The remote (sym-swift) saw the new connection reach .ready, sent its own handshake, and waited for ours. Ours never arrived. ~10 seconds later the heartbeat tick fired `ping` on every transport, the remote saw `ping` as the first frame, and disconnected with "[SYM] session: expected handshake, got ping" — protocol violation. Net result: every reconnect after a dedup-replace was killed within 10 seconds by the protocol-violation trip-wire, producing the flap loop visible on Mac Catalyst MeloMove. Fix: extracted handshake-build into _buildHandshake() helper; the existing-peer branch in _createPeer now sends the handshake on every newly-registered transport. Idempotent — if the remote already sent its handshake, it processes both fine. Verified end-to-end on Mac Catalyst MeloMove ↔ claude-code-mac on the same Mac. Connection stays stable, peers persist in the UI, CMBs flow continuously without the 10s drop. 150/150 unit tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Companion fix to v0.5.3. When the dual-dial dedup or stale-prior swap path in `_createPeer` replaced an existing transport, the new transport was registered in `existingPeer.transports` but no handshake was sent on it — `_addPeer` (which sends the handshake) is only called for brand-new peers, not transport replacements.
The remote (sym-swift) saw the new connection reach `.ready`, sent its own handshake, and waited for ours. Ours never arrived. ~10 seconds later the heartbeat tick fired `ping` on every transport, the remote saw `ping` as the first frame, and disconnected with `[SYM] session: expected handshake, got ping` — protocol violation.
Field evidence
```
[SYM] session: expected handshake, got ping
[SYM] session: disconnected: Connection closed
```
That log line on Mac Catalyst MeloMove was the closing-disconnect every ~10 seconds in the flap loop. Every reconnect after a dedup-replace was killed by the protocol-violation trip-wire.
Fix
Extracted handshake-build into `_buildHandshake()` helper; the existing-peer branch in `_createPeer` now sends the handshake on every newly-registered transport. Idempotent — if the remote already sent its handshake from its side, it processes both fine.
Tests
150/150 existing unit tests pass.
Test plan
🤖 Generated with Claude Code