@@ -112,7 +112,7 @@ class LoopTerminationError(Exception):
112112 class LoopResumeError (Exception ):
113113 """Exception raised when loop conditions indicate the loop should stop all coroutines and resume"""
114114
115- def __init__ (self ) -> None :
115+ def __init__ (self , * , use_pickle_session : bool = True ) -> None :
116116 # progress control
117117 self .loop_idx : int = 0 # current loop index / next loop index to kickoff
118118 self .step_idx : defaultdict [int , int ] = defaultdict (int ) # dict from loop index to next step index
@@ -133,6 +133,9 @@ def __init__(self) -> None:
133133
134134 self .semaphores : dict [str , asyncio .Semaphore ] = {}
135135
136+ # When False, skip pickle-based session dump/load (e.g. Claudex adapters use artifact JSON as SSOT)
137+ self .use_pickle_session : bool = use_pickle_session
138+
136139 def get_unfinished_loop_cnt (self , next_loop : int ) -> int :
137140 n = 0
138141 for li in range (next_loop ):
@@ -300,7 +303,7 @@ async def _run_step(self, li: int, force_subproc: bool = False) -> None:
300303 # Save snapshot after completing the step;
301304 # 1) It has to be after the step_idx is updated, so loading the snapshot will be on the right step.
302305 # 2) Only save it when the step forward, withdraw does not worth saving.
303- if name in self .loop_prev_out [li ]:
306+ if self . use_pickle_session and name in self .loop_prev_out [li ]:
304307 # 3) Only dump the step if (so we don't have to redo the step when we load the session again)
305308 # it has been executed successfully
306309 self .dump (self .session_folder / f"{ li } " / f"{ si } _{ name } " )
@@ -403,6 +406,9 @@ async def run(self, step_n: int | None = None, loop_n: int | None = None, all_du
403406 self .close_pbar ()
404407
405408 def withdraw_loop (self , loop_idx : int ) -> None :
409+ if not self .use_pickle_session :
410+ logger .warning (f"Pickle session disabled; cannot withdraw loop { loop_idx } . Skipping." )
411+ return
406412 prev_session_dir = self .session_folder / str (loop_idx - 1 )
407413 prev_path = min (
408414 (p for p in prev_session_dir .glob ("*_*" ) if p .is_file ()),
0 commit comments