fix: clear ended_at metadata when messages are appended to an ended session - #53761
Closed
nicha16 wants to merge 1 commit into
Closed
fix: clear ended_at metadata when messages are appended to an ended session#53761nicha16 wants to merge 1 commit into
nicha16 wants to merge 1 commit into
Conversation
…ession append_message() increments message_count on the sessions row but never clears ended_at/end_reason. When a session is ended (e.g. by daily reset or idle timeout) and then reused for new messages, the stale ended_at causes hermes sessions list to rank the session by its old end time rather than its actual last activity. Fix: add ended_at = NULL, end_reason = NULL to the existing UPDATE in append_message(). This is a no-op for the 99.9% of sessions where ended_at is already NULL, and only affects the edge case where messages arrive for a previously-ended session. Test: adjust the compression-tip ordering test so the root message is appended before the root is ended (realistic order), matching the fix's assumption that append_message should clear ended_at.
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.
Problem
append_message()in the SessionDB incrementsmessage_counton the sessions row but never clearsended_atorend_reason. When a session is ended (e.g. by daily reset or idle timeout) and later receives new messages, the staleended_atcauseshermes sessions listto sort the session by its old end time rather than the actual last activity.This produces incorrect ranking: the session can appear at position #29 instead of its true rank (~#12) by last-message timestamp.
Fix
Add
ended_at = NULL, end_reason = NULLto the existing UPDATE inappend_message(), in both the tool-call and non-tool-call branches. This is free — the row is already being written. For the 99.9% of sessions whereended_atis already NULL, the SET NULL is a no-op. It only affects the edge case where messages arrive for a previously-ended session.Test
Adjusted the compression-tip ordering test so the root message is appended before the root is ended (realistic order), matching the fix's assumption that
append_messageclearsended_at. All 288 tests intest_hermes_state.pypass.Implementation