Skip to content

fix(desktop): canonicalize relay URL in welcome team scoping - #5309

Open
BradGroux wants to merge 2 commits into
block:mainfrom
BradGroux:fix/desktop-welcome-team-relay-url-canonicalize
Open

fix(desktop): canonicalize relay URL in welcome team scoping#5309
BradGroux wants to merge 2 commits into
block:mainfrom
BradGroux:fix/desktop-welcome-team-relay-url-canonicalize

Conversation

@BradGroux

@BradGroux BradGroux commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Changing only the formatting of a community Relay URL could cause the Desktop onboarding path to miss the existing Welcome Team and provision another one. The affected comparisons now use the shared relay URL normalizer, so scheme/host case and trailing-slash variants reuse the existing community-scoped state.

The change also migrates the exact legacy localStorage marker to its canonical key when it is first read. That prevents an existing installation from taking one final duplicate-provisioning path after upgrading. Starter-agent matching coverage now verifies that relay formatting variants still reuse the same deployed instance.

Related issue

Addresses the formatting-only subset of #5109.

This does not claim that localhost, a LAN or Tailscale IP, and a MagicDNS hostname identify the same relay. Those are distinct endpoint strings and cannot be safely collapsed by URL normalization alone. It also does not remove already-stale agent records or change the mobile agent picker, so #5109 should remain open for those broader cases.

Testing

  • Focused onboarding and Welcome guide tests passed: 34 tests, 0 failures.
  • The prior branch verification passed Desktop Biome, file-size, text-size, pubkey-truncation, typecheck, production build, and the full Desktop JavaScript suite.

@BradGroux
BradGroux requested a review from a team as a code owner August 8, 2026 08:55
@BradGroux

Copy link
Copy Markdown
Contributor Author

This is the third recurring review + rebase pass for the open BradGroux PRs on block/buzz.

What this PR does

Canonicalizes the relay URL used as a community scope in the welcome-team ensured-marker storage key. The old code used the raw communityScope string directly, so a relay URL edit (trailing slash, uppercase scheme, mixed case) would orphan the marker and re-trigger welcome-team creation.

The fix imports the shared normalizeRelayUrl helper (already used elsewhere in the codebase) and applies it inside welcomeChannelEnsuredStorageKey. It also removes a local normalizeRelayUrl duplicate in welcomeGuide.ts that only trimmed and stripped trailing slashes, replacing it with the shared canonicalizer. The isAgentScopedToRelay early-return for falsy relayUrl is a correct guard added alongside the refactor.

Correctness

  • The storage key now uses a canonicalized relay URL, so wss://community-a.example/, WSS://Community-A.Example/, and wss://community-a.example// all map to the same key. This prevents orphaned markers.
  • The new test in welcome.test.mjs covers trailing-slash, uppercase-scheme, and double-slash variants.
  • The ensureWelcomeTeam cache key construction is consistent — it normalizes before building the key string.
  • No new dependencies. No unwrap/expect in production paths.

Rebase result

Already based on current main (02f640bc4). No rebase needed — 0 commits behind.

  • Head SHA: 7298de0b715b10a60c661b949cfeb0e4a4ae3f1c (unchanged)
  • Mergeable: ✅ MERGEABLE
  • CI: DCO ✅, Semgrep OSS ✅, zizmor ✅

No code changes were made — this was a review + rebase pass only.

@BradGroux
BradGroux force-pushed the fix/desktop-welcome-team-relay-url-canonicalize branch from 7298de0 to 582fb63 Compare August 9, 2026 10:40
@BradGroux

Copy link
Copy Markdown
Contributor Author

Portfolio review update (2026-08-09)

I reviewed this against current main at 5bf78671f45178f8de02ba18d3d321cbbf19cd1f and the newer discussion on #5109. The formatting bug is still real, but the original Fixes #5109 scope was too broad: URL canonicalization cannot prove that localhost, IP, and MagicDNS endpoints are the same relay, and this PR does not clean stale identities or change the mobile picker.

I rebased the branch, added migration of the exact legacy Welcome marker, strengthened starter reuse coverage across URL formatting variants, and rewrote the PR description to state the narrower scope. Focused onboarding and Welcome guide tests pass (34/34). The current head is 582fb6332f4f3c6b31fd647b3740ddfbefec35e9; #5109 should remain open for the broader identity and cleanup work.

dm-builder and others added 2 commits August 10, 2026 22:01
Editing a community's Relay URL to a different string for the same
relay orphaned the existing Welcome Team (Fizz/Honey/Bumble) and minted
a fresh trio with new keypairs. Two places used bare exact-string
comparison on the relay URL with no canonicalization:

1. welcomeChannelEnsuredStorageKey built a localStorage key from
   communityScope (the raw relay URL) verbatim. A different string for
   the same relay caused a cache miss, treating the community as
   never-provisioned and triggering re-provisioning.

2. isAgentScopedToRelay in welcomeGuide.ts used a local normalizeRelayUrl
   that only trimmed and stripped trailing slashes — it did not lowercase
   the scheme or host. An existing agent stamped with one string was
   invisible to a lookup using a different but logically identical string.

Both now use the shared normalizeRelayUrl from shared/lib/normalizeRelayUrl
which trims, strips trailing slashes, and lowercases — the same normalizer
used by every other relay-scoped local store (sidebar, channel sort,
message snapshots, self-profile).

Closes block#5109.

Co-authored-by: Brad Groux <brad@digitalmeld.com>
Signed-off-by: Brad Groux <brad@digitalmeld.com>
Signed-off-by: dm-builder <f01486f036641ccb52c11bb1e0ff2346ea89a8b4e3b49cd772249948f6fcbae6@digitalmeld.communities.buzz.xyz>
Co-authored-by: Brad Groux <bradgroux@hotmail.com>
Signed-off-by: Brad Groux <bradgroux@hotmail.com>
@BradGroux
BradGroux force-pushed the fix/desktop-welcome-team-relay-url-canonicalize branch from 582fb63 to cc288a9 Compare August 11, 2026 03:01
@BradGroux

Copy link
Copy Markdown
Contributor Author

Portfolio rebase and review update (2026-08-11)

Rebased onto main at 7e6e9c547 (2026-08-10). No conflicts.

Still needed: The relay URL canonicalization bug in welcome team scoping is still present. The onboarding polish in #5310 and the Welcome banner fixes in #5406 and #5330 did not touch welcome.ts or welcomeGuide.ts — the localStorage key still uses the raw communityScope string without normalization, so a formatting-only change to the relay URL (e.g., trailing slash, scheme case) causes a duplicate Welcome Team.

Verification: cargo check not applicable (TS only). The PR adds a legacyWelcomeChannelEnsuredStorageKey for migration and normalizes via the shared normalizeRelayUrl helper from @/shared/lib/normalizeRelayUrl. New tests cover canonicalization and legacy key migration.

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