Repository navigation
fix(sync): hub join pairs again when the hub revoked the device's token - #101
Merged
Merged
Conversation
A device whose token the hub revoked, or that lost it, could not run notesctl hub join again: join reused the paired hub, and sync.join failed with "reach the hub: ... pair again", an unavailable error that a client cannot tell from an unreachable hub (#99, F3). - A new application error, revoked (1006). Every sync method that dials a hub (join, conflicts, resolve, reset, verify, history, readRevision) answers it when the hub refuses the token or the device holds none; other dial failures stay unavailable. - notesctl hub join: when sync.join on a paired hub answers revoked, it says so, runs the pairing flow once and joins again. The new pairing replaces the hub's row and token, and wakes the loops of the vaults that sync with that hub. - sync.join's result names the hub vault and the URL, also before the vault's loop has read its remote (F4: "syncing at : offline"). Fixes #99.
…ault that is not joined Review points of PR #101: syncsAgain's waits use a 20-second context, and docs/design/sync.md says that hub join for a vault still joined answers conflict before the token check, and how to renew the token then.
bketelsen
approved these changes
Oct 27, 2026
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.
Fixes #99 (F3 from Duncan's Snow retest of #98), and F4.
Problem.
notesctl hub joinreused a hub the device had paired with. With a revoked token (or no token),sync.joinfailed withunavailable("reach the hub: … pair again"), so neither the CLI nor the app could tell a refused token from an unreachable hub. Nothing paired again; the only way out was to move the data directory aside.Fix.
revoked(1006), additive.sync.join,conflicts,resolve,reset,verify,historyandreadRevisionanswer it when the hub refuses the device's token or the device holds none (dialErrorininternal/syncer/service.go). Other dial failures stayunavailable.notesctl hub join: whensync.joinon an already paired hub answersrevoked, it prints one line, runs the pairing flow once (code, approval on the hub) and callssync.joinagain. At most 1 new pairing. The new pairing replaces the hub row and token (keep,PutSyncHub) and wakes the loops of every vault on that hub, so a vault in staterevokedsyncs again.sync.join's result names the hub vault and URL, also when the loop's first snapshot has not read its remote yet.hub forgetcommand: pairing again replaces the old hub record, which is what the issue's "done when" asks.Tests.
internal/syncer/rejoin_test.go: a revoked token givesrevokedand leaves no sync state; no token givesrevoked; an unreachable hub staysunavailable; the join result names the hub vault and URL.cmd/notesctl/hub_rejoin_test.go: join → pair → join and then stop (fake, no loop); a real hub and device: join, revoke,sync leave,hub joinpairs again and a note reaches the hub; a vault left in staterevokedsyncs again after another vault'shub joinpairs again. The 2 real-hub tests fail without thehub.gochange.Limits.
hub joinfor a vault still joined in staterevokedanswersconflict(leave first), as before: runhub joinfor another vault, orsync leavethenhub join.readRevision's blob download can still report a 401 asunavailable; the dial path is fixed.Generated:
api/zz_generated.go,app/src/rpc/gen/api.ts,docs/specs/rpc-api.md(make gen). Docs:docs/design/sync.md,docs/specs/sync-protocol.md.Checks: tidy, gen-check, vet, gofmt and
make testpass in the nsl machine; golangci-lint 2.15.0: 0 issues.