Skip to content

Commit a38fedb

Browse files
loganjLarry
andauthored
fix(desktop): recognize agents without NIP-OA in Huddles (#8544)
🤖 ## Summary In a Huddle (a voice call in a channel), Buzz Desktop decides which participants are agents. It uses that answer to choose whose text it speaks aloud, which agents can publish voice, and when the last person leaves and the Huddle ends. Desktop currently treats a participant as an agent only when its channel role is `bot`. #8494 changes the relay so that it gives `bot` only to agents with a verified owner attestation (NIP-OA). After that change, agents without an attestation join as ordinary members, and Desktop treats them as people: - their messages are not spoken, - their voice publisher is refused, - the Huddle stays open after the last person leaves while such an agent is still connected. With this PR, Desktop also counts a member as an agent when a trusted person has published a managed-agent record for it. Desktop already publishes such a record for every agent it runs, on every machine. Trusted people are: - **you**, so your own agents count as agents on all of your machines; - **the Huddle's owner**, usually the person who started it, so the agents they added count as agents for everyone who joins. Some agents without an attestation still count as people: an agent added by someone who does not own the Huddle, as seen from any machine other than that person's. The only way to recognize those agents is an owner attestation. This PR does not sign one. ### Details - `huddle/roster.rs` (`fetch_huddle_roster`) is now the only place that decides agent or person for Huddles. A member is an agent if its role is `bot`, or if the current user or a channel `owner` published a kind:30177 managed-agent record whose `d` tag is that member's key. Records from other authors are ignored. Records whose signature does not verify are ignored. - All Huddle checks use the roster: voice-publisher authorization, `get_huddle_agent_pubkeys` (spoken-text gating and the participant list), the periodic roster refresh, adding an agent, cleanup at the end of the Huddle, and the last-person check. - Trusting the owner's records is a compatibility policy for Huddles, not proof of identity. A record creates no owner. It lets the channel owner mark a member as an agent for every Huddle behavior that reads the roster: spoken text, voice publishing, remote transcription and turn-taking (both skip agent audio), cleanup, and the last-person check. Before #8494 the client chose the role, so an owner could already do this by labeling a member `bot`. - If the managed-agent records cannot be read, Desktop does not drop agents that have the `bot` role. Spoken text, voice publishing, adding agents and cleanup keep working for those agents. The Huddle does not end automatically, because an agent without an attestation could be counted as a person. When you join, and on each periodic refresh, Desktop adds the `bot` agents to its stored list and keeps stored agents that are still members. ### Related issue Follow-up to #8494 (the relay stores `bot` only for attested agents). No existing issue found. ### Testing - New helper-level unit tests in `huddle/roster.rs`. They do not run the relay query, the pipeline writers or the leave path. - the `bot` role, the user's own record and the owner's record each mark a member as an agent; - records from other members are ignored; - a record with a forged signature is ignored; - when the record read fails, `bot` agents stay agents, the Huddle cannot end automatically, and the next successful read restores the full roster. - when the record read fails, a joiner with no stored agents still stores the `bot` agents, an agent known only by its record stays stored, and a stored agent that left drops out. - New tests in `huddle/roster_hydration_tests.rs` run the real `post_connect_setup` and hot-start entrypoints against a fake relay whose managed-agent record read fails. The voice-model, audio and pipeline steps are passed in, so the tests replace them. Post-connect stores the `bot` agent before media setup starts; the hot-start refresh also keeps a still-member agent known from an earlier record and drops one that left; the same incomplete roster gives no human count for the last-person check. The tests fail when either entrypoint skips its roster read, and when the roster code accepts only complete rosters. - `cargo test --lib huddle::` (Huddle tests only), `cargo clippy --tests -D warnings` and `cargo fmt --check` pass in `desktop/src-tauri`. - Not yet tested in a live Huddle. --------- Signed-off-by: Logan Johnson <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 834dca2 commit a38fedb

8 files changed

Lines changed: 660 additions & 140 deletions

File tree

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::sync::Arc;
44

5-
use super::{relay_api, tts};
5+
use super::{relay_api, roster, tts};
66
use crate::app_state::AppState;
77

88
pub(super) async fn ensure(
@@ -51,15 +51,13 @@ pub(super) async fn ensure(
5151
Arc::clone(&huddle.local_tts_publishers),
5252
)
5353
};
54-
let has_bot_membership =
55-
relay_api::fetch_channel_members_with_roles(&ephemeral_channel_id, state)
56-
.await?
57-
.into_iter()
58-
.any(|(pubkey, role)| {
59-
pubkey.eq_ignore_ascii_case(speaker_pubkey) && role.as_deref() == Some("bot")
60-
});
61-
if !has_bot_membership {
62-
return Err("agent is not an active bot member of the Huddle".to_string());
54+
let is_huddle_agent = roster::fetch_huddle_roster(&ephemeral_channel_id, state)
55+
.await?
56+
.agents
57+
.iter()
58+
.any(|pubkey| pubkey.eq_ignore_ascii_case(speaker_pubkey));
59+
if !is_huddle_agent {
60+
return Err("agent is not an active agent member of the Huddle".to_string());
6361
}
6462
let publisher = relay_api::connect_tts_audio_publisher(
6563
&ephemeral_channel_id,

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ use uuid::Uuid;
1818
use crate::{
1919
app_state::AppState,
2020
events,
21-
huddle::relay_api::{
22-
fetch_channel_members, fetch_channel_members_with_roles, validate_pubkey_hex,
23-
MAX_HUDDLE_AGENTS,
24-
},
21+
huddle::relay_api::{fetch_channel_members_with_roles, validate_pubkey_hex, MAX_HUDDLE_AGENTS},
22+
huddle::roster::fetch_huddle_roster,
2523
relay::submit_event,
2624
};
2725

@@ -216,8 +214,9 @@ pub(crate) async fn sync_agents_for_active_huddle(
216214

217215
// Membership reads can lag a just-accepted write, so merge the relay view
218216
// with local state instead of allowing a stale snapshot to remove agents.
219-
let fresh_agents = fetch_channel_members(&ephemeral_channel_id, Some("bot"), state)
217+
let fresh_agents = fetch_huddle_roster(&ephemeral_channel_id, state)
220218
.await
219+
.map(|roster| roster.agents)
221220
.unwrap_or_default();
222221
let mut known_agents = HashSet::new();
223222
let mut merged_agents = Vec::new();

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub mod pocket;
4141
pub mod preprocessing;
4242
pub mod reconnect;
4343
pub mod relay_api;
44+
mod roster;
4445
pub mod state;
4546
pub mod stt;
4647
pub mod transcription;
@@ -99,12 +100,10 @@ use agent_tts_routing::{
99100
pub use pipeline::check_pipeline_hotstart;
100101
use pipeline::{
101102
await_inflight_tts_start, maybe_start_stt_pipeline, maybe_start_tts_pipeline,
102-
post_connect_setup, PostConnectOutcome,
103-
};
104-
use relay_api::{
105-
count_human_members, fetch_channel_members, parse_channel_uuid, validate_pubkey_hex,
106-
MAX_HUDDLE_AGENTS,
103+
post_connect_setup, start_huddle_media, PostConnectOutcome,
107104
};
105+
use relay_api::{parse_channel_uuid, validate_pubkey_hex, MAX_HUDDLE_AGENTS};
106+
use roster::fetch_huddle_roster;
108107
use window::close_huddle_window;
109108

110109
fn normalize_huddle_channel_name(candidate: Option<String>, fallback: &str) -> String {
@@ -332,7 +331,14 @@ pub async fn start_huddle(
332331

333332
// 7. Hydrate members, download models, start pipelines (incl. audio relay).
334333
// Audio relay failure is fatal — no point in a huddle without audio.
335-
match post_connect_setup(&state, &ephemeral_channel_id, huddle_generation).await {
334+
match post_connect_setup(
335+
&state,
336+
&ephemeral_channel_id,
337+
huddle_generation,
338+
start_huddle_media,
339+
)
340+
.await
341+
{
336342
Ok(PostConnectOutcome::Ready) => {}
337343
Ok(PostConnectOutcome::Stale) => {
338344
close_huddle_window(&app, &ephemeral_channel_id);
@@ -455,7 +461,14 @@ pub async fn join_huddle(
455461

456462
// Hydrate members, download models, start pipelines (incl. audio relay).
457463
// Audio relay failure is fatal — no point in a huddle without audio.
458-
match post_connect_setup(&state, &ephemeral_channel_id, huddle_generation).await {
464+
match post_connect_setup(
465+
&state,
466+
&ephemeral_channel_id,
467+
huddle_generation,
468+
start_huddle_media,
469+
)
470+
.await
471+
{
459472
Ok(PostConnectOutcome::Ready) => {}
460473
Ok(PostConnectOutcome::Stale) => {
461474
return Err("huddle join was superseded".to_owned());
@@ -566,9 +579,8 @@ async fn remove_huddle_agents(ephemeral_channel_id: &str, state: &AppState) {
566579
return;
567580
};
568581

569-
let agent_pubkeys = match fetch_channel_members(ephemeral_channel_id, Some("bot"), state).await
570-
{
571-
Ok(pubkeys) => pubkeys,
582+
let agent_pubkeys = match fetch_huddle_roster(ephemeral_channel_id, state).await {
583+
Ok(roster) => roster.agents,
572584
Err(e) => {
573585
eprintln!("buzz-desktop: fetch huddle agents for cleanup failed: {e}");
574586
return;
@@ -614,9 +626,12 @@ pub async fn leave_huddle(app: tauri::AppHandle, state: State<'_, AppState>) ->
614626
// We check BEFORE removing self — the relay counts us as a member until
615627
// we leave. So "1 human remaining" means WE are the last one.
616628
if !parent_channel_id.is_empty() && !ephemeral_channel_id.is_empty() {
617-
let humans_remaining = count_human_members(&ephemeral_channel_id, &state)
629+
let humans_remaining = fetch_huddle_roster(&ephemeral_channel_id, &state)
618630
.await
619-
// On fetch failure, assume 2 humans remain (safe default).
631+
.ok()
632+
.and_then(|roster| roster.humans_remaining())
633+
// On fetch failure or an incomplete roster, assume 2 humans remain
634+
// (safe default).
620635
// unwrap_or(1) would mean "I'm the last human" → triggers auto-archive,
621636
// ending the huddle for everyone on a transient REST failure. Using 2
622637
// means we skip the auto-end path and just remove ourselves — the huddle
@@ -729,7 +744,9 @@ pub async fn get_huddle_agent_pubkeys(state: State<'_, AppState>) -> Result<Vec<
729744
hs.ephemeral_channel_id.clone()
730745
};
731746
match eph_id {
732-
Some(id) => fetch_channel_members(&id, Some("bot"), &state).await,
747+
Some(id) => fetch_huddle_roster(&id, &state)
748+
.await
749+
.map(|roster| roster.agents),
733750
None => Ok(Vec::new()),
734751
}
735752
}

0 commit comments

Comments
 (0)