style(memory): minimize summary diff churn

This commit is contained in:
chengyongru
2026-08-19 18:40:20 +08:00
committed by chengyongru
parent b162019271
commit 87fb090d22
5 changed files with 8 additions and 32 deletions
+1 -5
View File
@@ -102,11 +102,7 @@ class AutoCompact:
finally:
self._archiving.discard(key)
def prepare_session(
self,
session: Session,
key: str,
) -> tuple[Session, SessionSummary | None]:
def prepare_session(self, session: Session, key: str) -> tuple[Session, SessionSummary | None]:
if self._is_internal_session(key):
self._archiving.discard(key)
self._summaries.pop(key, None)
+1 -4
View File
@@ -686,10 +686,7 @@ class TestPrepareSession:
ac.sessions = mock_sm
key = "dream:20260602-155256"
ac._archiving.add(key)
ac._summaries[key] = SessionSummary(
"Hot summary.",
datetime(2026, 6, 2, 15, 52, 56),
)
ac._summaries[key] = SessionSummary("Hot summary.", datetime(2026, 6, 2, 15, 52, 56))
session = _make_session(
key=key,
updated_at=datetime.now() - timedelta(minutes=20),
+4 -12
View File
@@ -332,24 +332,16 @@ class TestBuildSystemPrompt:
def test_includes_session_summary(self, tmp_path):
builder = _builder(tmp_path)
result = builder.build_system_prompt(
session_summary=SessionSummary(
text="Previous chat about Python.",
last_active=datetime(2026, 8, 19, 10, 0),
)
)
summary = SessionSummary("Previous chat about Python.", datetime(2026, 8, 19, 10, 0))
result = builder.build_system_prompt(session_summary=summary)
assert "Previous chat about Python." in result
assert "[Archived Context Summary]" in result
def test_sections_separated_by_separator(self, tmp_path):
(tmp_path / "AGENTS.md").write_text("Rules.", encoding="utf-8")
builder = _builder(tmp_path)
result = builder.build_system_prompt(
session_summary=SessionSummary(
text="Summary.",
last_active=datetime(2026, 8, 19, 10, 0),
)
)
summary = SessionSummary("Summary.", datetime(2026, 8, 19, 10, 0))
result = builder.build_system_prompt(session_summary=summary)
assert "\n\n---\n\n" in result
def test_no_bootstrap_no_summary(self, tmp_path):
+1 -4
View File
@@ -121,10 +121,7 @@ def test_session_summary_replaces_matching_recent_history_entry(tmp_path) -> Non
builder.memory.append_history("another session event", session_key=session_key)
summary_cursor = builder.memory.append_history(overview, session_key=session_key)
summary = SessionSummary(
text=overview,
last_active=real_datetime(2026, 8, 19, 10, 0),
)
summary = SessionSummary(overview, real_datetime(2026, 8, 19, 10, 0))
prompt = builder.build_system_prompt(
session_key=session_key,
@@ -213,13 +213,7 @@ async def test_preflight_consolidation_receives_pending_summary(tmp_path) -> Non
loop = _make_loop(tmp_path, estimated_tokens=100, context_window_tokens=200)
session = loop.sessions.get_or_create("cli:test")
loop.auto_compact.prepare_session = MagicMock(
return_value=(
session,
SessionSummary(
text="earlier context",
last_active=session.updated_at,
),
)
return_value=(session, SessionSummary("earlier context", session.updated_at))
) # type: ignore[method-assign]
loop.consolidator.maybe_consolidate_by_tokens = AsyncMock(return_value=None) # type: ignore[method-assign]
loop.schedule_background = lambda coro: coro.close() # type: ignore[method-assign]