@@ -46,8 +46,6 @@ class ResultCache:
4646 Its purpose is to act as a central point for managing in progress
4747 async calls, allowing multiple clients to join and receive progress
4848 updates, get results and/or cancel in progress calls
49- TODO CRITICAL keep_alive logic is not correct as per spec - results currently
50- only kept for as long as longest session reintroduce TTL cache
5149 TODO MAJOR needs a lot more testing around edge cases/failure scenarios
5250 TODO MAJOR decide if async.Locks are required for integrity of internal
5351 data structures
@@ -130,7 +128,6 @@ async def call_tool():
130128 in_progress .future = self ._portal .start_task_soon (call_tool )
131129 result = types .CallToolAsyncResult (
132130 token = in_progress .token ,
133- recieved = round (self ._timer ()),
134131 keepAlive = timeout ,
135132 accepted = True ,
136133 )
@@ -248,19 +245,20 @@ async def notification_hook(
248245
249246 async def session_close_hook (self , session : ServerSession ):
250247 session_id = id (session )
251- logger .debug (f"Closing { session_id } " )
248+ logger .debug (f"Received session close for { session_id } " )
252249 dropped = self ._session_lookup .pop (session_id , None )
253- assert dropped is not None , f"Discarded callback, unknown session { session_id } "
250+ if dropped is None :
251+ # lots of sessions will have no async tasks debug and return
252+ logger .debug (f"Discarded callback, unknown session { session_id } " )
253+ return
254254
255255 in_progress = self ._in_progress .get (dropped )
256- if in_progress is None :
257- logger .warning ("In progress not found" )
258- else :
259- found = in_progress .sessions .pop (session_id , None )
260- if found is None :
261- logger .warning ("No session found" )
262- if len (in_progress .sessions ) == 0 :
263- in_progress .keep_alive_start = int (self ._timer ())
256+ assert in_progress is not None , "In progress not found"
257+ found = in_progress .sessions .pop (session_id , None )
258+ if found is None :
259+ logger .warning ("No session found" )
260+ if len (in_progress .sessions ) == 0 :
261+ in_progress .keep_alive_start = int (self ._timer ())
264262
265263 async def _expire (self ):
266264 for in_progress in self ._in_progress .values ():
0 commit comments