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

index fc230fa7d8dd06d11b7f5e650939d4e462765fa8..c3fb12086b5ed045664dcd47b47a9ae29f7fd011 100644 (file)
@@ -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(
index 928e970bd13c491ebeb1d4c85d73cc0be8b031cf..cd05cb2653d52193aee3e4b84f9f9387f08ab0e0 100644 (file)
@@ -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