Skip to content

fix(memory): skip hindsight daemon startup when running as root - #13109

Closed
LehaoLin wants to merge 1 commit into
NousResearch:mainfrom
LehaoLin:fix/hindsight-root-detection
Closed

LehaoLin wants to merge 1 commit into
NousResearch:mainfrom
LehaoLin:fix/hindsight-root-detection

Conversation

@LehaoLin

Copy link
Copy Markdown
Contributor

What does this PR do?

When hermes runs as root with local_embedded memory mode, the embedded PostgreSQL daemon (hindsight-api --daemon) cannot start because initdb refuses to run as root. The daemon then retries endlessly (~3 minutes per cycle), consuming CPU and memory in a tight loop. The only visible symptom is hermes hanging on startup with no clear error message.

This patch adds an early os.geteuid() == 0 check in the daemon startup path. When running as root, it skips the daemon entirely and logs a clear warning message telling the user to either:

  • Run hermes as a non-root user, or
  • Switch to cloud or local_external mode via hermes memory setup

Related Issue

Distinct from #13101 (which addresses missing hindsight-all package). This PR addresses the root-user daemon hang.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Changes Made

  • plugins/memory/hindsight/__init__.py: Added os.geteuid() check before daemon startup in initialize(). When root is detected, logs warning and skips daemon instead of entering an infinite retry loop.

How to Test

  1. Run hermes as root with hindsight configured in local_embedded mode
  2. Without this fix: hermes hangs on startup, hindsight-api --daemon process spins at ~30% CPU with log showing initdb: error: cannot be run as root repeating every ~3 minutes
  3. With this fix: hermes starts normally, a single warning is logged explaining the issue and suggesting alternatives
  4. Verify that running as a non-root user with local_embedded still works (no regression)

Checklist

  • My commit messages follow Conventional Commits
  • My PR contains only changes related to this fix
  • Cross-platform: uses os.geteuid() (POSIX) with hasattr guard

When hermes runs as root with local_embedded mode, the embedded
PostgreSQL daemon cannot start because initdb refuses to run as root.
The daemon retries endlessly (~3 min per cycle), consuming CPU and
memory in a loop, with the only visible symptom being hermes hanging
on startup.

This patch detects root at daemon startup time and skips the daemon
with a clear warning message pointing the user to either run as a
non-root user or switch to cloud/local_external mode.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers labels Apr 22, 2026
@teknium1

Copy link
Copy Markdown
Collaborator

Salvaged and merged via #50308 (commit 7bc6f18 on main) — your authorship is preserved in git log.

Your branch had gone stale: it wrapped the pre-refactor _start_daemon body (hardcoded ~/.hindsight/profiles/*.env + manual env parsing), which has since been extracted into helper functions, so the diff couldn't be cherry-picked cleanly without reverting that refactor. I reapplied your substantive contribution — the os.geteuid() == 0 root guard — onto current main, plus added a stderr warning so the failure is user-visible (the issue's "zero feedback" complaint) and a unit test covering the root + non-root paths. Thanks for the fix!

@teknium1 teknium1 closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants