fix(channel-detection): prevent phantom swaps when channels share PSK+name (#3452)#3453
Conversation
…antom swaps (#3452) Duplicate channel identities (same PSK + name) caused detectChannelMoves to emit phantom bidirectional swaps on every config sync, progressively corrupting message-to-channel attribution. Guard now requires the (psk, name) key to be unique in both before and after snapshots before matching; ambiguous identities are skipped (messages stay put) rather than incorrectly migrated. https://claude.ai/code/session_01P8be9VE84SBL1LoGefsQ3c
|
Claude finished @Yeraze's task —— View job Code Review Complete ✅Reviewing PR #3453 for channel detection phantom swap fix. Todo List
Overall Assessment: Excellent Fix 🎯This PR provides a clean, well-tested solution to a tricky edge case. The phantom swap issue was correctly identified and the fix is both safe and effective. ✅ Code Quality & Best PracticesStrong points:
Minor suggestions:
✅ Logic & ImplementationThe fix is sound:
Edge cases handled:
✅ Test Coverage - ComprehensiveExcellent regression test suite:
The test names clearly describe scenarios, making future maintenance easier. ✅ Performance ConsiderationsEfficient implementation:
For typical channel configurations (2-8 channels), performance impact is negligible. ✅ Security ConsiderationsNo security concerns identified:
✅ Architecture AlignmentFits well with existing codebase:
SummaryThis is a high-quality fix that:
Recommendation: Approve and merge 🚀 The solution is production-ready and effectively resolves issue #3452 without introducing new risks. |
Bump version to 4.10.3 across package.json, package-lock.json, helm/meshmonitor/Chart.yaml, desktop/package.json, and desktop/src-tauri/tauri.conf.json. Finalize the CHANGELOG: promote [Unreleased] to [4.10.3] and add the entries merged after the section was last written — MQTT NodeInfo clobber fix (#3456), Traffic Management/StatusMessage firmware-version gate (#3457), local-node module config storage (#3460), phantom channel swap fix (#3453), and the TX power help-text clarification (#3459). Add a release blog post highlighting the Traffic Management detection fix and the bug-fix round. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Fixes #3452 —
detectChannelMovesinsrc/server/utils/channelMoveDetection.tsproduced phantom bidirectional swap detections whenever two channels shared the same(psk, name)pair. On every config sync this triggeredmigrateMessagesForChannelMoves, progressively scrambling message↔channel attribution.Root cause: the matcher had no uniqueness guard — a duplicate identity in either snapshot caused each side to match the other, generating a bogus
slot X→Y, slot Y→Xswap that recurred forever.Fix: before matching, count occurrences of each
(psk, name)key in both the before and after snapshots. If the key appears more than once in either snapshot the identity is ambiguous — skip it. Messages stay in place (no corruption), which is strictly safer than mis-migrating them. Unique identities are still matched correctly, so genuine single-moves and genuine swaps continue to work.Changes
src/server/utils/channelMoveDetection.ts— addedchannelKey/countByKeyhelpers;detectChannelMovesnow guards on uniqueness before matchingsrc/server/utils/channelMoveDetection.test.ts— 4 new regression tests covering the phantom-swap scenario, the mixed unique+duplicate case, and the unchanged genuine-swap pathTest plan
npm test— all 10 tests inchannelMoveDetection.test.tspass (6 original + 4 new regression tests)channel_migration_on_startupentries inaudit_loghttps://claude.ai/code/session_01P8be9VE84SBL1LoGefsQ3c
Generated by Claude Code