From 325e371c1b8d21461500e9f2626582cc3e1b9066 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 3 Jul 2026 17:59:45 +0200 Subject: [PATCH] fix(optuna): reject non-record journal tails --- .../freqaimodels/optuna_journal_recovery.py | 4 ++-- .../freqaimodels/QuickAdapterRegressorV3.py | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py b/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py index fc230fa..c3fb120 100644 --- a/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py +++ b/ReforceXY/user_data/freqaimodels/optuna_journal_recovery.py @@ -48,10 +48,10 @@ def journal_has_corrupt_tail(journal_path: Path) -> bool: if not last_line: return True try: - json.loads(last_line) + record = json.loads(last_line) except ValueError: return True - return False + return not isinstance(record, dict) or "op_code" not in record def create_recovered_journal_storage( diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 928e970..cd05cb2 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -4233,11 +4233,12 @@ class QuickAdapterRegressorV3(BaseRegressionModel): Bounded tail probe (last ``_OPTUNA_JOURNAL_TAIL_PROBE_BYTES``). Return True iff the file is non-empty AND its trailing record - is (a) missing the newline, (b) empty (bare ``\\n``), or + is (a) missing the newline, (b) empty (bare ``\\n``), (c) not parseable by ``json.loads`` (malformed JSON or - invalid UTF-8). Fail-open when the probe window cuts a single - line larger than the window; defer to the post-construction - handler. + invalid UTF-8), or (d) not an Optuna operation record dict + containing ``op_code``. Fail-open when the probe window cuts a + single line larger than the window; defer to the + post-construction handler. """ if not journal_path.exists(): return False @@ -4267,10 +4268,10 @@ class QuickAdapterRegressorV3(BaseRegressionModel): if not last_line: return True try: - json.loads(last_line) + record = json.loads(last_line) except ValueError: return True - return False + return not isinstance(record, dict) or "op_code" not in record def optuna_create_storage(self, pair: str) -> optuna.storages.BaseStorage: storage_dir = self.full_path -- 2.53.0