@@ -649,12 +649,8 @@ impl QueuedNormalListenerEvent {
649649 } ) ;
650650 }
651651
652- /// `prompt_is_dm` must match how the running turn's prompt classified the
653- /// channel (see [`resolved_dm_channel`]): the DM steer rule is only right
654- /// for a turn whose `<context>` was rendered as a DM.
655652 fn steer_or_interrupt (
656653 self ,
657- prompt_is_dm : bool ,
658654 handling : MultipleEventHandling ,
659655 owner : Option < & str > ,
660656 pool : & mut AgentPool ,
@@ -671,12 +667,10 @@ impl QueuedNormalListenerEvent {
671667 // carry a message that replies in the same place. A channel-policy or
672668 // DM session spans several destinations; a message for another one
673669 // takes the cancel+merge path, whose re-prompt carries its own
674- // `<context>`.
675- let same_reply_route = queue
676- . in_flight_reply_route ( & self . scope )
677- . is_some_and ( |running| {
678- running. accepts_steer ( & self . steer_event . reply_route ( ) , prompt_is_dm)
679- } ) ;
670+ // `<context>`. The DM rule applies only when the running turn's
671+ // prompt itself was rendered as a DM.
672+ let same_reply_route =
673+ queue. in_flight_accepts_steer ( & self . scope , & self . steer_event . reply_route ( ) ) ;
680674 let native_attempted = matches ! ( signal, ControlSignal :: Steer )
681675 && same_reply_route
682676 && try_native_steer (
@@ -832,33 +826,8 @@ pub(crate) async fn is_dm_channel(
832826 channel_id : Uuid ,
833827 channel_info : & pool:: ChannelInfoResolver ,
834828) -> bool {
835- fail_closed_dm (
836- channel_id,
837- resolved_dm_channel ( channel_id, channel_info) . await ,
838- )
839- }
840-
841- /// Whether `channel_id` is a DM according to its metadata, or `None` when the
842- /// metadata cannot be resolved.
843- ///
844- /// Prompt formatting treats unresolved metadata as a non-DM channel, while
845- /// the author gate fails closed as a DM ([`fail_closed_dm`]). Decisions that
846- /// must agree with the rendered prompt, such as native steering, use this
847- /// value with the prompt's fallback.
848- pub ( crate ) async fn resolved_dm_channel (
849- channel_id : Uuid ,
850- channel_info : & pool:: ChannelInfoResolver ,
851- ) -> Option < bool > {
852- channel_info
853- . resolve_channel_metadata ( channel_id)
854- . await
855- . map ( |info| info. channel_type == "dm" )
856- }
857-
858- /// The author gate's DM classification: unresolved metadata is a DM.
859- fn fail_closed_dm ( channel_id : Uuid , resolved : Option < bool > ) -> bool {
860- match resolved {
861- Some ( is_dm) => is_dm,
829+ match channel_info. resolve_channel_metadata ( channel_id) . await {
830+ Some ( info) => info. channel_type == "dm" ,
862831 None => {
863832 tracing:: warn!(
864833 channel_id = %channel_id,
@@ -3554,12 +3523,13 @@ async fn run_harness(
35543523 // channel-keyed routing. Telemetry only for now —
35553524 // queue/pool partitioning by scope lands in a
35563525 // follow-up (see ticket outline steps 2–4).
3557- let channel_id = ingress. buzz_event. channel_id;
3558- let resolved_dm =
3559- resolved_dm_channel( channel_id, & ctx. channel_info) . await ;
35603526 let session_scope = ingress. session_scope(
35613527 config. session_policy,
3562- fail_closed_dm( channel_id, resolved_dm) ,
3528+ is_dm_channel(
3529+ ingress. buzz_event. channel_id,
3530+ & ctx. channel_info,
3531+ )
3532+ . await ,
35633533 ) ;
35643534 tracing:: debug!(
35653535 channel_id = %session_scope. channel_id( ) ,
@@ -3581,8 +3551,6 @@ async fn run_harness(
35813551 // event data through the optional steer/interrupt
35823552 // decision.
35833553 queued. steer_or_interrupt(
3584- // The prompt's fallback: unresolved is not a DM.
3585- resolved_dm. unwrap_or( false ) ,
35863554 config. multiple_event_handling,
35873555 owner_cache. get( ) ,
35883556 & mut pool,
@@ -4908,6 +4876,9 @@ fn dispatch_pending(
49084876 . state
49094877 . set_scope_owner_generation ( scope. clone ( ) , owner_generation) ;
49104878
4879+ // The prompt task records how it classified the channel, for the
4880+ // native-steer guard (`EventQueue::in_flight_accepts_steer`).
4881+ let prompt_dm = queue. in_flight_prompt_dm ( & scope) . unwrap_or_default ( ) ;
49114882 let abort_handle = pool. join_set . spawn ( async move {
49124883 pool:: run_prompt_task (
49134884 agent,
@@ -4917,6 +4888,7 @@ fn dispatch_pending(
49174888 result_tx,
49184889 Some ( control_rx) ,
49194890 task_turn_id,
4891+ prompt_dm,
49204892 )
49214893 . await ;
49224894 } ) ;
@@ -5638,6 +5610,7 @@ fn dispatch_heartbeat(
56385610 result_tx,
56395611 None ,
56405612 task_turn_id,
5613+ Default :: default ( ) ,
56415614 )
56425615 . await ;
56435616 } ) ;
@@ -10069,14 +10042,17 @@ mod edit_native_steer_tests {
1006910042 target_event_id : original. id . to_hex ( ) ,
1007010043 target_thread_tags : queue:: parse_thread_tags ( original) ,
1007110044 } ;
10072- steer_into_running_turn ( false , running_event, edit, Some ( resolved) )
10045+ steer_into_running_turn ( false , Some ( false ) , running_event, edit, Some ( resolved) )
1007310046 }
1007410047
1007510048 /// Drive `incoming` through the listener's steer decision while a turn
1007610049 /// for `running_event` is in flight in the same conversation session
10077- /// (the channel policy, or any DM).
10050+ /// (the channel policy, or any DM). `prompt_is_dm` is how the running
10051+ /// turn's prompt classified the channel; `None` means the prompt has not
10052+ /// been formatted yet.
1007810053 fn steer_into_running_turn (
1007910054 is_dm : bool ,
10055+ prompt_is_dm : Option < bool > ,
1008010056 running_event : nostr:: Event ,
1008110057 incoming : nostr:: Event ,
1008210058 incoming_edit : Option < queue:: ResolvedEdit > ,
@@ -10100,6 +10076,12 @@ mod edit_native_steer_tests {
1010010076 running. push ( & mut queue, scope. clone ( ) ) ;
1010110077 queue. flush_next ( ) . expect ( "running turn" ) ;
1010210078 assert ! ( queue. is_scope_in_flight( & scope) ) ;
10079+ if let Some ( prompt_is_dm) = prompt_is_dm {
10080+ queue
10081+ . in_flight_prompt_dm ( & scope)
10082+ . expect ( "in-flight turn records its prompt classification" )
10083+ . record ( prompt_is_dm) ;
10084+ }
1010310085
1010410086 let mut pool = AgentPool :: from_slots ( vec ! [ ] ) ;
1010510087 let ( control_tx, mut control_rx) = tokio:: sync:: oneshot:: channel ( ) ;
@@ -10129,7 +10111,6 @@ mod edit_native_steer_tests {
1012910111 incoming_ingress
1013010112 . push ( & mut queue, scope. clone ( ) )
1013110113 . steer_or_interrupt (
10132- is_dm,
1013310114 MultipleEventHandling :: Steer ,
1013410115 None ,
1013510116 & mut pool,
@@ -10205,7 +10186,8 @@ mod edit_native_steer_tests {
1020510186 /// natively into the running turn rather than cancelling it.
1020610187 #[ tokio:: test]
1020710188 async fn dm_top_level_follow_up_steers_natively ( ) {
10208- let ( steer, control) = steer_into_running_turn ( true , message ( None ) , message ( None ) , None ) ;
10189+ let ( steer, control) =
10190+ steer_into_running_turn ( true , Some ( true ) , message ( None ) , message ( None ) , None ) ;
1020910191
1021010192 assert ! ( steer. is_some( ) , "DM follow-up is sent as a native steer" ) ;
1021110193 assert_eq ! (
@@ -10220,14 +10202,42 @@ mod edit_native_steer_tests {
1022010202 async fn dm_thread_reply_during_top_level_turn_cancels_and_merges ( ) {
1022110203 let root = "ab" . repeat ( 32 ) ;
1022210204 let ( steer, control) =
10223- steer_into_running_turn ( true , message ( None ) , message ( Some ( & root) ) , None ) ;
10205+ steer_into_running_turn ( true , Some ( true ) , message ( None ) , message ( Some ( & root) ) , None ) ;
1022410206
1022510207 assert ! (
1022610208 steer. is_none( ) ,
1022710209 "no native steer into a different DM thread"
1022810210 ) ;
1022910211 assert_eq ! ( control, Some ( ControlSignal :: Steer ) ) ;
1023010212 }
10213+
10214+ /// A DM turn whose prompt was rendered while channel metadata was
10215+ /// unavailable got channel-style `<context>`: its replies go to a thread
10216+ /// rooted at its trigger. The DM rule must not apply once metadata
10217+ /// resolves, so a top-level follow-up takes the cancel+merge path.
10218+ #[ tokio:: test]
10219+ async fn dm_follow_up_into_channel_formatted_turn_cancels_and_merges ( ) {
10220+ let ( steer, control) =
10221+ steer_into_running_turn ( true , Some ( false ) , message ( None ) , message ( None ) , None ) ;
10222+
10223+ assert ! (
10224+ steer. is_none( ) ,
10225+ "steer guard follows the running prompt's classification"
10226+ ) ;
10227+ assert_eq ! ( control, Some ( ControlSignal :: Steer ) ) ;
10228+ }
10229+
10230+ /// Before the prompt task records its classification, nothing proves
10231+ /// which `<context>` the turn will carry, so the follow-up takes the
10232+ /// cancel+merge path.
10233+ #[ tokio:: test]
10234+ async fn follow_up_before_prompt_classification_cancels_and_merges ( ) {
10235+ let ( steer, control) =
10236+ steer_into_running_turn ( true , None , message ( None ) , message ( None ) , None ) ;
10237+
10238+ assert ! ( steer. is_none( ) , "no native steer without a recorded prompt" ) ;
10239+ assert_eq ! ( control, Some ( ControlSignal :: Steer ) ) ;
10240+ }
1023110241}
1023210242
1023310243#[ cfg( test) ]
0 commit comments