Skip to content

fix(legacy-ab): align legacy address book peer lookup with new API behavior - #423

Merged
YuZhiYuanDev merged 3 commits into
mainfrom
fix/legacy-ab-peer-lookup
Oct 11, 2026
Merged

YuZhiYuanDev merged 3 commits into
mainfrom
fix/legacy-ab-peer-lookup

Conversation

@hashbk

@hashbk hashbk commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Align findOrCreatePeer with the new API (address-book-peer.service.ts): non-IP devices must already exist in the peers table (registered via heartbeat) before they can be added to the address book; IP-format devices are still created on demand
  • In updateLegacyAddressBook, catch NotFoundException for unregistered non-IP devices and skip them with a warning log instead of creating a peer with a server-generated UUID
  • Remove the fallback sysinfo lookup from getLegacyAddressBook (no longer needed since peers are no longer created with server-generated UUIDs for non-IP devices)

Problem

The legacy address book's findOrCreatePeer unconditionally created a peers record with a server-generated uuid (via uuidv4()) for any device not found in the peers table. This differs from the new API behavior, where non-IP devices must have already registered via heartbeat (ensuring peers.uuid matches the client-reported uuid stored in sysinfos).

The server-generated uuid doesn't match any sysinfos.uuid record, causing getLegacyAddressBook to return empty username/hostname/platform for that peer.

Solution

Instead of creating peers on demand with server-generated UUIDs (which led to sysinfo lookup failures), reject non-IP devices that haven't sent a heartbeat — consistent with the new API. IP-format devices are still created automatically since they are reached via direct IP and never register through heartbeats.

When updating the legacy address book, devices that fail this check are skipped with a warning log, allowing the remaining valid devices to be synced successfully.

…gistration

When a peer is* added to the legacy address book before the device sends
its first heartbeat, findOrCreatePeer generates a server-side uuid that
differs from the client-reported uuid stored in sysinfos. This causes
getLegacyAddressBook to return empty username/hostname/platform because
sysinfoMap.get(deviceId) misses.

- findOrCreatePeer: order by lastHeartbeat DESC so the heartbeat-created
  peers record (with the client uuid) is preferred over a stale
  server-generated one.
- getLegacyAddressBook: add a fallback path that, for peers missing
  sysinfo, looks up all peers records by peers.id and finds the one
  with a heartbeat, then resolves sysinfo through that record's uuid.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cb104995-7966-4c36-afcb-1d2a7e23f8c8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Align findOrCreatePeer with the new API behavior: non-IP devices must
already exist in the peers table (registered via heartbeat) before they
can be added to the address book. IP-format devices are still created
on demand since they are reached via direct IP and never register
through heartbeats.

In updateLegacyAddressBook, catch NotFoundException and skip the
unregistered device with a warning log instead of failing the entire
operation.

Remove the fallback sysinfo lookup from getLegacyAddressBook since
peers are no longer created with server-generated UUIDs for non-IP
devices, making the fallback unnecessary.
@hashbk hashbk changed the title fix(legacy-ab): resolve sysinfo for peers created before heartbeat registration fix(legacy-ab): align legacy address book peer lookup with new API behavior Oct 11, 2026
@YuZhiYuanDev
YuZhiYuanDev merged commit 0f7673a into main Oct 11, 2026
12 checks passed
@YuZhiYuanDev
YuZhiYuanDev deleted the fix/legacy-ab-peer-lookup branch October 11, 2026 07:04
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