Skip to content

sessions.message_count column not maintained for api_server and tui sources #45236

Description

@NeverLookBackAgain

Problem

The message_count column in the sessions table remains NULL for sessions created through the API Server (source=api_server) and TUI (source=tui) paths, even though the messages table contains valid messages for these sessions.

This causes the Desktop sidebar (which queries with min_messages=1) to incorrectly filter out almost all sessions. For example:

  • 150 TUI sessions: only 3 had message_count >= 1
  • 35 api_server sessions: 0 had message_count >= 1

Impact

  • Desktop sidebar shows very few sessions despite having hundreds of conversations in the database
  • Any client that uses min_messages >= 1 loses visibility of most sessions
  • Users cannot see their conversation history without manual UPDATE queries

Workaround

Running the following SQL backfills the missing counts:

UPDATE sessions SET message_count = (
  SELECT COUNT(*) FROM messages WHERE messages.session_id = sessions.id
) WHERE message_count IS NULL OR message_count = 0;

Root Cause Investigation Needed

The message_count column should be maintained by the session creation/update code path. The fact that it's consistently NULL for api_server and tui sources (but correctly populated for messaging platform sources like weixin, feishu) suggests the increment logic is missing in the agent loop or gateway response path for these sources.

Environment

  • Hermes Agent v0.16.0 (2026.6.5)
  • Windows Desktop Client v0.16.0

Activity

  1. added
    type/bugSomething isn't working
    comp/gatewayGateway runner, session dispatch, delivery
    P3Low — cosmetic, nice to have
    on Jun 12, 2026
  2. added a commit that references this issue on Jul 4, 2026
    18889f9
  3. GottZ commented on Jul 26, 2026

    @GottZ

    This was generated by AI during triage.

    Summary

    Two PRs address #45236: #45345 fixes NULL-propagating counter increments and attempts to backfill existing NULL rows, while #45475 only initializes counters for newly inserted sessions and does not repair affected historical rows.

    Related pull requests

    Duplicates

    #45475 substantially overlaps the new-session portion of #45345's counter-recovery work, but #45345 additionally addresses NULL-safe increments and historical repair; treat #45475 as superseded once its applicable initialization is folded into #45345.

    Suggested consolidation

    Merge #45345 after rebasing it onto current main, relocating the historical backfill to a fresh post-current-schema migration, and adding current-version reopen coverage; optionally fold explicit zero initialization into the current upsert. Then close #45475 as superseded because its stale two-line insert change alone cannot recover the sessions reported in #45236.

    Complex graph

    flowchart LR
        classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
        classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
        classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
        classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
        classDef best stroke-width:3px,stroke:#b45309
        classDef target stroke-width:3px,stroke:#4338ca
        I45236(["issue #45236 (open)"])
        P45345["PR #45345 (open)"]
        P45475["PR #45475 (open)"]
        P45345 -->|best fix| I45236
        P45475 -.->|partial| I45236
        class I45236 open
        class I45236 target
        class P45345 open
        class P45475 open
        class P45345 best
        click I45236 "https://github.com/NousResearch/hermes-agent/issues/45236"
        click P45345 "https://github.com/NousResearch/hermes-agent/pull/45345"
        click P45475 "https://github.com/NousResearch/hermes-agent/pull/45475"
    
    Loading

    Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).

    Cross-PR triage: Reviewed 2 pull requests and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 6 kB of PR diffs, 3 kB of issue/PR text, 5 kB of discussion (6 comments), 3 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havearea/sessionsSession lifecycle, resume, persistence, historycomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions