Private
Public Access
0
0

fix(log_pruner): shorter retry loop, smaller sleep to avoid blocking startup

This commit is contained in:
2026-06-05 12:26:58 -04:00
parent 970f198ca6
commit ac08ee875c
+11 -8
View File
@@ -100,21 +100,24 @@ class LogPruner:
try: try:
sys.stderr.write(f"[LogPruner] Removing {session_id} at {resolved_path} (Size: {total_size} bytes)\n") sys.stderr.write(f"[LogPruner] Removing {session_id} at {resolved_path} (Size: {total_size} bytes)\n")
# Windows specific: sometimes files are locked. # Windows specific: sometimes files are locked by the running GUI process.
# We try a few times with small delays. # 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): def remove_readonly(func, path, excinfo):
os.chmod(path, 0o777) os.chmod(path, 0o777)
func(path) func(path)
for attempt in range(3): last_err = None
for attempt in range(2):
try: try:
shutil.rmtree(resolved_path, onerror=remove_readonly) shutil.rmtree(resolved_path, onerror=remove_readonly)
last_err = None
break break
except OSError: except OSError as e:
if attempt < 2: last_err = e
time.sleep(0.1) time.sleep(0.05)
else: if last_err is not None:
raise raise last_err
# Also remove from registry to keep it in sync # Also remove from registry to keep it in sync
if session_id in self.log_registry.data: if session_id in self.log_registry.data: