Skip to content

Adopt at most one stale link per UISP ID to tolerate MLO sublinks - #1144

Merged
WillNilges merged 4 commits into
mainfrom
wdn/mlo
Nov 15, 2026
Merged

WillNilges merged 4 commits into
mainfrom
wdn/mlo

Conversation

@WillNilges

@WillNilges WillNilges commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When UISP reports two data-link objects for the same device pair (MLO sublinks with distinct UUIDs), the orphan-adoption fallback in import_and_sync_uisp_links re-points every stale MeshDB row to the first new ID processed in a single pass. The second ID then finds no stale rows remaining (they were all just re-pointed) and creates a spurious extra Link.

Root cause

# BEFORE: re-points ALL stale rows to the same new ID
if existing_links:
    for existing_link in existing_links:
        change_list = update_link_from_uisp_data(existing_link, uisp_uuid, ...)

For MLO (2 UISP link IDs, same device pair):

  1. Process ID-A: fallback finds all N stale rows → re-points every one to A
  2. Process ID-B: exact lookup misses (all rows now have A) → fallback finds 0 stale → creates new row
  3. Net: +1 duplicate per import cycle, all rows converge on the same uisp_id

Fix

Adopt at most one stale row per UISP link ID (use existing_links[0] instead of iterating all). The end-of-import sweep handles marking any remaining stale rows INACTIVE.

# AFTER: adopt only the first stale row per new UISP ID
if existing_links:
    existing_link = existing_links[0]
    change_list = update_link_from_uisp_data(existing_link, uisp_uuid, ...)

Steady state after fix

  • 2 active rows for MLO (one per UISP sublink ID)
  • Remaining stale rows marked INACTIVE by end-of-import sweep
  • System self-heals after one import cycle

Tests

Added test_import_and_sync_links_mlo_two_ids_same_device_pair covering the MLO multi-stale-row scenario.

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (02b4c66) to head (c2ac7b5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1144      +/-   ##
==========================================
+ Coverage   95.00%   95.02%   +0.02%     
==========================================
  Files         100      100              
  Lines        4605     4605              
==========================================
+ Hits         4375     4376       +1     
+ Misses        230      229       -1     

☔ 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.

@WillNilges WillNilges changed the title Wdn/mlo Adopt at most one stale link per UISP ID to tolerate MLO sublinks Nov 14, 2026
# stale row before the second ID gets its own match. Any
# remaining stale rows are handled by later iterations or the
# end-of-import inactive sweep.
existing_link = existing_links[0]

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.

Is existing_links ordering ensured stable which would guarantee `existing_links[0] is the one we want to set in case of a change thereby reducing alerts?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Here it doesn't matter because within this block we're already filtering for the relevant link UUID:

existing_links: List[Link] = list(Link.objects.filter(uisp_id=uisp_uuid).select_for_update())

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As a sanity check I also added something to check the link type.

Comment thread docker-compose.yaml
ports:
- 5432:5432
image: docker.io/postgres:15-bookworm
image: docker.io/postgres:17.11-trixie

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.

Cheeky cheeky 😉 adding in infra changes without mention in the PR!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

bold of you to call docker-compose infra. This is for the dev setup. I was just trying to get the thing working. Apparently the meshdb container itself is using pg 17.11, but it's still talking to a pg 15.12 database 🤦🏻 so, this brings dev ever so slightly more in-line with reality.

Comment thread README.md
And if you have access to a database export, you can use the
[scripts/import_datadump.sh](scripts/import_datadump.sh) script to populate
your database
### Loading a Database Export

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.

Thank you! MOAR accurate docs for us noobs.

@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.

@WillNilges

Copy link
Copy Markdown
Collaborator Author

Good question. Ordering is deterministic via Meta.ordering = ["id"] on the Link model — UUID PK order. For the MLO case, all stale rows for the pair are identical in every field (same uisp_id, same device pair, same type, same status) except PK, so there's no "right one" to prefer — any deterministic pick is equally valid.

The fix doesn't change when the "possible duplicate objects" alert fires (still whenever len(existing_links) > 1); it changes what we do about it: adopt one and let the end-of-import sweep mark the rest INACTIVE, rather than re-pointing every one to the same new ID and creating duplicates.

When UISP reports two data-link objects for the same device pair (MLO
sublinks with distinct UUIDs), the orphan-adoption fallback in
import_and_sync_uisp_links re-points every stale MeshDB row to the first
new ID processed in a single pass. The second ID then finds no stale rows
remaining and creates a spurious extra Link.

Fix: adopt at most one stale row per UISP link ID (existing_links[0]
instead of iterating all). Prefer a type-matching stale row when types
differ, falling back to the first row by UUID order. The end-of-import
sweep marks any remaining stale rows INACTIVE.

Adds test_import_and_sync_links_mlo_two_ids_same_device_pair covering the
MLO multi-stale-row scenario.
@WillNilges
WillNilges merged commit edb42f9 into main Nov 15, 2026
14 checks passed
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