File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,7 +40,15 @@ impl ClarificationHub {
4040
4141 /// Remove a pending wait without notifying the tool (e.g. cooperative cancellation).
4242 pub fn cancel_wait ( & self , session_key : & str ) {
43- self . pending . remove ( session_key) ;
43+ let _ = self . cancel_wait_if_pending ( session_key) ;
44+ }
45+
46+ /// Remove a pending wait and report whether this call claimed it.
47+ ///
48+ /// Interactive hosts use this to reject duplicate dismissals instead of
49+ /// presenting a stale clarification as successfully dismissed.
50+ pub fn cancel_wait_if_pending ( & self , session_key : & str ) -> bool {
51+ self . pending . remove ( session_key) . is_some ( )
4452 }
4553
4654 /// If a tool is waiting on `session_key`, deliver `text` and return `true`.
@@ -86,4 +94,13 @@ mod tests {
8694 assert ! ( !hub. try_deliver_reply( "t:1:" , "late" . into( ) ) ) ;
8795 assert ! ( rx. await . is_err( ) ) ;
8896 }
97+
98+ #[ tokio:: test]
99+ async fn cancel_wait_if_pending_claims_once ( ) {
100+ let hub = ClarificationHub :: new ( ) ;
101+ let rx = hub. begin_wait ( "t:1:" ) . expect ( "begin" ) ;
102+ assert ! ( hub. cancel_wait_if_pending( "t:1:" ) ) ;
103+ assert ! ( !hub. cancel_wait_if_pending( "t:1:" ) ) ;
104+ assert ! ( rx. await . is_err( ) ) ;
105+ }
89106}
You can’t perform that action at this time.
0 commit comments