fix: flush un-retained turns in SessionEnd hook before daemon stop#1205
Open
octo-patch wants to merge 1 commit intovectorize-io:mainfrom
Open
fix: flush un-retained turns in SessionEnd hook before daemon stop#1205octo-patch wants to merge 1 commit intovectorize-io:mainfrom
octo-patch wants to merge 1 commit intovectorize-io:mainfrom
Conversation
…ixes vectorize-io#1145) When retainEveryNTurns > 1, the Stop hook skips retain on non-multiple turns so turns between the last multiple and session end are silently dropped. SessionEnd now calls _flush_remaining_turns() before stopping the daemon: - reads turn_count from state without incrementing it - skips flush when retainEveryNTurns == 1 (Stop hook covers all turns) - skips flush when turn_count % retainEveryNTurns == 0 (Stop hook already retained) - uses session_id as document_id so the flush upserts the same document as prior full-session retains (deduplicates; last write wins) - includes flush_reason=session_end in metadata for observability Added four tests in TestSessionEndHook covering the flush/skip conditions.
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.
Fixes #1145
Problem
When
retainEveryNTurns > 1(e.g. the default of 10), the Stop hook skips retain on non-multiple turns. Turns between the last multiple and session end are silently dropped — a typical 27-turn session retains only up to turn 20, losing turns 21-27 completely.Solution
session_end.pynow calls_flush_remaining_turns()before stopping the daemon:turn_countfrom state (without incrementing) and checksturn_count % retain_every_n != 0retainEveryNTurns == 1— Stop hook already covers every turnturn_count % retainEveryNTurns == 0— the last Stop hook already retainedsession_idasdocument_idso the flush upserts the same document as prior full-session retains (last write wins, no duplicate storage)flush_reason: session_endto metadata for observabilityconfig.get("autoRetain")— no-op when auto-retain is disabledTesting
Added
TestSessionEndHook(4 tests) totest_hooks.py:test_flushes_remaining_turns_on_session_end— verifies flush fires when turn 1/3 was skippedtest_skips_flush_when_retain_every_n_is_one— no extra retain when already retained every turntest_skips_flush_when_last_stop_already_retained— no double-retain after turn 3/3test_skips_flush_when_auto_retain_disabled— respectsautoRetain: falseAll 137 existing tests continue to pass.