diff --git a/src/log_pruner.py b/src/log_pruner.py index a5f35ca8..6d0f9be9 100644 --- a/src/log_pruner.py +++ b/src/log_pruner.py @@ -100,21 +100,24 @@ class LogPruner: try: sys.stderr.write(f"[LogPruner] Removing {session_id} at {resolved_path} (Size: {total_size} bytes)\n") - # Windows specific: sometimes files are locked. - # We try a few times with small delays. + # Windows specific: sometimes files are locked by the running GUI process. + # We try a few times with backoff so transient locks are retried but + # the main thread (e.g. hook server startup) is not blocked. def remove_readonly(func, path, excinfo): os.chmod(path, 0o777) func(path) - for attempt in range(3): + last_err = None + for attempt in range(2): try: shutil.rmtree(resolved_path, onerror=remove_readonly) + last_err = None break - except OSError: - if attempt < 2: - time.sleep(0.1) - else: - raise + except OSError as e: + last_err = e + time.sleep(0.05) + if last_err is not None: + raise last_err # Also remove from registry to keep it in sync if session_id in self.log_registry.data: