fix(sync): the requesting device must never show an approval prompt (+ backfill legacy initialized flag)#12
Merged
Conversation
…ed flag for legacy devices After #11, the existing origin device had no per-chain initialized flag (it was paired before the flag existed), so it was treated as needsTransfer=true and auto-requested too — causing the brand-new requesting device to be shown an approve/deny prompt for its own join. Fixes: - One-time legacy backfill in startSync: a device that already holds notes is grandfathered as initialized (it's the chain's source of truth) so it stops auto-requesting. Empty devices still request normally. Marker-gated. - Hard guards regardless of flag state: a device that still needs an initial transfer ignores transfer-requested (nothing to send), never approves its own request, and never requests a transfer from itself (client + server reject).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom (after #11)
The brand-new device that's requesting to join also shows an approve/deny prompt — i.e. it appears to approve its own join. Both devices end up prompting each other.
Root cause
Two issues, both stemming from the per-chain
initializedflag introduced in #11:notes-sync-initialized-roomentry. After fix(sync): classify transfer-need by explicit join intent + auto-request source so approval prompt appears #11 it is therefore treated as "not initialized" → it declaresneedsTransfer: true→ it auto-requests a transfer too. With both devices requesting, the server relays atransfer-requestedto each, so the new (empty) device is shown an approval prompt for a join it can't possibly satisfy.(A fresh device starts with zero notes — confirmed in
useNotes.loadNotes— so "holds notes" is a reliable signal here, unlike the earlierhasDataattempt where the test device wasn't actually empty.)Fix
transfer-requestedmessages — it has nothing to send, so it never shows an approval prompt.requesterId === self).request-transfer-from).Net effect for the reported case: the existing device (has notes) is correctly the approver and stops auto-requesting; the new empty device is the requester and is never shown an approve/deny prompt.
Files changed
src/utils/sync.ts—migrateInitFlagIfNeeded()(run instartSync); ignoretransfer-requestedwhile we still need a transfer or when it's our own; never request from self.server/src/index.ts— reject arequest-transfer-fromwhose target is the requester itself.Verification
initialized→needsTransfer:false→ no longer auto-requests, shows the prompt; new empty device →needsTransfer:true→ requests, and the guard means it never shows a prompt. Both devices prompting each other is no longer possible.tsc/build/lint — sandbox has no installed toolchain for either workspace and installs are blocked (registry 403). Changes use only existing in-scope symbols.Manual test plan