fix(desktop): skip a starter channel the relay will never create (#8911)

## Problem

On first run, the desktop app creates the `general` and
`welcome-everyone` starter channels at fixed ids when it can't find a
live one. Some refusals of that create are permanent. Any refusal
aborted setup **before it joined the new member to the starters that do
exist**:

| Starter state in the community | Relay reply to the create | Before |
|---|---|---|
| Another listed channel holds the name, archived ones included (with
#8782) | 400 `invalid: an open channel named "…" already exists` | setup
fails, not joined to `general` |
| An archived channel holds the fixed id | 400 `invalid: channel is
archived` (the relay checks this before duplicates) | setup fails |
| The channel at the fixed id was renamed or retyped | `duplicate` |
waits, then `starter channels created but metadata not yet available` |
| The channel at the fixed id was deleted | `duplicate`, and no metadata
is ever served | same |

Onboarding itself continues, because public starter failures are already
caught in `initializeStarterChannels`. The new member just never gets
joined to the other starter. With #8782 this happens to every new
desktop user in a community whose `welcome-everyone` or `general` is
archived.

## Fix

`ensure_starter_channels_inner` now skips a starter it can never create
or use, clears its pending-owner mark, and still joins the rest. Before
skipping after a permanent refusal, it reads the open directory again,
from the writer rather than a replica, once for all refused starters: a
live starter created after the first read is joined instead of skipped.
Any other refusal still fails setup. On the TS side,
`ensureStarterChannels` reports a skipped starter as `null` instead of
throwing. No caller reads those fields.

## Testing

- New tests run `ensure_starter_channels_inner` against a stub relay
that sends the relay's real reply shapes, one per row above, plus one
checking that other refusals still fail, and one where a live
`welcome-everyone` is listed only by writer-pinned reads (a lagging
replica) and gets joined. Each test fails when its guard is removed.
- Ran the real starter-setup code as a new user against a local relay
built from #8782, one community per row:
  - On `main`, rows 1, 2 and 4 fail.
- On this branch, all four join `general`, and each community still has
exactly one `welcome-everyone`.
  - A rerun is a no-op.
- `cargo test` (desktop Tauri, full), clippy, fmt, desktop `pnpm test`,
`tsc`, and biome all pass.

Related: #8782 (relay refuses taken names), #8807 (the same fix for
mobile). The archived-id case returns `channel is archived`, not
`duplicate`, so mobile needs to handle that reply too.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Salman Mohammed <smohammed@squareup.com>
Co-authored-by: opus <f038cc09b32a776e7d95b65c267e9d851777ee2b6cdbd46a48edba01b1d10ebd@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Salman Mohammed
2026-11-02 12:59:28 -05:00
committed by GitHub
parent 3ae2b6a377
commit f99807a79a
7 changed files with 409 additions and 21 deletions

View File

@@ -332,6 +332,25 @@ test("ensureStarterChannels resumes when one starter channel is missing", async
assert.equal(ensureCalls, 1);
});
test("ensureStarterChannels keeps the starters setup did not skip", async () => {
// welcome-everyone's name belongs to an archived channel, so the native
// command skips it and returns only general.
const general = makeChannel({
id: "general-channel",
name: "general",
visibility: "open",
});
const result = await ensureStarterChannels({
getChannels: async () => [],
ensureStarterChannels: async () => [general],
});
assert.equal(result.generalChannel, general);
assert.equal(result.welcomeChannel, null);
assert.deepEqual(result.channels, [general]);
});
test("isWelcomeExperienceChannel matches legacy Welcome and starter welcome-everyone", () => {
assert.equal(isWelcomeExperienceChannel(makeChannel()), true);
assert.equal(

View File

@@ -41,8 +41,12 @@ type StarterChannelsClient = {
export type StarterChannelsResult = {
channels: Channel[];
generalChannel: Channel;
welcomeChannel: Channel;
/**
* Null when setup skipped this starter because its name or id belongs to a
* channel that cannot serve as it, such as an archived one.
*/
generalChannel: Channel | null;
welcomeChannel: Channel | null;
};
type WelcomeChannelOptions = {
@@ -269,15 +273,18 @@ export async function ensureStarterChannels(
};
}
// The native command fails unless every starter it did not skip is usable.
const ensuredChannels = await client.ensureStarterChannels();
const ensuredStarters = findStarterChannels(ensuredChannels);
if (!ensuredStarters) {
throw new Error("Starter channels were not available after setup");
}
return {
channels: ensuredChannels,
...ensuredStarters,
generalChannel: findStarterChannel(
ensuredChannels,
STARTER_GENERAL_CHANNEL_NAME,
),
welcomeChannel: findStarterChannel(
ensuredChannels,
STARTER_WELCOME_CHANNEL_NAME,
),
};
}