Skip to content

A joining iPhone or iPad no longer makes a second Personal space - #1106

Merged
serafimcloud merged 6 commits into
yetanotherbrowser:mainfrom
advenimus:advenimus/sync-join-repair
Nov 24, 2026
Merged

serafimcloud merged 6 commits into
yetanotherbrowser:mainfrom
advenimus:advenimus/sync-join-repair

Conversation

@advenimus

Copy link
Copy Markdown
Contributor

What changes

When an iPhone or iPad joins sync, it no longer makes a second Personal space. A device that already made one moves its tabs back into the first Personal and deletes the copy, by itself.

Part 1 of 4 replacing #1049. It stands alone on main.

Why it happened

A joining device took the account after the first page of the catch-up, before the Mac's spaces had arrived. With no Personal in sight it made its own, so the account ended up with two Personal spaces, and the sidebar foot showed the same icon twice.

  • SyncBridge now takes the account only when the line is .live, meaning the whole catch-up is in.
  • A launch takes it only after one whole catch-up has finished at least once. A "caught up once" mark is kept in browser-ids.json. Files from before this change read as caught up, so devices already in sync are not affected.
  • Repair (SyncBridge+JoinRepair.swift):
    • Only the device that made the copy acts.
    • It moves the copy's tabs into the first Personal (00000000-…0001) and drops pins that are already there by URL.
    • Then it deletes the emptied copy.
    • Running it twice changes nothing.
    • Tab records already follow removal-wins.
  • docs/sync.md describes the rule.

Ruled out:

  • A merge on every device: two devices could each move the same tabs.
  • A fix in the shared sync engine: it would change the Mac. The gate on the iPhone side is enough.

Proof

  • Logic: SyncBridgeTests, new tests that fail on main and pass here:
    • a join that stops partway through the catch-up takes no account;
    • a launch before any whole catch-up waits;
    • the second Personal is repaired, and pins already in the first are not duplicated;
    • two phones joining at once;
    • a device that didn't make the copy leaves it alone.

Checked on

  • iPad Pro 13" and iPhone 18 Pro simulators, iOS 27.2. Yab Dev on an iPad Air and an iPhone 18 Pro.
  • Engine(s) tried: not about a page.

Checklist

  • SyncBridgeTests and HistoryTests: iPad 99/99, iPhone 75/75.
    • Known, also on main: testTheJoinSheetComesBackUntilThisIPhoneIsIn and testTheRecoveryKeyLetsTheIPhoneIn fail when run after BrowserKeysTests.
    • testAPushInTheBackCatchesUpAndClosesTheLine is flaky on main too.
  • ./design-check --base origin/main and scripts/swift-parse-check --base origin/main are clean.
  • Nothing visible changes.

…ing the account

Root cause: SyncBridge.receive took the account on the first catch-up
page that carried any space. The server sends a catch-up oldest change
first, 500 records a page, so another space (ECI) can come pages before
the account's first space. The rebuild then found no first space to merge
the starting Personal into, imported it, and flushLocal pushed it as a new
space. An iPhone that joined this way gave the account a second Personal,
which every device, the iPad's sidebar foot included, shows.

Taking the account from a batch now needs the line live; the catch-up's
end already takes it in changed(.live), as a rejoin does.
…irst and deletes it

Root cause: before the join waited for the whole catch-up, an iPhone could
take the account on a catch-up page that had Work but not yet the first
space. Its used starting Personal then had no first space to merge into,
so flushLocal sent it up under a fresh id (browser-ids.json maps
local.personal to it). The existing prune never removes it: it holds
pages, and its maker is a living device.

Only the device that made the copy repairs it, on each live line, beside
pruneEmptyPersonals: its own mapping names the copy, the first space is
in, the copy is still Personal with the house, has no sign-ins or folders,
and holds no other device's tab of today. Its tabs go into the first space
with the existing merge (pins pinned, kept kept), the moves are written,
and the copy is deleted only once the journal holds nothing of it but
blanks. One device only, because a tab's removal wins and two devices
moving and deleting at once could lose a tab. The merge also no longer
doubles a pin the first space already has at that address.
Three places decided whether a space is still the starting Personal:
the join's merge (name only), the empty-Personal prune and the
broken-join repair (name and house, trimmed). They now share
isStartingPersonal(name:icon:), so the merge, too, treats a starting
space given another icon as the person's own, as the repair already did.

