From 70a6b5e6efd7ddd33f4916c82adbeff1ed7b408c Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Mon, 18 May 2026 17:25:14 +0100 Subject: [PATCH] fix(ai): strip markdown code block from Anthropic response before JSON parse Claude Haiku wraps JSON in ```json ... ``` blocks, causing json.loads to fail silently. The except clause swallowed the error, leaving ai_title empty for all 303 sessions. Co-Authored-By: Claude Sonnet 4.6 --- src/services/ai_session_summary.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/ai_session_summary.py b/src/services/ai_session_summary.py index 68dfedd..67d7745 100644 --- a/src/services/ai_session_summary.py +++ b/src/services/ai_session_summary.py @@ -41,6 +41,10 @@ Return only valid JSON, no other text.""" try: text = response.content[0].text.strip() + # Strip markdown code block if model wraps response (e.g. ```json ... ```) + if text.startswith("```"): + text = text.split("\n", 1)[1] if "\n" in text else text + text = text.rsplit("```", 1)[0].strip() data = json.loads(text) ai_title = str(data.get("title", ""))[:200] ai_result = str(data.get("result", ""))