@@ -12,7 +12,7 @@ use std::sync::Arc;
1212use std:: time:: { Duration , Instant } ;
1313
1414use tokio:: sync:: RwLock ;
15- use tracing:: { debug, warn } ;
15+ use tracing:: debug;
1616
1717use crate :: tools:: spec:: ToolResult ;
1818
@@ -145,7 +145,12 @@ impl ToolResponseStore {
145145 ///
146146 /// If the store is at capacity, the oldest entry will be evicted.
147147 /// Returns `true` if an entry was evicted to make room.
148- pub async fn store ( & self , call_id : impl Into < String > , tool_name : impl Into < String > , result : ToolResult ) -> bool {
148+ pub async fn store (
149+ & self ,
150+ call_id : impl Into < String > ,
151+ tool_name : impl Into < String > ,
152+ result : ToolResult ,
153+ ) -> bool {
149154 let call_id = call_id. into ( ) ;
150155 let tool_name = tool_name. into ( ) ;
151156 let mut evicted = false ;
@@ -185,7 +190,7 @@ impl ToolResponseStore {
185190 /// Marks the response as read but does not consume it.
186191 pub async fn get ( & self , call_id : & str ) -> Option < ToolResult > {
187192 let mut responses = self . responses . write ( ) . await ;
188-
193+
189194 if let Some ( response) = responses. get_mut ( call_id) {
190195 response. read = true ;
191196 let mut stats = self . stats . write ( ) . await ;
@@ -202,7 +207,7 @@ impl ToolResponseStore {
202207 /// entries are cleaned up after being consumed (#5293).
203208 pub async fn take ( & self , call_id : & str ) -> Option < ToolResult > {
204209 let mut responses = self . responses . write ( ) . await ;
205-
210+
206211 if let Some ( response) = responses. remove ( call_id) {
207212 let mut stats = self . stats . write ( ) . await ;
208213 stats. takes += 1 ;
@@ -234,16 +239,16 @@ impl ToolResponseStore {
234239 let mut responses = self . responses . write ( ) . await ;
235240 let ttl = self . config . ttl ;
236241 let before = responses. len ( ) ;
237-
242+
238243 responses. retain ( |_, v| !v. is_expired ( ttl) ) ;
239-
244+
240245 let removed = before - responses. len ( ) ;
241246 if removed > 0 {
242247 debug ! ( removed, "Cleaned up expired responses" ) ;
243248 let mut stats = self . stats . write ( ) . await ;
244249 stats. expired_cleanups += removed as u64 ;
245250 }
246-
251+
247252 removed
248253 }
249254
@@ -253,14 +258,14 @@ impl ToolResponseStore {
253258 pub async fn cleanup_read ( & self ) -> usize {
254259 let mut responses = self . responses . write ( ) . await ;
255260 let before = responses. len ( ) ;
256-
261+
257262 responses. retain ( |_, v| !v. read ) ;
258-
263+
259264 let removed = before - responses. len ( ) ;
260265 if removed > 0 {
261266 debug ! ( removed, "Cleaned up read-but-not-consumed responses" ) ;
262267 }
263-
268+
264269 removed
265270 }
266271
@@ -278,7 +283,7 @@ impl ToolResponseStore {
278283 pub async fn info ( & self ) -> StoreInfo {
279284 let responses = self . responses . read ( ) . await ;
280285 let stats = self . stats . read ( ) . await ;
281-
286+
282287 StoreInfo {
283288 current_size : responses. len ( ) ,
284289 max_size : self . config . max_size ,
@@ -411,14 +416,22 @@ mod tests {
411416 let store = ToolResponseStore :: with_config ( config) ;
412417
413418 // Fill to capacity
414- store. store ( "call-1" , "Read" , ToolResult :: success ( "1" ) ) . await ;
415- store. store ( "call-2" , "Read" , ToolResult :: success ( "2" ) ) . await ;
416- store. store ( "call-3" , "Read" , ToolResult :: success ( "3" ) ) . await ;
419+ store
420+ . store ( "call-1" , "Read" , ToolResult :: success ( "1" ) )
421+ . await ;
422+ store
423+ . store ( "call-2" , "Read" , ToolResult :: success ( "2" ) )
424+ . await ;
425+ store
426+ . store ( "call-3" , "Read" , ToolResult :: success ( "3" ) )
427+ . await ;
417428
418429 assert_eq ! ( store. len( ) . await , 3 ) ;
419430
420431 // Add one more, should evict oldest
421- let evicted = store. store ( "call-4" , "Read" , ToolResult :: success ( "4" ) ) . await ;
432+ let evicted = store
433+ . store ( "call-4" , "Read" , ToolResult :: success ( "4" ) )
434+ . await ;
422435 assert ! ( evicted) ;
423436 assert_eq ! ( store. len( ) . await , 3 ) ;
424437
@@ -429,11 +442,12 @@ mod tests {
429442
430443 #[ tokio:: test]
431444 async fn test_expired_cleanup ( ) {
432- let config = ToolResponseStoreConfig :: default ( )
433- . with_ttl ( Duration :: from_millis ( 50 ) ) ;
445+ let config = ToolResponseStoreConfig :: default ( ) . with_ttl ( Duration :: from_millis ( 50 ) ) ;
434446 let store = ToolResponseStore :: with_config ( config) ;
435447
436- store. store ( "call-1" , "Read" , ToolResult :: success ( "1" ) ) . await ;
448+ store
449+ . store ( "call-1" , "Read" , ToolResult :: success ( "1" ) )
450+ . await ;
437451 assert_eq ! ( store. len( ) . await , 1 ) ;
438452
439453 // Wait for expiration
@@ -448,8 +462,12 @@ mod tests {
448462 async fn test_cleanup_read ( ) {
449463 let store = ToolResponseStore :: new ( ) ;
450464
451- store. store ( "call-1" , "Read" , ToolResult :: success ( "1" ) ) . await ;
452- store. store ( "call-2" , "Read" , ToolResult :: success ( "2" ) ) . await ;
465+ store
466+ . store ( "call-1" , "Read" , ToolResult :: success ( "1" ) )
467+ . await ;
468+ store
469+ . store ( "call-2" , "Read" , ToolResult :: success ( "2" ) )
470+ . await ;
453471
454472 // Read one entry
455473 store. get ( "call-1" ) . await ;
@@ -466,7 +484,9 @@ mod tests {
466484 async fn test_stats ( ) {
467485 let store = ToolResponseStore :: new ( ) ;
468486
469- store. store ( "call-1" , "Read" , ToolResult :: success ( "1" ) ) . await ;
487+ store
488+ . store ( "call-1" , "Read" , ToolResult :: success ( "1" ) )
489+ . await ;
470490 store. get ( "call-1" ) . await ;
471491 store. take ( "call-1" ) . await ;
472492
@@ -489,8 +509,12 @@ mod tests {
489509 async fn test_clear ( ) {
490510 let store = ToolResponseStore :: new ( ) ;
491511
492- store. store ( "call-1" , "Read" , ToolResult :: success ( "1" ) ) . await ;
493- store. store ( "call-2" , "Read" , ToolResult :: success ( "2" ) ) . await ;
512+ store
513+ . store ( "call-1" , "Read" , ToolResult :: success ( "1" ) )
514+ . await ;
515+ store
516+ . store ( "call-2" , "Read" , ToolResult :: success ( "2" ) )
517+ . await ;
494518
495519 assert_eq ! ( store. len( ) . await , 2 ) ;
496520
@@ -502,7 +526,9 @@ mod tests {
502526 async fn test_info ( ) {
503527 let store = ToolResponseStore :: new ( ) ;
504528
505- store. store ( "call-1" , "Read" , ToolResult :: success ( "1" ) ) . await ;
529+ store
530+ . store ( "call-1" , "Read" , ToolResult :: success ( "1" ) )
531+ . await ;
506532
507533 let info = store. info ( ) . await ;
508534 assert_eq ! ( info. current_size, 1 ) ;
0 commit comments