Skip to content

Fix: duplicate Link objects for MLO links with rotating UISP UUIDs - #1143

Closed
WillNilges wants to merge 3 commits into
mainfrom
fix/uisp-mlo-link-duplicates
Closed

WillNilges wants to merge 3 commits into
mainfrom
fix/uisp-mlo-link-duplicates

Conversation

@WillNilges

Copy link
Copy Markdown
Collaborator

Problem

Device nycmesh-713-mlo6-3461 (NN 713) accumulated 24 near-identical Link rows connecting it to nycmesh-3461-mlo6-713 (NN 3461) — all sharing the same uisp_id, which no longer exists in UISP. This was the only duplicate group in the entire 2,945-link table, i.e. specific to this link pair.

Root cause (verified against live UISP + MeshDB data):

  • UISP reports this MLO link as two data-link objects (one per radio), both with the same device endpoints, and their UUIDs rotate whenever the MLO link re-establishes (observed cadence: ~6–8 times/day over 11-09 → 11-12).
  • The orphan-adoption fallback in import_and_sync_uisp_links (added in Fix: slack spam due to rotating UISP link UUIDs #700 for rotating ethernet link UUIDs) is designed for one link per device pair: it re-points every orphaned row on the pair to the incoming UUID. Each import therefore adopted all 23 stale rows onto the first sublink's new ID, after which the second sublink's ID found nothing to adopt and created a new row. Net: +1 duplicate per re-establishment, and all rows converge on the same (now-stale) uisp_id.

Note: the top-level frequency field is misreported for MLO sublinks (both report 5710 MHz even though one is a 320 MHz 6 GHz channel), so the link type is mislabeled "5 GHz Airmax" on both — a UISP-side issue that should eventually be fixed there.

Fix

The two sublink objects are distinguishable by their per-end interface identification (e.g. wifi0/main vs wifi1/backup), which identifies the radio and is stable across UUID rotation. This PR:

  1. Persists that identification on Link: new nullable from_interface_name, from_interface_description, to_interface_name, to_interface_description (migration 0015, mirrored on HistoricalLink).
  2. Narrows orphan-adoption candidates by interface signature (orientation-insensitive):
    • matching orphan row(s) → adopt only those;
    • no match but some candidates have known interfaces → different radio → create instead of adopting;
    • no interface info (legacy rows / bare payloads) → existing behavior, unchanged.
  3. Persists interfaces on both adoption and creation.

Tests

  • 4 new regression tests in test_uisp_import.py: MLO rotation adopts the correct row per radio (no new rows); a genuinely new radio creates a row; legacy NULL-interface rows still adopt and gain interface data; no-interface payloads keep legacy behavior.
  • Updated 2 existing tests (mock call signature, Slack notification JSON).
  • pytest (unit), mypy, black, isort, flake8 all pass. (test_nn.py::TestNNRaceCondition fails on clean main as well — pre-existing.)

Data cleanup (separate, manual)

The existing 23 duplicate rows are not auto-deleted. After this deploys, the next import converges them onto current UUIDs and stamps their interfaces; then 22 of the 23 can be deleted.

UISP reports MLO links (e.g. Wave-MLO6 pairs) as one data-link object per
radio, all on the same device pair, and the objects' UUIDs rotate whenever
the MLO link re-establishes. The orphan-adoption fallback (added for
rotating ethernet link UUIDs) was designed for one link per device pair:
it re-points every orphaned row on the pair to the incoming UUID, so each
import adopted all stale rows onto the first sublink's new ID, after which
the second sublink's ID found nothing to adopt and created a brand-new
row. Net effect: +1 duplicate Link per re-establishment, all rows sharing
the same (now-stale) uisp_id. This produced 24 near-identical links for
nycmesh-713-mlo6-3461 <-> nycmesh-3461-mlo6-713.

The two sublink objects are distinguishable by their per-end interface
identification (e.g. wifi0/main vs wifi1/backup), which identifies the
radio and is stable across UUID rotation. Persist that identification on
Link (from/to interface name + description) and use it to narrow orphan
adoption candidates:

- if an orphaned row's interface signature matches the incoming link,
  adopt only the matching row(s);
- if no orphaned row matches but some have known interfaces, the incoming
  link is a different radio -> create it instead of adopting;
- if there is no interface info (legacy rows / bare payloads), keep the
  existing device-pair-only behavior.

Note: the top-level 'frequency' field is misreported for MLO sublinks
(both report 5710 MHz despite one being a 320 MHz 6 GHz channel), so it
is not used for matching; link type remains mislabeled until UISP fixes
its reporting.

The existing 23 duplicate rows are not auto-cleaned; they converge onto
current IDs and gain interface data on the next import, after which they
can be deleted manually.
Comment thread src/meshapi/models/link.py Resolved
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.99%. Comparing base (02b4c66) to head (301ef06).

Files with missing lines Patch % Lines
src/meshapi/util/uisp_import/sync_handlers.py 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1143      +/-   ##
==========================================
- Coverage   95.00%   94.99%   -0.01%     
==========================================
  Files         100      100              
  Lines        4605     4639      +34     
==========================================
+ Hits         4375     4407      +32     
- Misses        230      232       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: Willard Nilges <willardnilges@gmail.com>
@lotia

lotia commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Strangely the referenced test_nn.py::TestNNRaceCondition does not fail in CI. All tests run there as we can see here
https://github.com/nycmeshnet/meshdb/actions/runs/43363301070/job/131681638293#step:7:73

@lotia lotia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of suggestions, which will are not semantically relevant. Other than that it looks good to me.

I have NOT run tests locally since they are slow and also tend to fail when they don't in CI. I have look at the CI test output and we have passing tests!

}
}
}
if from_iface is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nitpick and semantically irrelevant but you did ask for a detailed review 😉

Understand this is a test but want to clarify whether you were checking for the actual None object/type rather than a falsy value where the general idiom is

if not from_iface:

note that the above will also be true for 0, False and "" so my suggestion may be bunk here.

from_end["interface"] = {
"identification": {"type": "wlan", "name": from_iface[0], "description": from_iface[1]}
}
if to_iface is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@WillNilges WillNilges closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants