test(agent): cover early user-message persistence

Use session.add_message for the pre-turn user-message flush and add focused regression tests for crash-time persistence and duplicate-free successful saves.

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-04-13 10:26:09 +08:00
committed by Xubin Ren
parent ea94a9c088
commit b964a894d2
2 changed files with 63 additions and 6 deletions
+1 -6
View File
@@ -701,12 +701,7 @@ class AgentLoop:
# makes recovery possible from the session log alone.
user_persisted_early = False
if isinstance(msg.content, str) and msg.content.strip():
from datetime import datetime as _dt
session.messages.append({
"role": "user",
"content": msg.content,
"timestamp": _dt.now().isoformat(),
})
session.add_message("user", msg.content)
self.sessions.save(session)
user_persisted_early = True