From 9c975c8d1d60ffbf6b5f992f23388fc05379b2eb Mon Sep 17 00:00:00 2001 From: Nik Shevchenko Date: Tue, 17 Mar 2026 17:52:12 -0400 Subject: [PATCH] Fix calendar synthesis JSON parsing from LLM responses The ACPBridge LLM sometimes returns JSON wrapped in markdown code fences or with leading text. Strip code fences and find the JSON object before parsing. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Sources/CalendarReaderService.swift | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/desktop/Desktop/Sources/CalendarReaderService.swift b/desktop/Desktop/Sources/CalendarReaderService.swift index 0a930711c07..800453a0297 100644 --- a/desktop/Desktop/Sources/CalendarReaderService.swift +++ b/desktop/Desktop/Sources/CalendarReaderService.swift @@ -161,9 +161,27 @@ actor CalendarReaderService { onToolActivity: { @Sendable _, _, _, _ in } ) - let responseText = result.text + var responseText = result.text log("CalendarReaderService: Synthesis raw response (\(responseText.count) chars): \(responseText.prefix(300))") + // Extract JSON from response — handle markdown code fences and leading text + if let jsonStart = responseText.range(of: "```json") { + responseText = String(responseText[jsonStart.upperBound...]) + if let jsonEnd = responseText.range(of: "```") { + responseText = String(responseText[..