fix(memory): fall back to raw_archive on LLM error response

When chat_with_retry returns an error response (finish_reason='error')
instead of raising an exception, archive() previously treated the error
message as a valid summary and wrote it to history.jsonl, while the
original session data was already cleared by /new — causing irreversible
data loss.

Fix: check finish_reason after the LLM call and raise RuntimeError on
error responses, which naturally falls through to the existing raw_archive
fallback. This preserves the original messages in history.jsonl instead
of losing them.

Fixes #3244
This commit is contained in:
Cheng Yongru
2026-04-17 20:15:07 +08:00
committed by Xubin Ren
parent ebbed1cbe2
commit aabc3d5017
2 changed files with 42 additions and 0 deletions
+2
View File
@@ -457,6 +457,8 @@ class Consolidator:
tools=None,
tool_choice=None,
)
if response.finish_reason == "error":
raise RuntimeError(f"LLM returned error: {response.content}")
summary = response.content or "[no summary]"
self.store.append_history(summary)
return summary