fix(memory): preserve full consolidation input
This commit is contained in:
1 parent
835cac0ae7
commit
d4e23dec12
2 files changed
+25
-8
No files matched your search
+21
-4
@@ -669,11 +669,28 @@ class MemoryStore:
|
|||||||
max_chars: int | None = None,
|
max_chars: int | None = None,
|
||||||
session_key: str | None = None,
|
session_key: str | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Persist and return a bounded raw checkpoint when summarization degrades."""
|
"""Persist raw messages in bounded chunks and return a checkpoint."""
|
||||||
checkpoint = self._build_raw_checkpoint(messages, max_chars=max_chars)
|
limit = max_chars if max_chars is not None else _RAW_ARCHIVE_MAX_CHARS
|
||||||
self.append_history(checkpoint, session_key=session_key)
|
chunk_size = min(max(1, limit), _HISTORY_ENTRY_HARD_CAP - 1_000)
|
||||||
|
formatted = self._format_messages(public_history_messages(messages))
|
||||||
|
chunks = [
|
||||||
|
formatted[start:start + chunk_size]
|
||||||
|
for start in range(0, len(formatted), chunk_size)
|
||||||
|
] or [""]
|
||||||
|
for part, chunk in enumerate(chunks, start=1):
|
||||||
|
suffix = f" (part {part}/{len(chunks)})" if len(chunks) > 1 else ""
|
||||||
|
self.append_history(
|
||||||
|
f"[RAW] {len(messages)} messages{suffix}\n{chunk}",
|
||||||
|
session_key=session_key,
|
||||||
|
)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Memory consolidation degraded: raw-archived {} messages", len(messages)
|
"Memory consolidation degraded: raw-archived {} messages in {} entries",
|
||||||
|
len(messages),
|
||||||
|
len(chunks),
|
||||||
|
)
|
||||||
|
checkpoint = self._normalize_history_entry(
|
||||||
|
f"[RAW] {len(messages)} messages\n{formatted}",
|
||||||
|
max_chars=limit,
|
||||||
)
|
)
|
||||||
return checkpoint
|
return checkpoint
|
||||||
|
|
||||||
|
|||||||
@@ -1333,7 +1333,6 @@ class TestCompactIdleSession:
|
|||||||
assert mock_provider.chat_stream_with_retry.await_count == 2
|
assert mock_provider.chat_stream_with_retry.await_count == 2
|
||||||
entries = store.read_unprocessed_history(since_cursor=0)
|
entries = store.read_unprocessed_history(since_cursor=0)
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
assert entries[0]["content"].startswith("[RAW] ")
|
|
||||||
assert "important answer" in entries[0]["content"]
|
assert "important answer" in entries[0]["content"]
|
||||||
assert sessions.get_or_create("cli:repeated-tool").last_archived == 2
|
assert sessions.get_or_create("cli:repeated-tool").last_archived == 2
|
||||||
|
|
||||||
@@ -1391,8 +1390,9 @@ class TestCompactIdleSession:
|
|||||||
assert "[RAW]" in result
|
assert "[RAW]" in result
|
||||||
mock_provider.chat_stream_with_retry.assert_not_awaited()
|
mock_provider.chat_stream_with_retry.assert_not_awaited()
|
||||||
entries = store.read_unprocessed_history(since_cursor=0)
|
entries = store.read_unprocessed_history(since_cursor=0)
|
||||||
assert len(entries) == 1
|
assert len(entries) > 1
|
||||||
assert entries[0]["content"].startswith("[RAW] ")
|
assert all(entry["content"].startswith("[RAW] ") for entry in entries)
|
||||||
|
assert "x" * 100_000 in "".join(entry["content"].split("\n", 1)[1] for entry in entries)
|
||||||
assert sessions.get_or_create("sdk:oversized").last_archived == 1
|
assert sessions.get_or_create("sdk:oversized").last_archived == 1
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -1523,7 +1523,7 @@ class TestRawArchiveTruncation:
|
|||||||
messages = [{"role": "user", "content": big}]
|
messages = [{"role": "user", "content": big}]
|
||||||
store.raw_archive(messages)
|
store.raw_archive(messages)
|
||||||
entries = store.read_unprocessed_history(since_cursor=0)
|
entries = store.read_unprocessed_history(since_cursor=0)
|
||||||
assert len(entries) == 1
|
assert len(entries) > 1
|
||||||
assert len(entries[0]["content"]) < 50_000
|
assert len(entries[0]["content"]) < 50_000
|
||||||
assert "[RAW]" in entries[0]["content"]
|
assert "[RAW]" in entries[0]["content"]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user