fix(agent): persist _last_summary across restarts with used sentinel

The previous implementation popped _last_summary from session.metadata
after injecting it into the prompt, then saved the session. This caused
the summary to be permanently lost after a process restart, making the
AI forget archived context and appear to ignore memory or reference
non-existent previous messages.

Replace the destructive pop with a _last_summary_used sentinel:
- _last_summary stays in metadata for restart survival
- _last_summary_used prevents duplicate injection within the same turn
- Clear the sentinel whenever a new summary is generated

Updates tests to match the new persistence behavior.
This commit is contained in:
chengyongru
2026-05-09 14:58:38 +08:00
committed by Xubin Ren
parent 56eee06736
commit e5a1416a37
4 changed files with 27 additions and 13 deletions
@@ -190,7 +190,10 @@ async def test_consolidation_persists_summary_for_next_prepare_session(tmp_path,
reloaded, pending = loop.auto_compact.prepare_session(reloaded, "cli:test")
assert pending is not None
assert "User discussed project status." in pending
assert "_last_summary" not in reloaded.metadata
# _last_summary persists for restart survival; _last_summary_used prevents
# duplicate injection within the same turn.
assert "_last_summary" in reloaded.metadata
assert reloaded.metadata.get("_last_summary_used") is True
@pytest.mark.asyncio