fix(hindsight): flush buffered turns on session end to prevent silent data loss - #36988
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(hindsight): flush buffered turns on session end to prevent silent data loss#36988liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
… data loss When retain_every_n_turns > 1, a session that ends before hitting the modulo boundary (CLI exit, idle timeout, /reset) silently drops all buffered turns. The on_session_switch hook already handles this for mid-session rotations, but on_session_end was inherited as a no-op from the base MemoryProvider class despite being declared in plugin.yaml. Add on_session_end() that flushes _session_turns via the same writer queue used by on_session_switch, preserving FIFO ordering with any still-queued retains from the same session. Fixes NousResearch#36216
Collaborator
Contributor
Author
|
Acknowledged — #36219 looks more complete. Closing this as duplicate. |
Contributor
Author
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Flushes buffered turns in
HindsightMemoryProvider.on_session_end()to prevent silent data loss when a session ends before hitting theretain_every_n_turnsmodulo boundary.Related Issue
Fixes #36216
Type of Change
Changes Made
plugins/memory/hindsight/__init__.py: Addedon_session_end()method that flushes_session_turnsvia the writer queue before session teardown. Mirrors the existing flush logic inon_session_switch()but without resetting session state (the session is ending, not rotating).tests/plugins/memory/test_hindsight_provider.py: AddedTestSessionEndBufferFlushwith 4 tests: buffered turns flushed, empty buffer no-op, state preservation during flush, skip during shutdown.How to Test
retain_every_n_turns: 12in Hindsight configpytest tests/plugins/memory/test_hindsight_provider.py::TestSessionEndBufferFlush -xvsto verify the regression tests passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/plugins/memory/test_hindsight_provider.py -xand all 105 tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
plugins/memory/hindsight/__init__.py—HindsightMemoryProvider.on_session_end(new method),on_session_switch(reference pattern),sync_turn(buffer logic),shutdown(teardown sequence)on_session_switch(lines 1586-1712) uses identical flush logic;shutdown(line 1714) drains the same writer queue;MemoryManager.on_session_end(agent/memory_manager.py:477) is the caller