Skip to content

fix: clear ended_at metadata when messages are appended to an ended session - #53761

Closed
nicha16 wants to merge 1 commit into
NousResearch:mainfrom
nicha16:fix/append-message-clear-ended-at
Closed

fix: clear ended_at metadata when messages are appended to an ended session#53761
nicha16 wants to merge 1 commit into
NousResearch:mainfrom
nicha16:fix/append-message-clear-ended-at

Conversation

@nicha16

@nicha16 nicha16 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Problem

append_message() in the SessionDB increments message_count on the sessions row but never clears ended_at or end_reason. When a session is ended (e.g. by daily reset or idle timeout) and later receives new messages, the stale ended_at causes hermes sessions list to 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 = NULL to the existing UPDATE in append_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 where ended_at is 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_message clears ended_at. All 288 tests in test_hermes_state.py pass.

Implementation

# Before
UPDATE sessions SET message_count = message_count + 1 WHERE id = ?

# After
UPDATE sessions SET message_count = message_count + 1,
                    ended_at = NULL, end_reason = NULL WHERE id = ?

…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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P3 Low — cosmetic, nice to have labels Jun 27, 2026
@nicha16 nicha16 closed this Jun 27, 2026
@nicha16
nicha16 deleted the fix/append-message-clear-ended-at branch June 27, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants