From dba41d760c7f11c8685ddf475e934d4a600f7f82 Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Sat, 31 Jan 2026 23:24:06 -0800 Subject: [PATCH] fix(cli): handle malformed AskUserQuestion data from LLM (#770) Co-authored-by: Letta --- src/cli/App.tsx | 11 +++++++---- src/cli/helpers/memoryReminder.ts | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cli/App.tsx b/src/cli/App.tsx index 4efe3aa..439a5ae 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -9264,10 +9264,13 @@ ${SYSTEM_REMINDER_CLOSE} parseMemoryPreference(questions, answers); // Format the answer string like Claude Code does - const answerParts = questions.map((q) => { - const answer = answers[q.question] || ""; - return `"${q.question}"="${answer}"`; - }); + // Filter out malformed questions (LLM might send invalid data) + const answerParts = questions + .filter((q) => q.question) + .map((q) => { + const answer = answers[q.question] || ""; + return `"${q.question}"="${answer}"`; + }); const toolReturn = `User has answered your questions: ${answerParts.join(", ")}. You can now continue with the user's answers in mind.`; const precomputedResult: ToolExecutionResult = { diff --git a/src/cli/helpers/memoryReminder.ts b/src/cli/helpers/memoryReminder.ts index 62b975b..92d29a1 100644 --- a/src/cli/helpers/memoryReminder.ts +++ b/src/cli/helpers/memoryReminder.ts @@ -60,6 +60,8 @@ export function parseMemoryPreference( answers: Record, ): boolean { for (const q of questions) { + // Skip malformed questions (LLM might send invalid data) + if (!q.question) continue; const questionLower = q.question.toLowerCase(); const headerLower = q.header?.toLowerCase() || "";