PNI-only contacts synced from Storage Service are left with RegisteredState.UNKNOWN and never appear in New Chat

Open Beginner friendly
#15,142 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ArviFoxy is already working on this.

Since Nov 22, 2026.

  • #15143 by @ArviFoxy — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin, sqlite
Domain
database

Research direction

Start in RecipientTable.kt at getValuesForStorageContact (around lines 4790-4797) and compare its ACI-only check with buildContentValuesForNewUser (line 4740) and ContactRecordProcessor.isInvalid (104-109). The fix is to treat a valid PNI like an ACI when deciding REGISTERED; then verify a PNI-only ContactRecord with unregisteredAtTimestamp == 0 is inserted with registered = 1 and appears in the New Chat query. Also inspect ContactDiscovery.kt:56, where refresh exits early without Contacts permission.

Written by the indexing model from the issue text.

Description

Guidelines
  • I have searched open and closed issues for duplicates
  • I am submitting a bug report for existing functionality that does not work as intended
  • This isn't a feature request or a discussion topic
Bug description
Summary

When a valid PNI-only ContactRecord (unregisteredAtTimestamp = 0, whitelisted = true, pni/pniBinary, e164, and a name/nickname, with no aci) is synced from Storage Service, Signal-Android inserts or updates the recipient without setting RecipientTable.REGISTERED. The row stays at SQLite's default RegisteredState.UNKNOWN (0) and logs:

Contact is marked as registered, but has no serviceId! Can't locally mark registered.

Because New Chat queries (ContactSearchSelection.SIGNAL_CONTACT and getSignalOnlyContactsForIndex) require registered = 1, these contacts do not appear in the New Chat contact list. If Android Contacts permission is not granted, ContactDiscovery.refreshAll returns early (ContactDiscovery.kt:56), so neither pull-to-refresh nor DirectoryRefreshJob ever marks them registered and they stay missing indefinitely.

Why this matters

CDSv2 only returns a PNI (never an ACI) for phone numbers you haven't messaged yet, and Signal clients upload these PNI-only contacts to Storage Service (RecipientTable.getContactStorageSyncIdsMap, line 1320). This breaks any case where a PNI-only contact arrives via Storage Sync on an Android device without a subsequent CDS refresh — for example:

  • Restoring an account on Android (or syncing to a linked Android device) without granting Android system Contacts permission, where previously discovered PNI-only contacts are restored from Storage Service.
  • Syncing PNI-only contacts discovered on another device (e.g. Signal-iOS or a linked device). I ran into this while building a Telegram -> Signal migration tool that discovers Signal contacts via CDSv2 and writes PNI-only ContactRecords to Storage Service. Those contacts appear immediately on Signal-iOS and Signal-Desktop, but do not appear in New Chat on Signal-Android even after pulling down to refresh.

The workaround is forcing the user to grant Contacts permission which isn't great..

Root cause

In app/src/main/java/org/thoughtcrime/securesms/database/RecipientTable.kt (getValuesForStorageContact, lines 4790–4797 on main / 8959dc6e):

put(UNREGISTERED_TIMESTAMP, contact.proto.unregisteredAtTimestamp)
if (contact.proto.unregisteredAtTimestamp > 0L) {
  put(REGISTERED, RegisteredState.NOT_REGISTERED.id)
} else if (contact.proto.signalAci != null) {
  put(REGISTERED, RegisteredState.REGISTERED.id)
} else {
  Log.w(TAG, "Contact is marked as registered, but has no serviceId! Can't locally mark registered. (Phone: ${contact.proto.e164.nullIfBlank()}, Username: ${username?.isNotEmpty()})")
}

Line 4793 only checks contact.proto.signalAci != null and ignores contact.proto.signalPni, even though:

  1. The warning message itself says has no serviceId, not has no ACI.
  2. ContactRecordProcessor.isInvalid (ContactRecordProcessor.kt:104-109) accepts contacts with either a valid ACI or a valid PNI.
  3. Other paths in RecipientTable.kt treat either ACI or PNI as sufficient to mark a recipient registered or as a ServiceId:
    • buildContentValuesForNewUser (RecipientTable.kt:4740): if (pni != null || aci != null) sets REGISTERED = RegisteredState.REGISTERED.id
    • processPnpTuple (RecipientTable.kt:3015-3023): PnpOperation.SetPni sets REGISTERED = RegisteredState.REGISTERED.id
    • applyStorageSyncContactInsert (RecipientTable.kt:972) and applyStorageSyncContactUpdate (RecipientTable.kt:1030): signalAci != null || signalPni != null
    • getValuesForStorageContact (RecipientTable.kt:4800, 4803): contact.proto.signalAci ?: contact.proto.signalPni
Cross-client behavior (Signal-iOS & Signal-Desktop)

Both other official clients already mark PNI-only ContactRecords with unregisteredAtTimestamp == 0 as registered:

  • Signal-iOS (SignalServiceKit/StorageService/StorageServiceProto+Sync.swift:493-504) requires AtLeastOneServiceId(aci:pni:) and unconditionally calls markAsRegisteredAndSave whenever unregisteredAtTimestamp is unset/0:
    } else {
        recipientManager.markAsRegisteredAndSave(
            &recipient,
            shouldUpdateStorageService: false,
            tx: transaction,
        )
    }
    
    guard let serviceIds = AtLeastOneServiceId(aci: recipient.aci, pni: recipient.pni) else {
        owsFailDebug("Can't have a merge result without a ServiceId")
        return .invalid
    }
    
  • Signal-Desktop (ts/services/storageRecordOps.preload.ts:1800-1804) similarly calls conversation.setRegistered({ fromStorageService: true, shouldSave: false }) whenever !contactRecord.unregisteredAtTimestamp || contactRecord.unregisteredAtTimestamp === 0n, regardless of whether the record has an ACI or only a PNI.

Aligning RecipientTable.getValuesForStorageContact with buildContentValuesForNewUser (if (pni != null || aci != null)) and ContactRecordProcessor.isInvalid brings Android into line with both iOS and Desktop.

Steps to reproduce
  1. On a Signal-Android device without Contacts permission (or before DirectoryRefreshJob runs), sync a Storage Service ContactRecord that has pni/pniBinary, e164, whitelisted = true, a nickname (or name), unregisteredAtTimestamp = 0, and no aci for a user not already in the local recipient table.
  2. Open New Chat on Signal-Android (and optionally pull down to refresh).
Actual result
  • RecipientTable.getValuesForStorageContact logs "Contact is marked as registered, but has no serviceId! Can't locally mark registered." and omits REGISTERED.
  • The recipient is inserted with registered = 0 (RegisteredState.UNKNOWN) and does not appear in New Chat.
  • Without Contacts permission, pulling down to refresh does not resolve it because ContactDiscovery.refreshAll exits early.
Expected result

A ContactRecord with unregisteredAtTimestamp == 0 and a valid PNI (even without an ACI) is marked RegisteredState.REGISTERED and appears in New Chat immediately after Storage Sync, matching Signal-iOS and Signal-Desktop.

Screenshots

No response

Device

No response

Android version

No response

Signal version

No response

Link to debug log

No response

Dominant language
Kotlin
Stars
29.7k
Forks
7k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from signalapp/Signal-Android

All issues in signalapp/Signal-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.