fix: use summary checkpoints for all compaction triggers (#5694)
* fix: exclude archived history after manual compaction * refactor: share summary checkpoints across compaction paths * fix: use summary checkpoints for every compaction trigger * test: assert replay starts at the archived boundary * fix: preserve nothing summaries without raw fallback * test: assert compaction results positively * test: verify checkpoint continuation after session reload
This commit is contained in:
1 parent
c039a7052a
commit
3548aec576
18 files changed
+335
-271
No files matched your search
+4
-32
@@ -99,7 +99,6 @@ from nanobot.session.recovery import (
|
||||
restore_runtime_checkpoint,
|
||||
)
|
||||
from nanobot.session.summary import (
|
||||
SUMMARY_CONTINUATION_TEXT,
|
||||
SessionSummary,
|
||||
SessionSummaryCheckpoint,
|
||||
)
|
||||
@@ -2140,32 +2139,6 @@ class AgentLoop:
|
||||
|
||||
return filtered
|
||||
|
||||
@staticmethod
|
||||
def _insert_summary_checkpoint(
|
||||
session: Session,
|
||||
checkpoint: SessionSummaryCheckpoint,
|
||||
*,
|
||||
insert_at: int | None = None,
|
||||
) -> None:
|
||||
"""Commit a replacement summary and its hidden transcript boundary."""
|
||||
hint = {
|
||||
"role": "user",
|
||||
"content": SUMMARY_CONTINUATION_TEXT,
|
||||
HIDDEN_HISTORY_META: True,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
}
|
||||
if insert_at is None:
|
||||
session.messages.append(hint)
|
||||
checkpoint_session_index = len(session.messages) - 1
|
||||
else:
|
||||
session.messages.insert(insert_at, hint)
|
||||
checkpoint_session_index = insert_at
|
||||
session.metadata["_last_summary"] = {
|
||||
"text": checkpoint.summary,
|
||||
"last_active": session.updated_at.isoformat(),
|
||||
}
|
||||
session.last_archived = checkpoint_session_index
|
||||
|
||||
@staticmethod
|
||||
def _validated_checkpoint_boundary(
|
||||
checkpoint: SessionSummaryCheckpoint | None,
|
||||
@@ -2227,9 +2200,8 @@ class AgentLoop:
|
||||
# the first message after the replacement checkpoint.
|
||||
if summary_checkpoint is not None and checkpoint_boundary == skip - 1:
|
||||
insert_at = len(session.messages) - (1 if input_persisted_early else 0)
|
||||
self._insert_summary_checkpoint(
|
||||
session,
|
||||
summary_checkpoint,
|
||||
session.commit_summary_checkpoint(
|
||||
summary_checkpoint.summary,
|
||||
insert_at=insert_at,
|
||||
)
|
||||
|
||||
@@ -2237,7 +2209,7 @@ class AgentLoop:
|
||||
# Insert against the raw transcript index before filtering the
|
||||
# message so persistence cleanup cannot shift the H/Δ boundary.
|
||||
if summary_checkpoint is not None and checkpoint_boundary == message_index:
|
||||
self._insert_summary_checkpoint(session, summary_checkpoint)
|
||||
session.commit_summary_checkpoint(summary_checkpoint.summary)
|
||||
|
||||
entry = dict(message)
|
||||
followup_id_value = cast(object, entry.pop(PENDING_FOLLOWUP_ID_KEY, None))
|
||||
@@ -2319,7 +2291,7 @@ class AgentLoop:
|
||||
if tc.get("id")
|
||||
)
|
||||
if summary_checkpoint is not None and checkpoint_boundary == len(messages):
|
||||
self._insert_summary_checkpoint(session, summary_checkpoint)
|
||||
session.commit_summary_checkpoint(summary_checkpoint.summary)
|
||||
if turn_latency_ms is not None and last_assistant_idx is not None:
|
||||
session.messages[last_assistant_idx]["latency_ms"] = int(turn_latency_ms)
|
||||
if saved_followup_ids:
|
||||
|
||||
Reference in new issue
Block a user