Fix optimize crash: normalize LLM strategies that return dicts instead of strings

The analysis LLM sometimes returns strategies as objects like
[{"name": "clarity"}] instead of plain strings ["clarity"]. The
', '.join(strategies) call then fails with "expected str, got dict".

Fix: normalize each strategy to a string regardless of format —
handles str, dict with name/strategy keys, or fallback to str().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root 2026-03-29 08:24:53 -05:00
parent 462d81868f
commit ef68f5b9f7

View File

@ -7531,7 +7531,18 @@ def _run_optimize(job_id, run_id):
j_e = analysis_raw.rfind("}") + 1 j_e = analysis_raw.rfind("}") + 1
if j_s >= 0 and j_e > j_s: if j_s >= 0 and j_e > j_s:
parsed = json.loads(analysis_raw[j_s:j_e]) parsed = json.loads(analysis_raw[j_s:j_e])
strategies = parsed.get("strategies", strategies)[:5] raw_strats = parsed.get("strategies", strategies)[:5]
# Normalize — LLM might return strings or dicts
strategies = []
for s in raw_strats:
if isinstance(s, str):
strategies.append(s)
elif isinstance(s, dict):
strategies.append(s.get("name", s.get("strategy", str(s))))
else:
strategies.append(str(s))
if not strategies:
strategies = ["clarity", "depth", "specificity"]
except Exception: except Exception:
pass pass