@@ -3072,6 +3072,10 @@ async fn run_harness(
30723072 .await
30733073 .map_err(|e| anyhow::anyhow!("channel discovery error: {e}"))?;
30743074
3075+ if let Some(binding) = &config.bound_session {
3076+ binding.validate_channel_metadata(channel_info_map.get(&binding.channel_id()))?;
3077+ }
3078+
30753079 tracing::info!("discovered {} channel(s)", channel_info_map.len());
30763080 let channel_ids: Vec<Uuid> = channel_info_map.keys().copied().collect();
30773081
@@ -3532,7 +3536,7 @@ async fn run_harness(
35323536 observer.as_ref(),
35333537 owner_hex,
35343538 relay.event_publisher(),
3535- config.bound_session.as_ref().map(|binding| binding.channel_id),
3539+ config.bound_session.as_ref().map(|binding| binding.channel_id() ),
35363540 );
35373541 } else {
35383542 tracing::warn!("observer control frame received but no owner resolved — dropping");
@@ -4579,11 +4583,12 @@ fn bound_session_admits(
45794583 let Some(binding) = binding else {
45804584 return true;
45814585 };
4582- if buzz_event.channel_id != binding.channel_id {
4586+ if buzz_event.channel_id != binding.channel_id() {
45834587 return false;
45844588 }
45854589 match routed_scope {
45864590 Some(scope) => binding.accepts(scope),
4591+ None if matches!(binding, config::BoundSession::DirectMessage { .. }) => true,
45874592 None => {
45884593 u32::from(buzz_event.event.kind.as_u16()) != KIND_STREAM_MESSAGE
45894594 || binding.accepts(&scope::SessionScope::derive(
@@ -7273,12 +7278,40 @@ mod bound_session_admission_tests {
72737278 }
72747279
72757280 fn binding() -> config::BoundSession {
7276- config::BoundSession {
7281+ config::BoundSession::Thread {
72777282 channel_id: Uuid::new_v4(),
72787283 thread_root: "a".repeat(64),
72797284 }
72807285 }
72817286
7287+ #[test]
7288+ fn a_bound_dm_admits_conversation_events_but_no_channel_thread() {
7289+ let channel = Uuid::new_v4();
7290+ let binding = config::BoundSession::DirectMessage {
7291+ dm_channel_id: channel,
7292+ };
7293+ for root in [None, Some("a".repeat(64))] {
7294+ let event = buzz_event(channel, 9, "plain owner DM", root.as_deref());
7295+ assert!(bound_session_admits(Some(&binding), &event, None));
7296+ let dm = scope::SessionScope::derive(
7297+ scope::SessionPolicy::Thread,
7298+ channel,
7299+ true,
7300+ &event.event,
7301+ );
7302+ assert!(bound_session_admits(Some(&binding), &event, Some(&dm)));
7303+ let thread = scope::SessionScope::derive(
7304+ scope::SessionPolicy::Thread,
7305+ channel,
7306+ false,
7307+ &event.event,
7308+ );
7309+ assert!(!bound_session_admits(Some(&binding), &event, Some(&thread)));
7310+ }
7311+ let foreign = buzz_event(Uuid::new_v4(), 9, "another DM", None);
7312+ assert!(!bound_session_admits(Some(&binding), &foreign, None));
7313+ }
7314+
72827315 /// The pre-check runs before `!shutdown` / `!cancel`, so an owner command
72837316 /// in a foreign thread or channel never reaches the control handlers.
72847317 #[test]
@@ -7287,7 +7320,7 @@ mod bound_session_admission_tests {
72877320 let foreign_root = "b".repeat(64);
72887321 for command in ["!shutdown", "!cancel"] {
72897322 let foreign_thread = buzz_event(
7290- binding.channel_id,
7323+ binding.channel_id() ,
72917324 KIND_STREAM_MESSAGE as u16,
72927325 command,
72937326 Some(&foreign_root),
@@ -7304,7 +7337,7 @@ mod bound_session_admission_tests {
73047337 Uuid::new_v4(),
73057338 KIND_STREAM_MESSAGE as u16,
73067339 command,
7307- Some(& binding.thread_root),
7340+ binding.thread_root( ),
73087341 );
73097342 assert!(!bound_session_admits(
73107343 Some(&binding),
@@ -7313,10 +7346,10 @@ mod bound_session_admission_tests {
73137346 ));
73147347
73157348 let in_thread = buzz_event(
7316- binding.channel_id,
7349+ binding.channel_id() ,
73177350 KIND_STREAM_MESSAGE as u16,
73187351 command,
7319- Some(& binding.thread_root),
7352+ binding.thread_root( ),
73207353 );
73217354 assert!(bound_session_admits(Some(&binding), &in_thread, None));
73227355 }
@@ -7326,14 +7359,14 @@ mod bound_session_admission_tests {
73267359 fn only_in_thread_prompts_are_admitted() {
73277360 let binding = binding();
73287361 let in_scope = scope::SessionScope::Thread {
7329- channel_id: binding.channel_id,
7330- root_event_id: binding.thread_root.clone (),
7362+ channel_id: binding.channel_id() ,
7363+ root_event_id: binding.thread_root().unwrap().to_owned (),
73317364 };
73327365 let reply = buzz_event(
7333- binding.channel_id,
7366+ binding.channel_id() ,
73347367 KIND_STREAM_MESSAGE as u16,
73357368 "@agent continue",
7336- Some(& binding.thread_root),
7369+ binding.thread_root( ),
73377370 );
73387371 assert!(bound_session_admits(Some(&binding), &reply, None));
73397372 assert!(bound_session_admits(
@@ -7347,11 +7380,11 @@ mod bound_session_admission_tests {
73477380 foreign_channel_id,
73487381 KIND_STREAM_MESSAGE as u16,
73497382 "@agent start",
7350- Some(& binding.thread_root),
7383+ binding.thread_root( ),
73517384 );
73527385 let foreign_scope = scope::SessionScope::Thread {
73537386 channel_id: foreign_channel_id,
7354- root_event_id: binding.thread_root.clone (),
7387+ root_event_id: binding.thread_root().unwrap().to_owned (),
73557388 };
73567389 assert!(!bound_session_admits(
73577390 Some(&binding),
@@ -7367,10 +7400,10 @@ mod bound_session_admission_tests {
73677400 // An edit carries its thread on the original, so the pre-check can
73687401 // only check its channel; the routed scope decides admission.
73697402 let edit_kind = buzz_core::kind::KIND_STREAM_MESSAGE_EDIT as u16;
7370- let edit = buzz_event(binding.channel_id, edit_kind, "@agent edited", None);
7403+ let edit = buzz_event(binding.channel_id() , edit_kind, "@agent edited", None);
73717404 assert!(bound_session_admits(Some(&binding), &edit, None));
73727405 let edited_foreign_thread = scope::SessionScope::Thread {
7373- channel_id: binding.channel_id,
7406+ channel_id: binding.channel_id() ,
73747407 root_event_id: "c".repeat(64),
73757408 };
73767409 assert!(!bound_session_admits(
0 commit comments