@@ -49,15 +49,13 @@ def __init__(
4949 self ._timeout_seconds = timeout_seconds
5050 self ._tracing_adapter = FireworksTracingAdapter (base_url = self ._model_base_url )
5151 self ._session : Optional [aiohttp .ClientSession ] = None
52- self ._active_runs = 0
5352
5453 def _get_or_create_session (self ) -> aiohttp .ClientSession :
5554 if self ._session is None or self ._session .closed :
5655 self ._session = aiohttp .ClientSession ()
5756 return self ._session
5857
5958 def __call__ (self , rows : List [EvaluationRow ], config : RolloutProcessorConfig ) -> List [asyncio .Task [EvaluationRow ]]:
60- self ._active_runs += 1
6159 tasks : List [asyncio .Task [EvaluationRow ]] = []
6260
6361 # Start with constructor values
@@ -208,26 +206,17 @@ async def _sem_wrapper(r: EvaluationRow) -> EvaluationRow:
208206 tasks = [asyncio .create_task (_sem_wrapper (row )) for row in rows ]
209207 return tasks
210208
211- def _should_close_session (self ) -> bool :
212- self ._active_runs = max (0 , self ._active_runs - 1 )
213- return self ._active_runs == 0 and self ._session is not None and not self ._session .closed
214-
215209 async def acleanup (self ) -> None :
216- """Async cleanup — only closes the session when the last run finishes.
217-
218- rollout_processor_with_retry calls acleanup() per-run, but the session
219- is shared across parallel runs. Closing it early would cancel in-flight
220- requests in other runs.
221- """
222- if self ._should_close_session ():
223- await self ._session .close () # type: ignore[union-attr]
210+ """Async cleanup - preferred when you can await."""
211+ if self ._session and not self ._session .closed :
212+ await self ._session .close ()
224213
225214 def cleanup (self ) -> None :
226- """Sync cleanup — best-effort fallback when not in an async context ."""
227- if self ._should_close_session () :
215+ """Sync cleanup - best-effort, schedules close if event loop is running ."""
216+ if self ._session and not self . _session . closed :
228217 try :
229218 loop = asyncio .get_running_loop ()
230- loop .create_task (self ._session .close ()) # type: ignore[union-attr]
219+ loop .create_task (self ._session .close ())
231220 except RuntimeError :
232221 logger .warning (
233222 "RemoteRolloutProcessor.cleanup() called outside of async context. "
0 commit comments