Skip to content

fix(sync): hub join pairs again when the hub revoked the device's token - #101

Merged
bketelsen merged 2 commits into
mainfrom
irulan/hub-join-revoked
Oct 27, 2026
Merged

bketelsen merged 2 commits into
mainfrom
irulan/hub-join-revoked

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Fixes #99 (F3 from Duncan's Snow retest of #98), and F4.

Problem. notesctl hub join reused a hub the device had paired with. With a revoked token (or no token), sync.join failed with unavailable ("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.

  • New application error revoked (1006), additive. sync.join, conflicts, resolve, reset, verify, history and readRevision answer it when the hub refuses the device's token or the device holds none (dialError in internal/syncer/service.go). Other dial failures stay unavailable.
  • notesctl hub join: when sync.join on an already paired hub answers revoked, it prints one line, runs the pairing flow once (code, approval on the hub) and calls sync.join again. 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 state revoked syncs again.
  • F4: sync.join's result names the hub vault and URL, also when the loop's first snapshot has not read its remote yet.
  • No hub forget command: 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 gives revoked and leaves no sync state; no token gives revoked; an unreachable hub stays unavailable; 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 join pairs again and a note reaches the hub; a vault left in state revoked syncs again after another vault's hub join pairs again. The 2 real-hub tests fail without the hub.go change.

Limits.

  • hub join for a vault still joined in state revoked answers conflict (leave first), as before: run hub join for another vault, or sync leave then hub join.
  • readRevision's blob download can still report a 401 as unavailable; 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 test pass in the nsl machine; golangci-lint 2.15.0: 0 issues.

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.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 27, 2026
@bketelsen
bketelsen merged commit 80e15c0 into main Oct 27, 2026
8 checks passed
@bketelsen
bketelsen deleted the irulan/hub-join-revoked branch October 27, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hub join: a device whose token was revoked cannot pair again

2 participants