The merge's pin dedupe built its set from every pin of the first space,
a pin with no address as "". Blank pins never reach the compare (isBlank
drops them first), so no pin was lost, but the set now holds only real
addresses and a test pins that two address-less pins are no duplicates.
SyncBridge.swift is over 3,000 lines, and the broken-join repair is a
self-contained rule with its own tests. joinDuplicate,
repairJoinDuplicate and isStartingPersonal move as they are into
SyncBridge+JoinRepair.swift; the bridge's app, mirror and ids become
readable (private(set)) and its log internal so the extension can reach
them. No behavior change; SyncBridgeTests pass as before.
A first catch-up cut after a page (Work in, the first space not yet)
left a journal with spaces. The next launch took the account from it
before the line was up, and the starting Personal went up as a second
Personal. The in-session path already waited for live; the launch path
read "the journal holds spaces" as "caught up".

The phone's own association file (browser-ids.json) now keeps a mark
set when the line first reaches live, and a launch takes the account
from the journal only with it. Fixture worlds and seeds keep today's
rule: they have no saved association.

Migration: a file saved before the mark existed is read as caught up.
It is written only after the iPhone took the account, so an install
that joined on an older build keeps taking it offline at launch.
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect iPhone joins and shared space records across devices.

Fix the saved-pin deletion before merging; preserving split views also needs attention.

Findings

  1. P1 Distinct saved pins get deleted ▶
  2. P2 Repair loses Mac split views ▶

Summary

This PR waits for a full sync catch-up before adopting an account and repairs duplicate Personal spaces on the device that created them.

  • Joining iPhones wait for every catch-up page before syncing their spaces.
  • The iPhone that made a duplicate Personal folds it into the account’s first space.

Two repair cases need attention: distinct saved pins can be deleted, and Mac split views are lost. The iOS tests were not run here.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Load saved journal] --> B{Caught up before?}
    B -->|Yes| C[Adopt saved account]
    B -->|No| D[Wait for full catch-up]
    C --> E[Line becomes live]
    D --> E
    E --> F[Save caught-up mark]
    F --> G{This device created a duplicate?}
    G -->|Yes| H[Merge tabs into first Personal]
    H --> I[Write tab moves]
    I --> J[Delete emptied copy]
    G -->|No| K[Keep spaces unchanged]
Loading

Reviews (1) · Last reviewed commit: "fix: a launch takes the account only aft..." · Reviewed by Greptile

Comment on lines +1600 to +1602
let pinned = Set(first.pins.filter { !isBlank($0) }.compactMap { $0.url.map(address) })
for tab in start.keptTabs where !isBlank(tab) && !have.contains(tab.id) { out.kept.append(.tab(tab)) }
for tab in start.pins where !tab.isPrivate && !isBlank(tab) && !have.contains(tab.id) { out.pins.append(tab) }
for tab in start.pins where !tab.isPrivate && !isBlank(tab) && !have.contains(tab.id) && !pinned.contains(tab.url.map(address) ?? "") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Distinct saved pins get deleted. The new filter compares each pin's current url, not its saved home. On a Mac, pins with different saved addresses can both navigate to the same page, such as a sign-in page. If one is in each Personal space, repair drops the copy's pin and flushLocal() deletes its record everywhere, including its distinct saved address. Compare saved addresses from the sync records, falling back to the current address only when no home exists.

Comment on lines +54 to +61
flushLocal()
let row = engine.row(copy)
guard row.folders.isEmpty, (row.all + row.elsewhere).allSatisfy({ Self.blankURL($0.url) }) else {
log.notice("sync: the second Personal still holds tabs; its delete waits")
return true
}
log.notice("sync: moved the second Personal a broken join made into the first space")
deleteSpace(local)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Repair loses Mac split views. A duplicate Personal can contain two shared pins or kept tabs paired on a Mac and still pass these checks. flushLocal() moves the tabs, but PhoneSync.move leaves their SyncPair records under the copy. deleteSpace then removes those records, so the Mac loses the saved split view. Move pairs whose tabs survive into the first space too, or skip such copies before moving their tabs.

@serafimcloud
serafimcloud merged commit 6330e20 into yetanotherbrowser:main Nov 24, 2026
5 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