Skip to content

Commit fb4a801

Browse files
authored
Improve huddle audio failure handling (#2578)
## Summary - Preserve plain-string errors returned by Tauri and show an actionable message when huddle audio is unavailable in the relay deployment. - Use one error formatter across channel, timeline, wave, and profile huddle actions while preserving other relay and device errors. - Complete the huddle lifecycle when audio setup fails after publishing a start event, preventing peers and reloaded clients from reconstructing a phantom active huddle. - Cover unavailable-audio formatting and START → rollback-END reconstruction with regression tests. ## Behavior The Tauri huddle commands reject with a plain string. Several desktop toast call sites only preserved JavaScript `Error` objects, so the relay message was discarded and replaced with “Failed to join huddle.” The desktop now recognizes `huddle_audio_unavailable` and the current relay message, then shows: > Huddle audio isn’t available on this server. Ask an administrator to turn it on. Other relay and device messages remain intact, including microphone errors. `start_huddle` also publishes `KIND_HUDDLE_STARTED` before audio setup. If setup fails, rollback now publishes `KIND_HUDDLE_ENDED` through the normal end-and-archive path before resetting local state. This makes the failed start observable to lifecycle reconstruction and prevents stale join affordances. ## Checks - `cd desktop && pnpm test` — 3,405 passed - `cd desktop/src-tauri && cargo test` — 1,560 passed, 13 ignored; 3 diagnostic tests passed - `cd desktop && pnpm exec playwright test tests/e2e/channels.spec.ts --project=smoke --grep 'huddle rollback end event'` — passed - `just desktop-tauri-check` - `cd desktop && pnpm typecheck` - `cd desktop && pnpm check` - Pre-commit and pre-push hooks
1 parent cfdea81 commit fb4a801

10 files changed

Lines changed: 158 additions & 20 deletions

File tree

‎desktop/src-tauri/src/huddle/mod.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,9 @@ pub async fn start_huddle(
289289
// Audio relay failure is fatal — no point in a huddle without audio.
290290
if let Err(e) = post_connect_setup(&state, &ephemeral_channel_id).await {
291291
// Rollback: audio relay failed after state was committed.
292-
// Archive the ephemeral channel and reset state.
293-
if let Ok(archive_builder) = events::build_archive(ephemeral_uuid) {
294-
if let Err(ae) = submit_event(archive_builder, &state).await {
295-
eprintln!(
296-
"buzz-desktop: rollback archive of {ephemeral_channel_id} failed: {ae}"
297-
);
298-
}
299-
}
292+
// Publish the terminal lifecycle event before archiving so
293+
// other clients do not reconstruct a phantom active huddle.
294+
emit_end_and_archive(&parent_channel_id, &ephemeral_channel_id, &state).await;
300295
if let Ok(mut hs) = state.huddle_state.lock() {
301296
hs.reset_preserving_generation();
302297
}

‎desktop/src/features/channels/ui/ChannelMembersBar.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { EllipsisVertical, Settings2, Users } from "lucide-react";
22
import * as React from "react";
3+
import { toast } from "sonner";
34
import { useQueryClient } from "@tanstack/react-query";
45
import { useHuddle } from "@/features/huddle";
56
import { HuddleIndicator } from "@/features/huddle/components/HuddleIndicator";
7+
import { formatHuddleActionError } from "@/features/huddle/lib/huddleError";
68
import { buildHuddleChannelName } from "@/features/huddle/lib/huddleChannelName";
79
import {
810
useAvailableAcpRuntimes,
@@ -127,6 +129,7 @@ export function ChannelMembersBar({
127129
void queryClient.invalidateQueries({ queryKey: ["channels"] });
128130
} catch (e) {
129131
console.error("Failed to start huddle:", e);
132+
toast.error(formatHuddleActionError(e, "start"));
130133
}
131134
}}
132135
renderMode={variant === "compact" ? "menu-item" : "button"}

‎desktop/src/features/huddle/HuddleContext.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as React from "react";
44

55
import { setupAudioWorklet, type AudioWorkletHandle } from "./lib/audioWorklet";
66
import { useAudioDevices } from "./lib/useAudioDevices";
7+
import { formatHuddleActionError } from "./lib/huddleError";
78
import { useTtsSubscription } from "./lib/useTtsSubscription";
89

910
/**
@@ -457,7 +458,7 @@ export function HuddleProvider({ children }: { children: React.ReactNode }) {
457458
const w = workletRef.current;
458459
workletRef.current = null;
459460
await cleanupFailedStart(w, true);
460-
setHuddleError(msg);
461+
setHuddleError(formatHuddleActionError(e, "start"));
461462
console.error("Failed to start huddle:", e);
462463
throw e;
463464
} finally {
@@ -503,7 +504,7 @@ export function HuddleProvider({ children }: { children: React.ReactNode }) {
503504
const w = workletRef.current;
504505
workletRef.current = null;
505506
await cleanupFailedStart(w, false);
506-
setHuddleError(msg);
507+
setHuddleError(formatHuddleActionError(e, "join"));
507508
console.error("Failed to join huddle:", e);
508509
throw e;
509510
} finally {

‎desktop/src/features/huddle/components/HuddleAttachment.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from "@/shared/ui/attachment";
2525
import { useHuddle } from "../HuddleContext";
2626
import { isHuddleStartStale } from "../lib/huddleCardState";
27+
import { formatHuddleActionError } from "../lib/huddleError";
2728

2829
type HuddleAttachmentProps = {
2930
channelId: string | null;
@@ -221,9 +222,7 @@ export function HuddleAttachment({
221222
await joinHuddle(channelId, ephemeralChannelId);
222223
void queryClient.invalidateQueries({ queryKey: ["channels"] });
223224
} catch (error) {
224-
const message =
225-
error instanceof Error ? error.message : "Failed to join huddle";
226-
toast.error(message);
225+
toast.error(formatHuddleActionError(error, "join"));
227226
} finally {
228227
setIsJoining(false);
229228
}

‎desktop/src/features/huddle/components/HuddleIndicator.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { listen } from "@tauri-apps/api/event";
22
import { Headphones } from "lucide-react";
33
import * as React from "react";
4+
import { toast } from "sonner";
45
import { useQueryClient } from "@tanstack/react-query";
56

67
import { relayClient } from "@/shared/api/relayClient";
@@ -10,6 +11,7 @@ import { Button } from "@/shared/ui/button";
1011
import { DropdownMenuItem } from "@/shared/ui/dropdown-menu";
1112
import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip";
1213
import { useHuddle } from "../HuddleContext";
14+
import { formatHuddleActionError } from "../lib/huddleError";
1315

1416
/** Huddle lifecycle event kinds */
1517
const KIND_HUDDLE_STARTED = 48100;
@@ -263,6 +265,7 @@ export function HuddleIndicator({
263265
void queryClient.invalidateQueries({ queryKey: ["channels"] });
264266
} catch (e) {
265267
console.error("Failed to join huddle:", e);
268+
toast.error(formatHuddleActionError(e, "join"));
266269
} finally {
267270
setIsJoining(false);
268271
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { formatHuddleActionError } from "./huddleError.ts";
5+
6+
const AUDIO_UNAVAILABLE_MESSAGE =
7+
"Huddle audio isn’t available on this server. Ask an administrator to turn it on.";
8+
9+
test("maps the relay deployment rejection to actionable copy", () => {
10+
assert.equal(
11+
formatHuddleActionError(
12+
"audio relay auth error: huddle audio unavailable in this deployment",
13+
"join",
14+
),
15+
AUDIO_UNAVAILABLE_MESSAGE,
16+
);
17+
});
18+
19+
test("recognizes the relay error code when present", () => {
20+
assert.equal(
21+
formatHuddleActionError("huddle_audio_unavailable", "start"),
22+
AUDIO_UNAVAILABLE_MESSAGE,
23+
);
24+
});
25+
26+
test("preserves other string and Error messages", () => {
27+
assert.equal(
28+
formatHuddleActionError("Microphone unavailable", "join"),
29+
"Microphone unavailable",
30+
);
31+
assert.equal(
32+
formatHuddleActionError(new Error("Connection timed out"), "start"),
33+
"Connection timed out",
34+
);
35+
});
36+
37+
test("uses action-specific fallback copy for unknown errors", () => {
38+
assert.equal(
39+
formatHuddleActionError({ reason: "unknown" }, "join"),
40+
"Couldn’t join the huddle.",
41+
);
42+
assert.equal(
43+
formatHuddleActionError(null, "start"),
44+
"Couldn’t start the huddle.",
45+
);
46+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export type HuddleAction = "join" | "start";
2+
3+
const HUDDLE_AUDIO_UNAVAILABLE_MESSAGE =
4+
"Huddle audio isn’t available on this server. Ask an administrator to turn it on.";
5+
6+
function rawErrorMessage(error: unknown): string | null {
7+
if (error instanceof Error) {
8+
return error.message;
9+
}
10+
if (typeof error === "string") {
11+
return error;
12+
}
13+
return null;
14+
}
15+
16+
export function formatHuddleActionError(
17+
error: unknown,
18+
action: HuddleAction,
19+
): string {
20+
const message = rawErrorMessage(error)?.trim();
21+
const normalized = message?.toLowerCase();
22+
23+
if (
24+
normalized?.includes("huddle_audio_unavailable") ||
25+
normalized?.includes("huddle audio unavailable in this deployment")
26+
) {
27+
return HUDDLE_AUDIO_UNAVAILABLE_MESSAGE;
28+
}
29+
30+
if (message) {
31+
return message;
32+
}
33+
34+
return action === "join"
35+
? "Couldn’t join the huddle."
36+
: "Couldn’t start the huddle.";
37+
}

‎desktop/src/features/messages/ui/WaveMessageAttachment.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { toast } from "sonner";
44

55
import { channelsQueryKey } from "@/features/channels/hooks";
66
import { useHuddle } from "@/features/huddle";
7+
import { formatHuddleActionError } from "@/features/huddle/lib/huddleError";
78
import {
89
Attachment,
910
AttachmentAction,
@@ -45,9 +46,7 @@ export function WaveMessageAttachment({
4546
await startHuddle(channelId, [...huddleMemberPubkeys]);
4647
await queryClient.invalidateQueries({ queryKey: channelsQueryKey });
4748
} catch (error) {
48-
toast.error(
49-
error instanceof Error ? error.message : "Failed to start huddle.",
50-
);
49+
toast.error(formatHuddleActionError(error, "start"));
5150
}
5251
},
5352
[

‎desktop/src/features/profile/ui/UserProfilePopover.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { toast } from "sonner";
55

66
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
77
import { useHuddle } from "@/features/huddle";
8+
import { formatHuddleActionError } from "@/features/huddle/lib/huddleError";
89
import {
910
channelsQueryKey,
1011
useChannelsQuery,
@@ -374,9 +375,7 @@ export function UserProfilePopover({
374375
setOpen(false);
375376
}
376377
} catch (error) {
377-
toast.error(
378-
error instanceof Error ? error.message : "Failed to start huddle.",
379-
);
378+
toast.error(formatHuddleActionError(error, "start"));
380379
} finally {
381380
if (isMountedRef.current) {
382381
setPendingAction(null);

‎desktop/tests/e2e/channels.spec.ts‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { KIND_TYPING_INDICATOR } from "../../src/shared/constants/kinds";
3+
import {
4+
KIND_HUDDLE_ENDED,
5+
KIND_HUDDLE_STARTED,
6+
KIND_TYPING_INDICATOR,
7+
} from "../../src/shared/constants/kinds";
48
import {
59
TEST_IDENTITIES,
610
installMockBridge,
@@ -2879,6 +2883,58 @@ test("channel header omits the add agent action", async ({ page }) => {
28792883
await expect(page.getByTestId("channel-management-trigger")).toBeVisible();
28802884
});
28812885

2886+
test("huddle rollback end event clears the active header action", async ({
2887+
page,
2888+
}) => {
2889+
await page.goto("/");
2890+
await page.getByTestId("channel-random").click();
2891+
await expect(page.getByTestId("chat-title")).toHaveText("random");
2892+
await waitForMockLiveSubscription(page, "random", KIND_HUDDLE_STARTED);
2893+
2894+
const ephemeralChannelId = "10000000-0000-4000-8000-000000000001";
2895+
const createdAt = Math.floor(Date.now() / 1000);
2896+
2897+
await page.evaluate(
2898+
({ createdAt, ephemeralChannelId, kind }) => {
2899+
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
2900+
channelName: "random",
2901+
content: JSON.stringify({
2902+
ephemeral_channel_id: ephemeralChannelId,
2903+
}),
2904+
createdAt,
2905+
id: "1".repeat(64),
2906+
kind,
2907+
});
2908+
},
2909+
{ createdAt, ephemeralChannelId, kind: KIND_HUDDLE_STARTED },
2910+
);
2911+
2912+
await expect(
2913+
page.getByRole("button", {
2914+
name: "Join active huddle (1 participant)",
2915+
}),
2916+
).toBeVisible();
2917+
2918+
await page.evaluate(
2919+
({ createdAt, ephemeralChannelId, kind }) => {
2920+
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
2921+
channelName: "random",
2922+
content: JSON.stringify({
2923+
ephemeral_channel_id: ephemeralChannelId,
2924+
}),
2925+
createdAt,
2926+
id: "2".repeat(64),
2927+
kind,
2928+
});
2929+
},
2930+
{ createdAt, ephemeralChannelId, kind: KIND_HUDDLE_ENDED },
2931+
);
2932+
2933+
await expect(
2934+
page.getByTestId("channel-start-huddle-trigger"),
2935+
).toHaveAttribute("aria-label", "Start huddle");
2936+
});
2937+
28822938
test("channel header actions show tooltips", async ({ page }) => {
28832939
await page.goto("/");
28842940
await page.getByTestId("channel-random").click();

0 commit comments

Comments
 (0)