fix(session): require user anchor for delivery retention

This commit is contained in:
chengyongru
2026-08-07 10:53:55 +08:00
committed by chengyongru
parent 60282d1588
commit 8dfce4c162
2 changed files with 20 additions and 4 deletions
+6 -4
View File
@@ -352,12 +352,14 @@ class Session:
start_idx = max(0, len(self.messages) - max_messages)
if extend_to_user:
start_idx = next(
recovered_user = next(
(i for i in range(start_idx, -1, -1) if self.messages[i].get("role") == "user"),
start_idx,
None,
)
if start_idx > 0 and self.messages[start_idx - 1].get("_channel_delivery"):
start_idx -= 1
if recovered_user is not None:
start_idx = recovered_user
if start_idx > 0 and self.messages[start_idx - 1].get("_channel_delivery"):
start_idx -= 1
retained = self.messages[start_idx:]