]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(optuna): recover non-record journal replay errors
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 3 Jul 2026 17:01:58 +0000 (19:01 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 3 Jul 2026 17:01:58 +0000 (19:01 +0200)
ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py

index c3fb12086b5ed045664dcd47b47a9ae29f7fd011..32246930e1687de039dab893406109e2d9c423c6 100644 (file)
@@ -17,6 +17,7 @@ _JOURNAL_QUARANTINE_TAG: Final[str] = "corrupt"
 _JOURNAL_QUARANTINE_TIE_BREAK_LIMIT: Final[int] = 99
 _JOURNAL_RECOVERABLE_ERRORS: Final[type[Exception] | tuple[type[Exception], ...]] = (
     KeyError,
+    TypeError,
     ValueError,
     json.JSONDecodeError,
 )
@@ -95,13 +96,10 @@ def _quarantine_journal(journal_path: Path, cause: Exception) -> Path | None:
 
 def _quarantine_path(journal_path: Path, now: datetime) -> Path:
     stamp = now.strftime("%Y%m%dT%H%M%S%fZ")
-    candidate = journal_path.with_name(
-        f"{journal_path.name}.{_JOURNAL_QUARANTINE_TAG}-{stamp}"
-    )
-    for index in range(1, _JOURNAL_QUARANTINE_TIE_BREAK_LIMIT + 1):
+    base_name = f"{journal_path.name}.{_JOURNAL_QUARANTINE_TAG}-{stamp}"
+    for index in range(_JOURNAL_QUARANTINE_TIE_BREAK_LIMIT + 1):
+        suffix = "" if index == 0 else f"-{index}"
+        candidate = journal_path.with_name(f"{base_name}{suffix}")
         if not candidate.exists():
             return candidate
-        candidate = journal_path.with_name(
-            f"{journal_path.name}.{_JOURNAL_QUARANTINE_TAG}-{stamp}-{index}"
-        )
-    return candidate
+    raise FileExistsError(journal_path)
index cd05cb2653d52193aee3e4b84f9f9387f08ab0e0..6e40c201d8df88a1c59e7e14f4208025c81acdc8 100644 (file)
@@ -230,6 +230,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
     _OPTUNA_JOURNAL_QUARANTINE_TAG: Final[str] = "corrupt"
     _OPTUNA_JOURNAL_RECOVERABLE_ERRORS: Final[tuple[type[Exception], ...]] = (
         KeyError,
+        TypeError,
         ValueError,
         json.JSONDecodeError,
     )
@@ -4172,18 +4173,18 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
         The tag is appended *after* ``.log`` so the live-journal glob
         ``optuna-*.log`` never matches quarantined artefacts. Collisions
         are bounded by ``_OPTUNA_JOURNAL_QUARANTINE_TIE_BREAK_LIMIT``;
-        microsecond UTC stamping makes them practically impossible.
+        exhausted candidates raise instead of reusing a quarantine file.
         """
         stamp = now.strftime("%Y%m%dT%H%M%S%fZ")
         tag = QuickAdapterRegressorV3._OPTUNA_JOURNAL_QUARANTINE_TAG
-        candidate = journal_path.with_name(f"{journal_path.name}.{tag}-{stamp}")
-        for n in range(
-            1, QuickAdapterRegressorV3._OPTUNA_JOURNAL_QUARANTINE_TIE_BREAK_LIMIT + 1
-        ):
+        base_name = f"{journal_path.name}.{tag}-{stamp}"
+        limit = QuickAdapterRegressorV3._OPTUNA_JOURNAL_QUARANTINE_TIE_BREAK_LIMIT
+        for index in range(limit + 1):
+            suffix = "" if index == 0 else f"-{index}"
+            candidate = journal_path.with_name(f"{base_name}{suffix}")
             if not candidate.exists():
                 return candidate
-            candidate = journal_path.with_name(f"{journal_path.name}.{tag}-{stamp}-{n}")
-        return candidate
+        raise FileExistsError(journal_path)
 
     @staticmethod
     def _optuna_quarantine_journal(