fix(state): compute message_count from messages table (#39734) - #39896
Closed
kyssta-exe wants to merge 1 commit into
Closed
fix(state): compute message_count from messages table (#39734)#39896kyssta-exe wants to merge 1 commit into
kyssta-exe wants to merge 1 commit into
Conversation
…s_rich (NousResearch#39734) The denormalized sessions.message_count column can lag behind the actual messages table after a partial write, crash, or race condition. This caused session search/browse to report message_count=0 and empty preview for sessions that actually had persisted messages. Compute message_count via a correlated subquery on the messages table in list_sessions_rich and _get_session_rich_row, overriding the stale denormalized value. This ensures the browse/read APIs always agree with direct message table counts and FTS discovery.
Contributor
Author
|
Stale — oldest open PR, no merge activity for weeks. |
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for targeting a real session-history consistency concern. The current implementation needs adjustment before this can preserve current SessionDB semantics.
Problems
- The added
COUNT(*)inhermes_state.py:1761counts inactive rows. Current main specifies thatmessage_counttracks only the live active set inhermes_state.py:3980-3984; this would inflate compacted and rewound sessions. - The Python override happens after
list_sessions_richappliess.message_count >= ?athermes_state.py:3327-3329. The TUI project tree calls this withmin_message_count=1attui_gateway/server.py:11116-11122, so a stale-zero session would still be filtered out. - No regression test accompanies the change.
tests/test_hermes_state.py:3685-3719covers rich-list previews but not stale counters or inactive rows.
Suggested changes
- Derive the count from active messages and use that same definition in filtering/counting paths.
- Add stale-counter regressions for active rows, compacted/inactive rows, and
min_message_count=1.
Automated hermes-sweeper review.
| ORDER BY m.timestamp, m.id LIMIT 1), | ||
| '' | ||
| ) AS _preview_raw, | ||
| (SELECT COUNT(*) FROM messages m3 WHERE m3.session_id = s.id) AS _computed_message_count, |
Contributor
There was a problem hiding this comment.
COUNT(*) includes soft-archived and rewound rows. On current main, message_count is explicitly the live active = 1 count (hermes_state.py:3980-3984), so this needs an active-row predicate to avoid inflating compacted sessions.
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 #39734. The denormalized sessions.message_count column can lag behind the actual messages table after a partial write, crash, or race condition, causing session search/browse to report message_count=0 and empty preview for sessions that actually had persisted messages. This computes message_count via a correlated subquery on the messages table in list_sessions_rich and _get_session_rich_row, overriding the stale denormalized value.