From: Jérôme Benoit Date: Fri, 3 Jul 2026 17:01:58 +0000 (+0200) Subject: fix(optuna): recover non-record journal replay errors X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=af0135191b931ef0d2896a9fa196dc99b6ec1628;p=freqai-strategies.git fix(optuna): recover non-record journal replay errors --- diff --git a/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py b/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py index c3fb120..3224693 100644 --- a/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py +++ b/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py @@ -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) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index cd05cb2..6e40c20 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -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(