From 31cfa08c66ea0ee02096cad7c31a074eaa105d9e Mon Sep 17 00:00:00 2001 From: SaguaroDev <74339271+SaguaroDev@users.noreply.github.com> Date: Sun, 10 May 2026 18:17:57 -0400 Subject: [PATCH] feat(memory): add rewound kwarg to on_session_switch hook --- agent/memory_manager.py | 6 ++++++ agent/memory_provider.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/agent/memory_manager.py b/agent/memory_manager.py index fc5d96da4..11ab353bc 100644 --- a/agent/memory_manager.py +++ b/agent/memory_manager.py @@ -491,6 +491,7 @@ class MemoryManager: *, parent_session_id: str = "", reset: bool = False, + rewound: bool = False, **kwargs, ) -> None: """Notify all providers that the agent's session_id has rotated. @@ -503,6 +504,10 @@ class MemoryManager: per-session state so subsequent writes land in the correct session's record. See ``MemoryProvider.on_session_switch`` for the full contract. + + ``rewound=True`` signals that session_id is unchanged but the + transcript was truncated; providers caching per-turn document + state should invalidate. """ if not new_session_id: return @@ -512,6 +517,7 @@ class MemoryManager: new_session_id, parent_session_id=parent_session_id, reset=reset, + rewound=rewound, **kwargs, ) except Exception as e: diff --git a/agent/memory_provider.py b/agent/memory_provider.py index 116ceff40..89ac40eff 100644 --- a/agent/memory_provider.py +++ b/agent/memory_provider.py @@ -178,6 +178,7 @@ class MemoryProvider(ABC): *, parent_session_id: str = "", reset: bool = False, + rewound: bool = False, **kwargs, ) -> None: """Called when the agent switches session_id mid-process. @@ -207,6 +208,10 @@ class MemoryProvider(ABC): (``_session_turns``, ``_turn_counter``, etc.) when this is set. ``False`` for ``/resume`` / ``/branch`` / compression where the logical conversation continues under the new id. + rewound: + ``True`` if session_id is unchanged but the transcript was + truncated; providers caching per-turn document state should + invalidate. Default is no-op for backward compatibility. """