Discord: several radio streams per voice channel; adding never overwrites (#213)

Owner-reported on live: adding a radio channel for a server + voice channel
that already had one (different label, system, even bot) overwrote the
existing stream and made its bot leave, because stream_id was guild:channel.

- New streams get guild:channel:<12 hex> ids (leases.new_stream_id); old
  guild:channel docs keep working for read/stop/remove/node reports. Route
  validators accept both (leases.STREAM_ID_PATTERN).
- start_stream: no stream_id = ADD. Same system already on in that channel
  is idempotent (already_on, label/mode untouched); a stopped one of that
  system is restarted; anything else is a new doc. stream_id = explicit
  restart/edit (admin Start button, reconciler), incl. moving to another bot.
- preferred_token_id is strict: bot already in this server -> 409
  preferred_busy naming the stream; on another node -> preferred_other_node;
  unusable -> preferred_unavailable. No silent swap. pool_exhausted now says
  one-bot-per-server and to add + invite another bot.
- One-token-per-guild was already enforced inside the lease transaction;
  now covered by race tests. Per-guild asyncio lock serialises the
  already-on / server-cap check with the create (guild half of #223).
- Stop by stream_id (POST /discord/guilds/{id}/stop {stream_id}); admin UI
  Stop/Start/Remove act on the row's stream; node picker lists every stream
  in a channel and adds beside other systems.
- Bot: /leave stream: (autocomplete) stops one; /leave channel: with several
  streams asks which unless all:True; bare /leave still stops the server.
  /status and /join name each stream's bot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Logan Cusano
2026-10-05 00:30:40 -04:00
co-authored by Claude Opus 5.5
parent 16a609e35b
commit 8af410aede
15 changed files with 913 additions and 113 deletions
+7 -2
View File
@@ -76,6 +76,9 @@ export const c2api = {
method: "PUT",
body: JSON.stringify(body),
}),
/** Without stream_id: ADD a stream to the voice channel (a channel can carry
* several, each its own bot + system; never replaces one). With stream_id:
* restart / edit that stream. */
startDiscordStream: (body: {
guild_id: string;
channel_id: string;
@@ -83,6 +86,7 @@ export const c2api = {
mode: "persistent" | "adhoc";
channel_name?: string;
preferred_token_id?: string;
stream_id?: string;
}) => request<DiscordStream>("/discord/streams", { method: "POST", body: JSON.stringify(body) }),
/** Permanently remove a radio channel (stopped through desired state first). Admin only. */
deleteDiscordStream: (streamId: string) =>
@@ -99,10 +103,11 @@ export const c2api = {
}>(`/discord/guilds/${encodeURIComponent(guildId)}?leave_radio_bots=${leaveRadioBots ? "true" : "false"}`, {
method: "DELETE",
}),
stopDiscordStream: (guildId: string, channelId: string) =>
/** Stop ONE stream (its voice channel may carry others, which keep playing). */
stopDiscordStream: (guildId: string, streamId: string) =>
request<{ stopped: string[] }>(`/discord/guilds/${encodeURIComponent(guildId)}/stop`, {
method: "POST",
body: JSON.stringify({ channel_id: channelId, reason: "stopped from web admin" }),
body: JSON.stringify({ stream_id: streamId, reason: "stopped from web admin" }),
}),
// Node approval
+2
View File
@@ -67,6 +67,8 @@ export interface DiscordStream {
stop_reason?: string | null;
updated_at?: string | null;
created_at?: string | null;
/** POST /discord/streams: this system was already on in that channel — nothing was replaced. */
already_on?: boolean;
}
export interface DiscordGuild {
+6
View File
@@ -18,7 +18,10 @@ export interface DiscordStreamView {
channel_id: string;
guild_name: string | null;
channel_name: string | null;
system_id?: string | null;
system_name: string | null;
/** The radio bot carrying it — tells apart several streams in one voice channel. */
token_name?: string | null;
mode: "persistent" | "adhoc" | null;
node_id: string | null;
node_name: string | null;
@@ -35,7 +38,10 @@ export interface DiscordVoiceChannel {
channel_id: string;
name: string;
category: string | null;
/** This node's system's stream in the channel, if any — what a pick restarts or moves. */
stream: DiscordStreamView | null;
/** Every live stream in the channel (several systems can share it, each its own bot). */
streams?: DiscordStreamView[];
}
export interface DiscordGuildOption {