hermes - 💡(How to fix) Fix [Bug]: _ensure_db_session hardcodes user_id=None — never records the authenticated user

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

self._session_db.create_session(
    session_id=self.session_id,
    source=self.platform or ...,
    user_id=None,  # <-- hardcoded, even when agent._user_id is set
    ...
)
RAW_BUFFERClick to expand / collapse

Problem or Use Case

AIAgent.__init__ accepts a user_id parameter which is stored as agent._user_id (agent/agent_init.py:265) and propagated to subagents, hooks, and memory providers. However, _ensure_db_session (run_agent.py:486) always writes user_id=None to the sessions table:

self._session_db.create_session(
    session_id=self.session_id,
    source=self.platform or ...,
    user_id=None,  # <-- hardcoded, even when agent._user_id is set
    ...
)

The sessions table has a user_id column (hermes_state.py:228) that is never populated for any session created through the normal AIAgent flow.

Impact: Audit queries, analytics, and any feature relying on user_id in the session DB get nothing — even for gateway platforms (Telegram, Discord, etc.) that correctly pass user_id to the AIAgent constructor.

Proposed Solution

Replace the hardcoded user_id=None with user_id=getattr(self, "_user_id", None). This is a one-line fix that correctly forwards the identity that was already provided at construction time.

Zero behavior change: when user_id is not passed to AIAgent (CLI sessions, loopback dashboard), _user_id is None and the column stays NULL — same as today.

Feature Type

Bug fix

Scope

Small (single line, 1 file)


This issue was drafted by an AI assistant (GLaDOS, Aperture Science) under human supervision and reviewed by the reporter before submission.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [Bug]: _ensure_db_session hardcodes user_id=None — never records the authenticated user